OpenTK.Half Struct Reference

The name Half is derived from half-precision floating-point number. It occupies only 16 bits, which are split into 1 Sign bit, 5 Exponent bits and 10 Mantissa bits. More...

List of all members.

Public Member Functions

 Half (Single f)
 The new Half instance will convert the parameter into 16-bit half-precision floating-point.
 Half (Single f, bool throwOnError)
 The new Half instance will convert the parameter into 16-bit half-precision floating-point.
 Half (Double d)
 The new Half instance will convert the parameter into 16-bit half-precision floating-point.
 Half (Double d, bool throwOnError)
 The new Half instance will convert the parameter into 16-bit half-precision floating-point.
Single ToSingle ()
 Converts the 16-bit half to 32-bit floating-point.
 Half (SerializationInfo info, StreamingContext context)
 Constructor used by ISerializable to deserialize the object.
void GetObjectData (SerializationInfo info, StreamingContext context)
 Used by ISerialize to serialize the object.
void FromBinaryStream (BinaryReader bin)
 Updates the Half by reading from a Stream.
void ToBinaryStream (BinaryWriter bin)
 Writes the Half into a Stream.
bool Equals (Half other)
 Returns a value indicating whether this instance is equal to a specified OpenTK.Half value.
int CompareTo (Half other)
 Compares this instance to a specified half-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified half-precision floating-point number.
override string ToString ()
 Converts this Half into a human-legible string representation.
string ToString (string format, IFormatProvider formatProvider)
 Converts this Half into a human-legible string representation.

Static Public Member Functions

static operator Half (float f)
 Converts a System.Single to a OpenTK.Half.
static operator Half (double d)
 Converts a System.Double to a OpenTK.Half.
static implicit operator float (Half h)
 Converts a OpenTK.Half to a System.Single.
static implicit operator double (Half h)
 Converts a OpenTK.Half to a System.Double.
static Half Parse (string s)
 Converts the string representation of a number to a half-precision floating-point equivalent.
static Half Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider)
 Converts the string representation of a number to a half-precision floating-point equivalent.
static bool TryParse (string s, out Half result)
 Converts the string representation of a number to a half-precision floating-point equivalent. Returns success.
static bool TryParse (string s, System.Globalization.NumberStyles style, IFormatProvider provider, out Half result)
 Converts the string representation of a number to a half-precision floating-point equivalent. Returns success.
static byte[] GetBytes (Half h)
 Returns the Half as an array of bytes.
static Half FromBytes (byte[] value, int startIndex)
 Converts an array of bytes into Half.

Public Attributes

UInt16 bits
const int maxUlps = 1

Static Public Attributes

static readonly Int32 SizeInBytes = 2
 The size in bytes for an instance of the Half struct.
static readonly Single MinValue = 5.96046448e-08f
 Smallest positive half.
static readonly Single MinNormalizedValue = 6.10351562e-05f
 Smallest positive normalized half.
static readonly Single MaxValue = 65504.0f
 Largest positive half.
static readonly Single Epsilon = 0.00097656f
 Smallest positive e for which half (1.0 + e) != half (1.0).

Properties

bool IsZero [get]
 Returns true if the Half is zero.
bool IsNaN [get]
 Returns true if the Half represents Not A Number (NaN).
bool IsPositiveInfinity [get]
 Returns true if the Half represents positive infinity.
bool IsNegativeInfinity [get]
 Returns true if the Half represents negative infinity.

Detailed Description

The name Half is derived from half-precision floating-point number. It occupies only 16 bits, which are split into 1 Sign bit, 5 Exponent bits and 10 Mantissa bits.

Quote from ARB_half_float_pixel specification: Any representable 16-bit floating-point value is legal as input to a GL command that accepts 16-bit floating-point data. The result of providing a value that is not a floating-point number (such as infinity or NaN) to such a command is unspecified, but must not lead to GL interruption or termination. Providing a denormalized number or negative zero to GL must yield predictable results.

