-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Needed to organize SinglePrecision code in preparation for DoublePrecision operations
- Loading branch information
Showing
10 changed files
with
157 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Apollo.Virtual.AGC.Base | ||
{ | ||
public class DoublePrecision | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Apollo.Virtual.AGC.Base | ||
{ | ||
public class SinglePrecision : OnesCompliment | ||
{ | ||
public SinglePrecision(ushort v) | ||
: base(v) | ||
{ | ||
} | ||
|
||
public SinglePrecision(int v) | ||
: base(v) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Single Precision Addition | ||
/// </summary> | ||
/// <param name="left">left operand</param> | ||
/// <param name="right">right operand</param> | ||
/// <returns></returns> | ||
public static SinglePrecision operator +(SinglePrecision left, OnesCompliment right) | ||
{ | ||
var sum = left.Value + right.Value; | ||
|
||
// if we have overflow, most likely from subtracting negative numbers | ||
if ((sum & 0x10000) > 0) | ||
{ | ||
// we need to ones compliment correct the negative number by adding 1 and taking the lower 16 bits | ||
// this process is called "end around carry" | ||
sum = sum + 1; | ||
sum = sum & 0xFFFF; | ||
} | ||
|
||
return new SinglePrecision(sum); | ||
} | ||
|
||
public static SinglePrecision operator +(SinglePrecision left, ushort right) | ||
{ | ||
return left + new SinglePrecision(right); | ||
} | ||
|
||
public static SinglePrecision operator ~(SinglePrecision a) | ||
{ | ||
return new SinglePrecision((ushort)~a.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters