Represents an half single-precision floating point number. More...
Public Member Functions | |
HalfSingle (UInt16 hfloat) | |
Construct an HalfFloat using directly its representation. | |
int | CompareTo (HalfSingle other) |
Compares the current object with another object of the same type. | |
int | CompareTo (object obj) |
Compares the current instance with another object of the same type. | |
bool | Equals (HalfSingle other) |
Indicates whether the current object is equal to another object of the same type. | |
string | ToString (string format, IFormatProvider formatProvider) |
Formats the value of the current instance using the specified format. |
Represents an half single-precision floating point number.
This documentation was produced by:
Representation of a float:
We assume that a float, f, is an IEEE 754 single-precision floating point number, whose bits are arranged as follows:
31 (msb) | | 30 23 | | | | | | 22 0 (lsb) | | | | | X XXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX
s e m
S is the sign-bit, e is the exponent and m is the significand.
If e is between 1 and 254, f is a normalized number:
s e-127 f = (-1) * 2 * 1.m
If e is 0, and m is not zero, f is a denormalized number:
s -126 f = (-1) * 2 * 0.m
If e and m are both zero, f is zero:
f = 0.0
If e is 255, f is an "infinity" or "not a number" (NAN), depending on whether m is zero or not.
Examples:
0 00000000 00000000000000000000000 = 0.0 0 01111110 00000000000000000000000 = 0.5 0 01111111 00000000000000000000000 = 1.0 0 10000000 00000000000000000000000 = 2.0 0 10000000 10000000000000000000000 = 3.0 1 10000101 11110000010000000000000 = -124.0625 0 11111111 00000000000000000000000 = +infinity 1 11111111 00000000000000000000000 = -infinity 0 11111111 10000000000000000000000 = NAN 1 11111111 11111111111111111111111 = NAN
Representation of a HalfFloat:
Here is the bit-layout for a HalfFloat number, h:
15 (msb) | | 14 10 | | | | | | 9 0 (lsb) | | | | | X XXXXX XXXXXXXXXX
s e m
S is the sign-bit, e is the exponent and m is the significand.
If e is between 1 and 30, h is a normalized number:
s e-15 h = (-1) * 2 * 1.m
If e is 0, and m is not zero, h is a denormalized number:
S -14 h = (-1) * 2 * 0.m
If e and m are both zero, h is zero:
h = 0.0
If e is 31, h is an "infinity" or "not a number" (NAN), depending on whether m is zero or not.
Examples:
0 00000 0000000000 = 0.0 0 01110 0000000000 = 0.5 0 01111 0000000000 = 1.0 0 10000 0000000000 = 2.0 0 10000 1000000000 = 3.0 1 10101 1111000001 = -124.0625 0 11111 0000000000 = +infinity 1 11111 0000000000 = -infinity 0 11111 1000000000 = NAN 1 11111 1111111111 = NAN
Conversion:
Converting from a float to a HalfFloat requires some non-trivial bit manipulations. In some cases, this makes conversion relatively slow, but the most common case is accelerated via table lookups.
Converting back from a HalfFloat to a float is easier because we don't have to do any rounding. In addition, there are only 65536 different HalfFloat numbers; we can convert each of those numbers once and store the results in a table. Later, all conversions can be done using only simple table lookups.
Derm.Types.HalfSingle.HalfSingle | ( | UInt16 | hfloat | ) |
Construct an HalfFloat using directly its representation.
hfloat |
int Derm.Types.HalfSingle.CompareTo | ( | HalfSingle | other | ) |
Compares the current object with another object of the same type.
other | An object to compare with this object. |
int Derm.Types.HalfSingle.CompareTo | ( | object | obj | ) |
Compares the current instance with another object of the same type.
obj | An object to compare with this instance. |
bool Derm.Types.HalfSingle.Equals | ( | HalfSingle | other | ) |
Indicates whether the current object is equal to another object of the same type.
other | An object to compare with this object. |
string Derm.Types.HalfSingle.ToString | ( | string | format, | |
IFormatProvider | formatProvider | |||
) |
Formats the value of the current instance using the specified format.
format | The System.String specifying the format to use.-or- null to use the default format defined for the type of the System.IFormattable implementation. | |
formatProvider | The System.IFormatProvider to use to format the value.-or- null to obtain the numeric format information from the current locale setting of the operating system. |