Class DoubleBits
DoubleBits manipulates Double numbers
by using bit manipulation and bit-field extraction.
For some operations (such as determining the exponent)
this is more accurate than using mathematical operations
(which suffer from round-off error).
The algorithms and constants in this class
apply only to IEEE-754 double-precision floating point format.
Inheritance
System.Object
DoubleBits
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Assembly: Mars.Common.dll
Syntax
Constructors
|
Improve this Doc
View Source
DoubleBits(Double)
Declaration
public DoubleBits(double x)
Parameters
Type |
Name |
Description |
System.Double |
x |
|
Fields
|
Improve this Doc
View Source
ExponentBias
Declaration
public const int ExponentBias = 1023
Field Value
Type |
Description |
System.Int32 |
|
Properties
|
Improve this Doc
View Source
BiasedExponent
Determines the exponent for the number.
Declaration
public int BiasedExponent { get; }
Property Value
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
Double
Declaration
public double Double { get; }
Property Value
Type |
Description |
System.Double |
|
|
Improve this Doc
View Source
Exponent
Determines the exponent for the number.
Declaration
public int Exponent { get; }
Property Value
Type |
Description |
System.Int32 |
|
Methods
|
Improve this Doc
View Source
GetBit(Int32)
Declaration
Parameters
Type |
Name |
Description |
System.Int32 |
i |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
GetExponent(Double)
Declaration
public static int GetExponent(double d)
Parameters
Type |
Name |
Description |
System.Double |
d |
|
Returns
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
MaximumCommonMantissa(Double, Double)
Declaration
public static double MaximumCommonMantissa(double d1, double d2)
Parameters
Type |
Name |
Description |
System.Double |
d1 |
|
System.Double |
d2 |
|
Returns
Type |
Description |
System.Double |
|
|
Improve this Doc
View Source
NumCommonMantissaBits(DoubleBits)
This computes the number of common most-significant bits in the mantissa.
It does not count the hidden bit, which is always 1.
It does not determine whether the numbers have the same exponent - if they do
not, the value computed by this function is meaningless.
Declaration
public int NumCommonMantissaBits(DoubleBits db)
Parameters
Returns
Type |
Description |
System.Int32 |
The number of common most-significant mantissa bits. |
|
Improve this Doc
View Source
PowerOf2(Int32)
Declaration
public static double PowerOf2(int exp)
Parameters
Type |
Name |
Description |
System.Int32 |
exp |
|
Returns
Type |
Description |
System.Double |
|
|
Improve this Doc
View Source
ToBinaryString(Double)
Declaration
public static string ToBinaryString(double d)
Parameters
Type |
Name |
Description |
System.Double |
d |
|
Returns
Type |
Description |
System.String |
|
|
Improve this Doc
View Source
ToString()
A representation of the Double bits formatted for easy readability.
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Overrides
System.Object.ToString()
|
Improve this Doc
View Source
TruncateToPowerOfTwo(Double)
Declaration
public static double TruncateToPowerOfTwo(double d)
Parameters
Type |
Name |
Description |
System.Double |
d |
|
Returns
Type |
Description |
System.Double |
|
|
Improve this Doc
View Source
ZeroLowerBits(Int32)
Declaration
public void ZeroLowerBits(int nBits)
Parameters
Type |
Name |
Description |
System.Int32 |
nBits |
|
Extension Methods