Struct Half
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.
Inherited Members
Namespace: OpenTK
Assembly: cs.temp.dll.dll
Syntax
[Serializable]
public struct Half : ISerializable, IComparable<Half>, IFormattable, IEquatable<Half>
Remarks
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.
Constructors
Half(SerializationInfo, StreamingContext)
Constructor used by ISerializable to deserialize the object.
Declaration
public Half(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | |
StreamingContext | context |
Half(Double)
The new Half instance will convert the parameter into 16-bit half-precision floating-point.
Declaration
public Half(double d)
Parameters
Type | Name | Description |
---|---|---|
System.Double | d | 64-bit double-precision floating-point number. |
Half(Double, Boolean)
The new Half instance will convert the parameter into 16-bit half-precision floating-point.
Declaration
public Half(double d, bool throwOnError)
Parameters
Type | Name | Description |
---|---|---|
System.Double | d | 64-bit double-precision floating-point number. |
System.Boolean | throwOnError | Enable checks that will throw if the conversion result is not meaningful. |
Half(Single)
The new Half instance will convert the parameter into 16-bit half-precision floating-point.
Declaration
public Half(float f)
Parameters
Type | Name | Description |
---|---|---|
System.Single | f | 32-bit single-precision floating-point number. |
Half(Single, Boolean)
The new Half instance will convert the parameter into 16-bit half-precision floating-point.
Declaration
public Half(float f, bool throwOnError)
Parameters
Type | Name | Description |
---|---|---|
System.Single | f | 32-bit single-precision floating-point number. |
System.Boolean | throwOnError | Enable checks that will throw if the conversion result is not meaningful. |
Fields
Epsilon
Smallest positive e for which half (1.0 + e) != half (1.0)
Declaration
public static readonly float Epsilon
Field Value
Type | Description |
---|---|
System.Single |
MaxValue
Largest positive half
Declaration
public static readonly float MaxValue
Field Value
Type | Description |
---|---|
System.Single |
MinNormalizedValue
Smallest positive normalized half
Declaration
public static readonly float MinNormalizedValue
Field Value
Type | Description |
---|---|
System.Single |
MinValue
Smallest positive half
Declaration
public static readonly float MinValue
Field Value
Type | Description |
---|---|
System.Single |
SizeInBytes
The size in bytes for an instance of the Half struct.
Declaration
public static readonly int SizeInBytes
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
IsNaN
Returns true if the Half represents Not A Number (NaN)
Declaration
public bool IsNaN { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsNegativeInfinity
Returns true if the Half represents negative infinity.
Declaration
public bool IsNegativeInfinity { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsPositiveInfinity
Returns true if the Half represents positive infinity.
Declaration
public bool IsPositiveInfinity { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsZero
Returns true if the Half is zero.
Declaration
public bool IsZero { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
CompareTo(Half)
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.
Declaration
public int CompareTo(Half other)
Parameters
Type | Name | Description |
---|---|---|
Half | other | A half-precision floating-point number to compare. |
Returns
Type | Description |
---|---|
System.Int32 | 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). |
Equals(Half)
Returns a value indicating whether this instance is equal to a specified OpenTK.Half value.
Declaration
public bool Equals(Half other)
Parameters
Type | Name | Description |
---|---|---|
Half | other | OpenTK.Half object to compare to this instance.. |
Returns
Type | Description |
---|---|
System.Boolean | True, if other is equal to this instance; false otherwise. |
FromBinaryStream(BinaryReader)
Updates the Half by reading from a Stream.
Declaration
public void FromBinaryStream(BinaryReader bin)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryReader | bin | A BinaryReader instance associated with an open Stream. |
FromBytes(Byte[], Int32)
Converts an array of bytes into Half.
Declaration
public static Half FromBytes(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | A Half in it's byte[] representation. |
System.Int32 | startIndex | The starting position within value. |
Returns
Type | Description |
---|---|
Half | A new Half instance. |
GetBytes(Half)
Returns the Half as an array of bytes.
Declaration
public static byte[] GetBytes(Half h)
Parameters
Type | Name | Description |
---|---|---|
Half | h | The Half to convert. |
Returns
Type | Description |
---|---|
System.Byte[] | The input as byte array. |
GetObjectData(SerializationInfo, StreamingContext)
Used by ISerialize to serialize the object.
Declaration
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | |
StreamingContext | context |
Parse(String)
Converts the string representation of a number to a half-precision floating-point equivalent.
Declaration
public static Half Parse(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | String representation of the number to convert. |
Returns
Type | Description |
---|---|
Half | A new Half instance. |
Parse(String, NumberStyles, IFormatProvider)
Converts the string representation of a number to a half-precision floating-point equivalent.
Declaration
public static Half Parse(string s, NumberStyles style, IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | String representation of the number to convert. |
System.Globalization.NumberStyles | style | Specifies the format of s. |
System.IFormatProvider | provider | Culture-specific formatting information. |
Returns
Type | Description |
---|---|
Half | A new Half instance. |
ToBinaryStream(BinaryWriter)
Writes the Half into a Stream.
Declaration
public void ToBinaryStream(BinaryWriter bin)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | bin | A BinaryWriter instance associated with an open Stream. |
ToSingle()
Converts the 16-bit half to 32-bit floating-point.
Declaration
public float ToSingle()
Returns
Type | Description |
---|---|
System.Single | A single-precision floating-point number. |
ToString()
Converts this Half into a human-legible string representation.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | The string representation of this instance. |
Overrides
ToString(String, IFormatProvider)
Converts this Half into a human-legible string representation.
Declaration
public string ToString(string format, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | Formatting for the output string. |
System.IFormatProvider | formatProvider | Culture-specific formatting information. |
Returns
Type | Description |
---|---|
System.String | The string representation of this instance. |
TryParse(String, out Half)
Converts the string representation of a number to a half-precision floating-point equivalent. Returns success.
Declaration
public static bool TryParse(string s, out Half result)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | String representation of the number to convert. |
Half | result | The Half instance to write to. |
Returns
Type | Description |
---|---|
System.Boolean | Success. |
TryParse(String, NumberStyles, IFormatProvider, out Half)
Converts the string representation of a number to a half-precision floating-point equivalent. Returns success.
Declaration
public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out Half result)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | String representation of the number to convert. |
System.Globalization.NumberStyles | style | Specifies the format of s. |
System.IFormatProvider | provider | Culture-specific formatting information. |
Half | result | The Half instance to write to. |
Returns
Type | Description |
---|---|
System.Boolean | Success. |
Operators
Explicit(Double to Half)
Converts a System.Double to a OpenTK.Half.
Declaration
public static explicit operator Half(double d)
Parameters
Type | Name | Description |
---|---|---|
System.Double | d | The value to convert. A System.Double |
Returns
Type | Description |
---|---|
Half | The result of the conversion. A Half |
Explicit(Single to Half)
Converts a System.Single to a OpenTK.Half.
Declaration
public static explicit operator Half(float f)
Parameters
Type | Name | Description |
---|---|---|
System.Single | f | The value to convert. A System.Single |
Returns
Type | Description |
---|---|
Half | The result of the conversion. A Half |
Implicit(Half to Double)
Converts a OpenTK.Half to a System.Double.
Declaration
public static implicit operator double (Half h)
Parameters
Type | Name | Description |
---|---|---|
Half | h | The value to convert. A Half |
Returns
Type | Description |
---|---|
System.Double | The result of the conversion. A System.Double |
Implicit(Half to Single)
Converts a OpenTK.Half to a System.Single.
Declaration
public static implicit operator float (Half h)
Parameters
Type | Name | Description |
---|---|---|
Half | h | The value to convert. A Half |
Returns
Type | Description |
---|---|
System.Single | The result of the conversion. A System.Single |