Definition at line 79 of file Half.cs.


Constructor & Destructor Documentation

OpenTK.Half.Half ( Single  f  ) 

The new Half instance will convert the parameter into 16-bit half-precision floating-point.

Parameters:
f 32-bit single-precision floating-point number.

Definition at line 109 of file Half.cs.

00110             : this()
00111         {
00112             unsafe
00113             {
00114                 bits = SingleToHalf(*(int*)&f);
00115             }
00116         }

OpenTK.Half.Half ( Single  f,
bool  throwOnError 
)

The new Half instance will convert the parameter into 16-bit half-precision floating-point.

Parameters:
f 32-bit single-precision floating-point number.
throwOnError Enable checks that will throw if the conversion result is not meaningful.

Definition at line 123 of file Half.cs.

00124             : this(f)
00125         {
00126             if (throwOnError)
00127             {
00128                 // handle cases that cause overflow rather than silently ignoring it
00129                 if (f > Half.MaxValue) throw new ArithmeticException("Half: Positive maximum value exceeded.");
00130                 if (f < -Half.MaxValue) throw new ArithmeticException("Half: Negative minimum value exceeded.");
00131 
00132                 // handle cases that make no sense
00133                 if (Single.IsNaN(f)) throw new ArithmeticException("Half: Input is not a number (NaN).");
00134                 if (Single.IsPositiveInfinity(f)) throw new ArithmeticException("Half: Input is positive infinity.");
00135                 if (Single.IsNegativeInfinity(f)) throw new ArithmeticException("Half: Input is negative infinity.");
00136             }
00137         }

OpenTK.Half.Half ( Double  d  ) 

The new Half instance will convert the parameter into 16-bit half-precision floating-point.

Parameters:
d 64-bit double-precision floating-point number.

Definition at line 143 of file Half.cs.

00143 : this((Single)d) { }

OpenTK.Half.Half ( Double  d,
bool  throwOnError 
)

The new Half instance will convert the parameter into 16-bit half-precision floating-point.

Parameters:
d 64-bit double-precision floating-point number.
throwOnError Enable checks that will throw if the conversion result is not meaningful.

Definition at line 150 of file Half.cs.

00150 : this((Single)d, throwOnError) { }

OpenTK.Half.Half ( SerializationInfo  info,
StreamingContext  context 
)

Constructor used by ISerializable to deserialize the object.

Parameters:
info 
context 

Definition at line 404 of file Half.cs.

00405         {
00406             this.bits = (ushort)info.GetValue("bits", typeof(ushort));
00407         }


Member Function Documentation

int OpenTK.Half.CompareTo ( Half  other  ) 

Compares this instance to a specified half-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified half-precision floating-point number.

Parameters:
other A half-precision floating-point number to compare.
Returns:

A signed number indicating the relative values of this instance and value. If the number is:

Less than zero, then this instance is less than other, or this instance is not a number (OpenTK.Half.NaN) and other is a number.

Zero: this instance is equal to value, or both this instance and other are not a number (OpenTK.Half.NaN), OpenTK.Half.PositiveInfinity, or OpenTK.Half.NegativeInfinity.

Greater than zero: this instance is greater than othrs, or this instance is a number and other is not a number (OpenTK.Half.NaN).

Definition at line 490 of file Half.cs.

00491         {
00492             return ((float)this).CompareTo((float)other);
00493         }

bool OpenTK.Half.Equals ( Half  other  ) 

Returns a value indicating whether this instance is equal to a specified OpenTK.Half value.

Parameters:
other OpenTK.Half object to compare to this instance..
Returns:
True, if other is equal to this instance; false otherwise.

Definition at line 447 of file Half.cs.

