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: OpenTK.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(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 |
---|---|---|
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 |
---|---|---|
Double | d | 64-bit double-precision floating-point number. |
Boolean | throwOnError | Enable checks that will throw if the conversion result is not meaningful. |
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(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 |
---|---|---|
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 |
---|---|---|
Single | f | 32-bit single-precision floating-point number. |
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 |
---|---|
Single |
MaxValue
Largest positive half
Declaration
public static readonly float MaxValue
Field Value
Type | Description |
---|---|
Single |
MinNormalizedValue
Smallest positive normalized half
Declaration
public static readonly float MinNormalizedValue
Field Value
Type | Description |
---|---|
Single |
MinValue
Smallest positive half
Declaration
public static readonly float MinValue
Field Value
Type | Description |
---|---|
Single |
SizeInBytes
The size in bytes for an instance of the Half struct.
Declaration
public static readonly int SizeInBytes
Field Value
Type | Description |
---|---|
Int32 |
Properties
IsNaN
Returns true if the Half represents Not A Number (NaN)
Declaration
public readonly bool IsNaN { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsNegativeInfinity
Returns true if the Half represents negative infinity.
Declaration
public readonly bool IsNegativeInfinity { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsPositiveInfinity
Returns true if the Half represents positive infinity.
Declaration
public readonly bool IsPositiveInfinity { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsZero
Returns true if the Half is zero.
Declaration
public readonly bool IsZero { get; }
Property Value
Type | Description |
---|---|
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 |
---|---|
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 |
---|---|
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 |
---|---|---|
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 |
---|---|---|
Byte[] | value | A Half in it's byte[] representation. |
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 |
---|---|
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 |
---|---|---|
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 |
---|---|---|
String | s | String representation of the number to convert. |
NumberStyles | style | Specifies the format of s. |
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 |
---|---|---|
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 |
---|---|
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 |
---|---|
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 |
---|---|---|
String | format | Formatting for the output string. |
IFormatProvider | formatProvider | Culture-specific formatting information. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
String | s | String representation of the number to convert. |
Half | result | The Half instance to write to. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
String | s | String representation of the number to convert. |
NumberStyles | style | Specifies the format of s. |
IFormatProvider | provider | Culture-specific formatting information. |
Half | result | The Half instance to write to. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
Double | d | The value to convert. A 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 |
---|---|---|
Single | f | The value to convert. A 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 |
---|---|
Double | The result of the conversion. A 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 |
---|---|
Single | The result of the conversion. A Single |