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.Mathematics
Assembly: OpenTK.Mathematics.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, bool)
Initializes a new instance of the Half struct with d
being converted
into a 16-bit half-precision floating-point number.
Declaration
public Half(double d, bool throwOnError)
Parameters
Type | Name | Description |
---|---|---|
double | d | 64-bit double-precision floating-point number. |
bool | throwOnError | Enable checks that will throw if the conversion result is not meaningful. |
Half(double)
Initializes a new instance of the Half struct with d
being converted
into a 16-bit half-precision floating-point number.
Declaration
public Half(double d)
Parameters
Type | Name | Description |
---|---|---|
double | d | 64-bit double-precision floating-point number. |
Half(SerializationInfo, StreamingContext)
Initializes a new instance of the Half struct. Used by ISerializable to deserialize the object.
Declaration
public Half(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | The object that contains a serialized Half struct. |
StreamingContext | context | The destination for this serialization. (This parameter is not used; specify null.). |
Half(float, bool)
Initializes a new instance of the Half struct with f
being converted
into a 16-bit half-precision floating-point number.
Declaration
public Half(float f, bool throwOnError)
Parameters
Type | Name | Description |
---|---|---|
float | f | 32-bit single-precision floating-point number. |
bool | throwOnError | Enable checks that will throw if the conversion result is not meaningful. |
Half(float)
Initializes a new instance of the Half struct with f
being converted
into a 16-bit half-precision floating-point number.
Declaration
public Half(float f)
Parameters
Type | Name | Description |
---|---|---|
float | f | 32-bit single-precision floating-point number. |
Fields
Epsilon
Smallest positive e for which half (1.0 + e) != half (1.0).
Declaration
public static readonly float Epsilon
Field Value
Type | Description |
---|---|
float |
MaxValue
Largest positive half.
Declaration
public static readonly float MaxValue
Field Value
Type | Description |
---|---|
float |
MinNormalizedValue
Smallest positive normalized half.
Declaration
public static readonly float MinNormalizedValue
Field Value
Type | Description |
---|---|
float |
MinValue
Smallest positive half.
Declaration
public static readonly float MinValue
Field Value
Type | Description |
---|---|
float |
SizeInBytes
The size in bytes for an instance of the Half struct.
Declaration
public static readonly int SizeInBytes
Field Value
Type | Description |
---|---|
int |
Properties
IsNaN
Gets a value indicating whether the Half represents Not A Number (NaN).
Declaration
public bool IsNaN { get; }
Property Value
Type | Description |
---|---|
bool |
IsNegativeInfinity
Gets a value indicating whether the Half represents negative infinity.
Declaration
public bool IsNegativeInfinity { get; }
Property Value
Type | Description |
---|---|
bool |
IsPositiveInfinity
Gets a value indicating whether the Half represents positive infinity.
Declaration
public bool IsPositiveInfinity { get; }
Property Value
Type | Description |
---|---|
bool |
IsZero
Gets a value indicating whether the Half is zero.
Declaration
public bool IsZero { get; }
Property Value
Type | Description |
---|---|
bool |
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
[Pure]
public int CompareTo(Half other)
Parameters
Type | Name | Description |
---|---|---|
Half | other | A half-precision floating-point number to compare. |
Returns
Type | Description |
---|---|
int | 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
[Pure]
public bool Equals(Half other)
Parameters
Type | Name | Description |
---|---|---|
Half | other | OpenTK.Half object to compare to this instance.. |
Returns
Type | Description |
---|---|
bool | True, if other is equal to this instance; false otherwise. |
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj |
Returns
Type | Description |
---|---|
bool |
Overrides
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[], int)
Converts an array of bytes into Half.
Declaration
[Pure]
public static Half FromBytes(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
byte[] | value | A Half in it's byte[] representation. |
int | 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
[Pure]
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. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
GetObjectData(SerializationInfo, StreamingContext)
Declaration
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
SerializationInfo | info | |
StreamingContext | context |
Parse(string, NumberStyles, IFormatProvider)
Converts the string representation of a number to a half-precision floating-point equivalent.
Declaration
[Pure]
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. |
Parse(string)
Converts the string representation of a number to a half-precision floating-point equivalent.
Declaration
[Pure]
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. |
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 |
---|---|
float | 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(IFormatProvider)
Converts this Half into a human-legible string representation.
Declaration
public string ToString(IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
IFormatProvider | formatProvider | Culture-specific formatting information. |
Returns
Type | Description |
---|---|
string | The string representation of this instance. |
ToString(string, IFormatProvider)
Converts this Half into a human-legible string representation.
Declaration
[Pure]
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. |
ToString(string)
Converts this Half into a human-legible string representation.
Declaration
public string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
string | format | Formatting for the output string. |
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
[Pure]
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 |
---|---|
bool | Success. |
TryParse(string, NumberStyles, IFormatProvider, out Half)
Converts the string representation of a number to a half-precision floating-point equivalent. Returns success.
Declaration
[Pure]
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 |
---|---|
bool | Success. |
Operators
operator ==(Half, Half)
Declaration
public static bool operator ==(Half left, Half right)
Parameters
Type | Name | Description |
---|---|---|
Half | left | |
Half | right |
Returns
Type | Description |
---|---|
bool |
explicit operator Half(double)
Converts a System.Double to a OpenTK.Half.
Declaration
[Pure]
public static explicit operator Half(double d)
Parameters
Type | Name | Description |
---|---|---|
double | d | The double value to convert. |
Returns
Type | Description |
---|---|
Half | The Half result of the conversion. |
explicit operator Half(float)
Converts a System.Single to a OpenTK.Half.
Declaration
[Pure]
public static explicit operator Half(float f)
Parameters
Type | Name | Description |
---|---|---|
float | f | The float value to convert. |
Returns
Type | Description |
---|---|
Half | The Half result of the conversion. |
implicit operator double(Half)
Converts a OpenTK.Half to a System.Double.
Declaration
[Pure]
public static implicit operator double(Half h)
Parameters
Type | Name | Description |
---|---|---|
Half | h | The Half value to convert. |
Returns
Type | Description |
---|---|
double | The double result of the conversion. |
implicit operator float(Half)
Converts a OpenTK.Half to a System.Single.
Declaration
[Pure]
public static implicit operator float(Half h)
Parameters
Type | Name | Description |
---|---|---|
Half | h | The Half value to convert. |
Returns
Type | Description |
---|---|
float | The float result of the conversion. |
operator !=(Half, Half)
Declaration
public static bool operator !=(Half left, Half right)
Parameters
Type | Name | Description |
---|---|---|
Half | left | |
Half | right |
Returns
Type | Description |
---|---|
bool |