00448         {
00449             short aInt, bInt;
00450             unchecked { aInt = (short)other.bits; }
00451             unchecked { bInt = (short)this.bits; }
00452 
00453             // Make aInt lexicographically ordered as a twos-complement int
00454             if (aInt < 0)
00455                 aInt = (short)(0x8000 - aInt);
00456 
00457             // Make bInt lexicographically ordered as a twos-complement int
00458             if (bInt < 0)
00459                 bInt = (short)(0x8000 - bInt);
00460 
00461             short intDiff = System.Math.Abs((short)(aInt - bInt));
00462 
00463             if (intDiff <= maxUlps)
00464                 return true;
00465 
00466             return false;
00467         }

void OpenTK.Half.FromBinaryStream ( BinaryReader  bin  ) 

Updates the Half by reading from a Stream.

Parameters:
bin A BinaryReader instance associated with an open Stream.

Definition at line 423 of file Half.cs.

00424         {
00425             this.bits = bin.ReadUInt16();
00426 
00427         }

static Half OpenTK.Half.FromBytes ( byte[]  value,
int  startIndex 
) [static]

Converts an array of bytes into Half.

Parameters:
value A Half in it's byte[] representation.
startIndex The starting position within value.
Returns:
A new Half instance.

Definition at line 579 of file Half.cs.

00580         {
00581             Half h;
00582             h.bits = BitConverter.ToUInt16(value, startIndex);
00583             return h;
00584         }

static byte [] OpenTK.Half.GetBytes ( Half  h  )  [static]

Returns the Half as an array of bytes.

Parameters:
h The Half to convert.
Returns:
The input as byte array.

Definition at line 570 of file Half.cs.

00571         {
00572             return BitConverter.GetBytes(h.bits);
00573         }

void OpenTK.Half.GetObjectData ( SerializationInfo  info,
StreamingContext  context 
)

Used by ISerialize to serialize the object.

Parameters:
info 
context 

Definition at line 412 of file Half.cs.

00413         {
00414             info.AddValue("bits", this.bits);
00415         }

static implicit OpenTK.Half.operator double ( Half  h  )  [static]

Converts a OpenTK.Half to a System.Double.

Parameters:
h The value to convert. A Half
Returns:
The result of the conversion. A System.Double

Definition at line 373 of file Half.cs.

00374         {
00375             return (double)h.ToSingle();
00376         }

static implicit OpenTK.Half.operator float ( Half  h  )  [static]

Converts a OpenTK.Half to a System.Single.

Parameters:
h The value to convert. A Half
Returns:
The result of the conversion. A System.Single

Definition at line 359 of file Half.cs.

00360         {
00361             return h.ToSingle();
00362         }

static OpenTK.Half.operator Half ( double  d  )  [explicit, static]

Converts a System.Double to a OpenTK.Half.

Parameters:
d The value to convert. A System.Double
Returns:
The result of the conversion. A Half

Definition at line 345 of file Half.cs.

00346         {
00347             return new Half(d);
00348         }

static OpenTK.Half.operator Half ( float  f  )  [explicit, static]

Converts a System.Single to a OpenTK.Half.

Parameters:
f The value to convert. A System.Single
Returns:
The result of the conversion. A Half

Definition at line 331 of file Half.cs.

00332         {
00333             return new Half(f);
00334         }

static Half OpenTK.Half.Parse ( string  s,
System.Globalization.NumberStyles  style,
IFormatProvider  provider 
) [static]

Converts the string representation of a number to a half-precision floating-point equivalent.

Parameters:
s String representation of the number to convert.
style Specifies the format of s.
provider Culture-specific formatting information.
Returns:
A new Half instance.

Definition at line 532 of file Half.cs.

00533         {
00534             return (Half)Single.Parse(s, style, provider);
00535         }

static Half OpenTK.Half.Parse ( string  s  )  [static]

Converts the string representation of a number to a half-precision floating-point equivalent.

Parameters:
s String representation of the number to convert.
Returns:
A new Half instance.

Definition at line 522 of file Half.cs.

00523         {
00524             return (Half)Single.Parse(s);
00525         }

void OpenTK.Half.ToBinaryStream ( BinaryWriter  bin  ) 

Writes the Half into a Stream.

Parameters:
bin A BinaryWriter instance associated with an open Stream.

Definition at line 431 of file Half.cs.

00432         {
00433             bin.Write(this.bits);
00434         }

Single OpenTK.Half.ToSingle (  ) 

Converts the 16-bit half to 32-bit floating-point.

Returns:
A single-precision floating-point number.

Definition at line 252 of file Half.cs.

00253         {
00254             int i = HalfToFloat(bits);
00255 
00256             unsafe
00257             {
00258                 return *(float*)&i;
00259             }
00260         }

string OpenTK.Half.ToString ( string  format,
IFormatProvider  formatProvider 
)

Converts this Half into a human-legible string representation.

Parameters:
format Formatting for the output string.
formatProvider Culture-specific formatting information.
Returns:
The string representation of this instance.

Definition at line 510 of file Half.cs.

00511         {
00512             return this.ToSingle().ToString(format, formatProvider);
00513         }

override string OpenTK.Half.ToString (  ) 

Converts this Half into a human-legible string representation.

Returns:
The string representation of this instance.

Definition at line 501 of file Half.cs.

00502         {
00503             return this.ToSingle().ToString();
00504         }

static bool OpenTK.Half.TryParse ( string  s,
System.Globalization.NumberStyles  style,
IFormatProvider  provider,
out Half  result 
) [static]

Converts the string representation of a number to a half-precision floating-point equivalent. Returns success.

Parameters:
s String representation of the number to convert.
style Specifies the format of s.
provider Culture-specific formatting information.
result The Half instance to write to.
Returns:
Success.

Definition at line 555 of file Half.cs.

00556         {
00557             float f;
00558             bool b = Single.TryParse(s, style, provider, out f);
00559             result = (Half)f;
00560             return b;
00561         }

static bool OpenTK.Half.TryParse ( string  s,
out Half  result 
) [static]

Converts the string representation of a number to a half-precision floating-point equivalent. Returns success.

Parameters:
s String representation of the number to convert.
result The Half instance to write to.
Returns:
Success.

Definition at line 541 of file Half.cs.

00542         {
00543             float f;
00544             bool b = Single.TryParse(s, out f);
00545             result = (Half)f;
00546             return b;
00547         }


Member Data Documentation

readonly Single OpenTK.Half.Epsilon = 0.00097656f [static]

Smallest positive e for which half (1.0 + e) != half (1.0).

Definition at line 395 of file Half.cs.

readonly Single OpenTK.Half.MaxValue = 65504.0f [static]

Largest positive half.

Definition at line 392 of file Half.cs.

readonly Single OpenTK.Half.MinNormalizedValue = 6.10351562e-05f [static]

Smallest positive normalized half.

Definition at line 389 of file Half.cs.

readonly Single OpenTK.Half.MinValue = 5.96046448e-08f [static]

Smallest positive half.

Definition at line 386 of file Half.cs.

readonly Int32 OpenTK.Half.SizeInBytes = 2 [static]

The size in bytes for an instance of the Half struct.

Definition at line 383 of file Half.cs.


Property Documentation

bool OpenTK.Half.IsNaN [get]

Returns true if the Half represents Not A Number (NaN).

Definition at line 93 of file Half.cs.

bool OpenTK.Half.IsNegativeInfinity [get]

Returns true if the Half represents negative infinity.

Definition at line 99 of file Half.cs.

bool OpenTK.Half.IsPositiveInfinity [get]

Returns true if the Half represents positive infinity.

Definition at line 96 of file Half.cs.

bool OpenTK.Half.IsZero [get]

Returns true if the Half is zero.

Definition at line 90 of file Half.cs.

 All Classes Functions Variables Enumerations Properties Events

Generated on Tue Mar 9 14:59:14 2010 for The Open Toolkit library by  doxygen 1.6.1