Represents a half-precision floating point number.
Half
00 Remarks
Note: Half is not fast enought and precision is also very bad, so is should not be used for matemathical computation (use Single instead). The main advantage of Half type is lower memory cost: two bytes per number. Half is typically used in graphical applications.
Note: All functions, where is used conversion half->float/float->half, are approx. ten times slower than float->double/double->float, i.e. ~3ns on 2GHz CPU.
References:
- Fast Half Float Conversions, Jeroen van der Zijp, link: http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
- IEEE 754 revision, link: http://grouper.ieee.org/groups/754/
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| .ctor | 7 | Initializes a new instance of System.Half to the value of the specified decimal number. |
| Negate | 1 | Returns the result of multiplying the specified System.Half value by negative one. |
| Add | 1 | Adds two specified System.Half values. |
| Subtract | 1 | Subtracts one specified System.Half value from another. |
| Multiply | 1 | Multiplies two specified System.Half values. |
| Divide | 1 | Divides two specified System.Half values. |
| op_UnaryPlus | 1 | Returns the value of the System.Half operand (the sign of the operand is unchanged). |
| op_UnaryNegation | 1 | Negates the value of the specified System.Half operand. |
| op_Addition | 1 | Adds two specified System.Half values. |
| op_Subtraction | 1 | Subtracts two specified System.Half values. |
| op_Multiply | 1 | Multiplies two specified System.Half values. |
| op_Division | 1 | Divides two specified System.Half values. |
| op_Equality | 1 | Returns a value indicating whether two instances of System.Half are equal. |
| op_Inequality | 1 | Returns a value indicating whether two instances of System.Half are not equal. |
| op_LessThan | 1 | Returns a value indicating whether a specified System.Half is less than another specified System.Half. |
| op_GreaterThan | 1 | Returns a value indicating whether a specified System.Half is greater than another specified System.Half. |
| op_LessThanOrEqual | 1 | Returns a value indicating whether a specified System.Half is less than or equal to another specified System.Half. |
| op_GreaterThanOrEqual | 1 | Returns a value indicating whether a specified System.Half is greater than or equal to another specified System.Half. |
| op_Implicit | 11 | Converts a System.Half to a double-precision floating-point number. |
| op_Explicit | 13 | Converts a System.Half to an 8-bit unsigned integer. |
| CompareTo | 2 | Compares this instance to a specified System.Half object. |
| Equals | 2 | Returns a value indicating whether this instance and a specified System.Half object represent the same value. |
| GetHashCode | 1 | Returns the hash code for this instance. |
| GetTypeCode | 1 | Returns the System.TypeCode for value type System.Half. |
| GetBytes | 1 | Returns the specified half-precision floating point value as an array of bytes. |
| GetBits | 1 | Converts the value of a specified instance of System.Half to its equivalent binary representation. |
| ToHalf | 2 | Returns a half-precision floating point number converted from two bytes at a specified position in a byte array. |
| Sign | 1 | Returns a value indicating the sign of a half-precision floating-point number. |
| Abs | 1 | Returns the absolute value of a half-precision floating-point number. |
| Max | 1 | Returns the larger of two half-precision floating-point numbers. |
| Min | 1 | Returns the smaller of two half-precision floating-point numbers. |
| IsNaN | 1 | Returns a value indicating whether the specified number evaluates to not a number (System.Half.NaN). |
| IsInfinity | 1 | Returns a value indicating whether the specified number evaluates to negative or positive infinity. |
| IsNegativeInfinity | 1 | Returns a value indicating whether the specified number evaluates to negative infinity. |
| IsPositiveInfinity | 1 | Returns a value indicating whether the specified number evaluates to positive infinity. |
| Parse | 4 | Converts the string representation of a number to its System.Half equivalent using the specified style and culture-specific format. |
| TryParse | 2 | Converts the string representation of a number to its System.Half equivalent. |
| ToString | 4 | Converts the numeric value of this instance to its equivalent string representation. |
| op_Exponent | 1 |
03 Fields
| Name | Overloads | Summary |
|---|---|---|
| Value | 1 | Internal representation of the half-precision floating-point number. |
| Epsilon | 2 | Represents the smallest positive System.Half value greater than zero. |
| MaxValue | 2 | Represents the largest possible value of System.Half. |
| MinValue | 2 | Represents the smallest possible value of System.Half. |
| NaN | 2 | Represents not a number (NaN). |
| NegativeInfinity | 2 | Represents negative infinity. |
| PositiveInfinity | 2 | Represents positive infinity. |
04 Members
Single)Initializes a new instance of System.Half to the value of the specified single-precision floating-point number.
| Name | Type | Description |
|---|---|---|
value | Single | The value to represent as a System.Half. |
Int32)Initializes a new instance of System.Half to the value of the specified 32-bit signed integer.
| Name | Type | Description |
|---|---|---|
value | Int32 | The value to represent as a System.Half. |
Int64)Initializes a new instance of System.Half to the value of the specified 64-bit signed integer.
| Name | Type | Description |
|---|---|---|
value | Int64 | The value to represent as a System.Half. |
Double)Initializes a new instance of System.Half to the value of the specified double-precision floating-point number.
| Name | Type | Description |
|---|---|---|
value | Double | The value to represent as a System.Half. |
Decimal)Initializes a new instance of System.Half to the value of the specified decimal number.
| Name | Type | Description |
|---|---|---|
value | Decimal | The value to represent as a System.Half. |
UInt32)Initializes a new instance of System.Half to the value of the specified 32-bit unsigned integer.
| Name | Type | Description |
|---|---|---|
value | UInt32 | The value to represent as a System.Half. |
UInt64)Initializes a new instance of System.Half to the value of the specified 64-bit unsigned integer.
| Name | Type | Description |
|---|---|---|
value | UInt64 | The value to represent as a System.Half. |
Returns the result of multiplying the specified System.Half value by negative one.
| Name | Type | Description |
|---|---|---|
half | Half | A System.Half. |
A System.Half with the value of half, but the opposite sign. -or- Zero, if half is zero.
Adds two specified System.Half values.
A System.Half value that is the sum of half1 and half2.
Subtracts one specified System.Half value from another.
The System.Half result of subtracting half2 from half1.
Multiplies two specified System.Half values.
| Name | Type | Description |
|---|---|---|
half1 | Half | A System.Half (the multiplicand). |
half2 | Half | A System.Half (the multiplier). |
A System.Half that is the result of multiplying half1 and half2.
Divides two specified System.Half values.
The System.Half that is the result of dividing half1 by half2.
Returns the value of the System.Half operand (the sign of the operand is unchanged).
| Name | Type | Description |
|---|---|---|
half | Half | The System.Half operand. |
The value of the operand, half.
Negates the value of the specified System.Half operand.
| Name | Type | Description |
|---|---|---|
half | Half | The System.Half operand. |
The result of half multiplied by negative one (-1).
Adds two specified System.Half values.
The System.Half result of adding half1 and half2.
Subtracts two specified System.Half values.
The System.Half result of subtracting half1 and half2.
Multiplies two specified System.Half values.
The System.Half result of multiplying half1 by half2.
Divides two specified System.Half values.
The System.Half result of half1 by half2.
Returns a value indicating whether two instances of System.Half are equal.
true if half1 and half2 are equal; otherwise, false.
Returns a value indicating whether two instances of System.Half are not equal.
true if half1 and half2 are not equal; otherwise, false.
Returns a value indicating whether a specified System.Half is less than another specified System.Half.
true if half1 is less than half1; otherwise, false.
Returns a value indicating whether a specified System.Half is greater than another specified System.Half.
true if half1 is greater than half2; otherwise, false.
Returns a value indicating whether a specified System.Half is less than or equal to another specified System.Half.
true if half1 is less than or equal to half2; otherwise, false.
Returns a value indicating whether a specified System.Half is greater than or equal to another specified System.Half.
true if half1 is greater than or equal to half2; otherwise, false.
Byte)Converts an 8-bit unsigned integer to a System.Half.
| Name | Type | Description |
|---|---|---|
value | Byte | An 8-bit unsigned integer. |
A System.Half that represents the converted 8-bit unsigned integer.
Int16)Converts a 16-bit signed integer to a System.Half.
| Name | Type | Description |
|---|---|---|
value | Int16 | A 16-bit signed integer. |
A System.Half that represents the converted 16-bit signed integer.
Char)Converts a Unicode character to a System.Half.
| Name | Type | Description |
|---|---|---|
value | Char | A Unicode character. |
A System.Half that represents the converted Unicode character.
Int32)Converts a 32-bit signed integer to a System.Half.
| Name | Type | Description |
|---|---|---|
value | Int32 | A 32-bit signed integer. |
A System.Half that represents the converted 32-bit signed integer.
Int64)Converts a 64-bit signed integer to a System.Half.
| Name | Type | Description |
|---|---|---|
value | Int64 | A 64-bit signed integer. |
A System.Half that represents the converted 64-bit signed integer.
Converts a System.Half to a single-precision floating-point number.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A single-precision floating-point number that represents the converted System.Half.
Converts a System.Half to a double-precision floating-point number.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A double-precision floating-point number that represents the converted System.Half.
SByte)Converts an 8-bit signed integer to a System.Half.
| Name | Type | Description |
|---|---|---|
value | SByte | An 8-bit signed integer. |
A System.Half that represents the converted 8-bit signed integer.
UInt16)Converts a 16-bit unsigned integer to a System.Half.
| Name | Type | Description |
|---|---|---|
value | UInt16 | A 16-bit unsigned integer. |
A System.Half that represents the converted 16-bit unsigned integer.
UInt32)Converts a 32-bit unsigned integer to a System.Half.
| Name | Type | Description |
|---|---|---|
value | UInt32 | A 32-bit unsigned integer. |
A System.Half that represents the converted 32-bit unsigned integer.
UInt64)Converts a 64-bit unsigned integer to a System.Half.
| Name | Type | Description |
|---|---|---|
value | UInt64 | A 64-bit unsigned integer. |
A System.Half that represents the converted 64-bit unsigned integer.
Single)Converts a single-precision floating-point number to a System.Half.
| Name | Type | Description |
|---|---|---|
value | Single | A single-precision floating-point number. |
A System.Half that represents the converted single-precision floating point number.
Double)Converts a double-precision floating-point number to a System.Half.
| Name | Type | Description |
|---|---|---|
value | Double | A double-precision floating-point number. |
A System.Half that represents the converted double-precision floating point number.
Decimal)Converts a decimal number to a System.Half.
| Name | Type | Description |
|---|---|---|
value | Decimal | decimal number |
A System.Half that represents the converted decimal number.
Converts a System.Half to an 8-bit unsigned integer.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
An 8-bit unsigned integer that represents the converted System.Half.
Converts a System.Half to a Unicode character.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A Unicode character that represents the converted System.Half.
Converts a System.Half to a 16-bit signed integer.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A 16-bit signed integer that represents the converted System.Half.
Converts a System.Half to a 32-bit signed integer.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A 32-bit signed integer that represents the converted System.Half.
Converts a System.Half to a 64-bit signed integer.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A 64-bit signed integer that represents the converted System.Half.
Converts a System.Half to a decimal number.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A decimal number that represents the converted System.Half.
Converts a System.Half to an 8-bit signed integer.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
An 8-bit signed integer that represents the converted System.Half.
Converts a System.Half to a 16-bit unsigned integer.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A 16-bit unsigned integer that represents the converted System.Half.
Converts a System.Half to a 32-bit unsigned integer.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A 32-bit unsigned integer that represents the converted System.Half.
Converts a System.Half to a 64-bit unsigned integer.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half to convert. |
A 64-bit unsigned integer that represents the converted System.Half.
Compares this instance to a specified System.Half object.
| Name | Type | Description |
|---|---|---|
other | Half | A System.Half object. |
A signed number indicating the relative values of this instance and value. Return Value Meaning Less than zero This instance is less than value. Zero This instance is equal to value. Greater than zero This instance is greater than value.
Object)Compares this instance to a specified System.Object.
| Name | Type | Description |
|---|---|---|
obj | Object | An System.Object or null. |
A signed number indicating the relative values of this instance and value. Return Value Meaning Less than zero This instance is less than value. Zero This instance is equal to value. Greater than zero This instance is greater than value. -or- value is null.
Returns a value indicating whether this instance and a specified System.Half object represent the same value.
| Name | Type | Description |
|---|---|---|
other | Half | A System.Half object to compare to this instance. |
true if value is equal to this instance; otherwise, false.
Object)Returns a value indicating whether this instance and a specified System.Object represent the same type and value.
| Name | Type | Description |
|---|---|---|
obj | Object | An System.Object. |
true if value is a System.Half and equal to this instance; otherwise, false.
Returns the hash code for this instance.
A 32-bit signed integer hash code.
Returns the System.TypeCode for value type System.Half.
The enumerated constant (TypeCode)255.
Returns the specified half-precision floating point value as an array of bytes.
| Name | Type | Description |
|---|---|---|
value | Half | The number to convert. |
An array of bytes with length 2.
Converts the value of a specified instance of System.Half to its equivalent binary representation.
| Name | Type | Description |
|---|---|---|
value | Half | A System.Half value. |
A 16-bit unsigned integer that contain the binary representation of value.
Byte(), Int32)Returns a half-precision floating point number converted from two bytes at a specified position in a byte array.
| Name | Type | Description |
|---|---|---|
value | Byte() | An array of bytes. |
startIndex | Int32 | The starting position within value. |
A half-precision floating point number formed by two bytes beginning at startIndex.
UInt16)Returns a half-precision floating point number converted from its binary representation.
| Name | Type | Description |
|---|---|---|
bits | UInt16 | Binary representation of System.Half value |
A half-precision floating point number formed by its binary representation.
Returns a value indicating the sign of a half-precision floating-point number.
| Name | Type | Description |
|---|---|---|
value | Half | A signed number. |
A number indicating the sign of value. Number Description -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.
Returns the absolute value of a half-precision floating-point number.
| Name | Type | Description |
|---|---|---|
value | Half | A number in the range System.Half.MinValue ≤ value ≤ System.Half.MaxValue. |
A half-precision floating-point number, x, such that 0 ≤ x ≤System.Half.MaxValue.
Returns the larger of two half-precision floating-point numbers.
| Name | Type | Description |
|---|---|---|
value1 | Half | The first of two half-precision floating-point numbers to compare. |
value2 | Half | The second of two half-precision floating-point numbers to compare. |
Parameter value1 or value2, whichever is larger. If value1, or value2, or both val1 and value2 are equal to System.Half.NaN, System.Half.NaN is returned.
Returns the smaller of two half-precision floating-point numbers.
| Name | Type | Description |
|---|---|---|
value1 | Half | The first of two half-precision floating-point numbers to compare. |
value2 | Half | The second of two half-precision floating-point numbers to compare. |
Parameter value1 or value2, whichever is smaller. If value1, or value2, or both val1 and value2 are equal to System.Half.NaN, System.Half.NaN is returned.
Returns a value indicating whether the specified number evaluates to not a number (System.Half.NaN).
| Name | Type | Description |
|---|---|---|
half | Half | A half-precision floating-point number. |
true if value evaluates to not a number (System.Half.NaN); otherwise, false.
Returns a value indicating whether the specified number evaluates to negative or positive infinity.
| Name | Type | Description |
|---|---|---|
half | Half | A half-precision floating-point number. |
true if half evaluates to System.Half.PositiveInfinity or System.Half.NegativeInfinity; otherwise, false.
Returns a value indicating whether the specified number evaluates to negative infinity.
| Name | Type | Description |
|---|---|---|
half | Half | A half-precision floating-point number. |
true if half evaluates to System.Half.NegativeInfinity; otherwise, false.
Returns a value indicating whether the specified number evaluates to positive infinity.
| Name | Type | Description |
|---|---|---|
half | Half | A half-precision floating-point number. |
true if half evaluates to System.Half.PositiveInfinity; otherwise, false.
String)Converts the string representation of a number to its System.Half equivalent.
| Name | Type | Description |
|---|---|---|
value | String | The string representation of the number to convert. |
The System.Half number equivalent to the number contained in value.
String, IFormatProvider)Converts the string representation of a number to its System.Half equivalent using the specified culture-specific format information.
| Name | Type | Description |
|---|---|---|
value | String | The string representation of the number to convert. |
provider | IFormatProvider | An System.IFormatProvider that supplies culture-specific parsing information about value. |
The System.Half number equivalent to the number contained in s as specified by provider.
String, NumberStyles)Converts the string representation of a number in a specified style to its System.Half equivalent.
| Name | Type | Description |
|---|---|---|
value | String | The string representation of the number to convert. |
style | NumberStyles | A bitwise combination of System.Globalization.NumberStyles values that indicates the style elements that can be present in value. A typical value to specify is System.Globalization.NumberStyles.Number. |
The System.Half number equivalent to the number contained in s as specified by style.
String, NumberStyles, IFormatProvider)Converts the string representation of a number to its System.Half equivalent using the specified style and culture-specific format.
| Name | Type | Description |
|---|---|---|
value | String | The string representation of the number to convert. |
style | NumberStyles | A bitwise combination of System.Globalization.NumberStyles values that indicates the style elements that can be present in value. A typical value to specify is System.Globalization.NumberStyles.Number. |
provider | IFormatProvider | An System.IFormatProvider object that supplies culture-specific information about the format of value. |
The System.Half number equivalent to the number contained in s as specified by style and provider.
String, Half)Converts the string representation of a number to its System.Half equivalent. A return value indicates whether the conversion succeeded or failed.
| Name | Type | Description |
|---|---|---|
value | String | The string representation of the number to convert. |
result | Half | When this method returns, contains the System.Half number that is equivalent to the numeric value contained in value, if the conversion succeeded, or is zero if the conversion failed. The conversion fails if the s parameter is null, is not a number in a valid format, or represents a number less than System.Half.MinValue or greater than System.Half.MaxValue. This parameter is passed uninitialized. |
true if s was converted successfully; otherwise, false.
Converts the string representation of a number to its System.Half equivalent using the specified style and culture-specific format. A return value indicates whether the conversion succeeded or failed.
| Name | Type | Description |
|---|---|---|
value | String | The string representation of the number to convert. |
style | NumberStyles | A bitwise combination of System.Globalization.NumberStyles values that indicates the permitted format of value. A typical value to specify is System.Globalization.NumberStyles.Number. |
provider | IFormatProvider | An System.IFormatProvider object that supplies culture-specific parsing information about value. |
result | Half | When this method returns, contains the System.Half number that is equivalent to the numeric value contained in value, if the conversion succeeded, or is zero if the conversion failed. The conversion fails if the s parameter is null, is not in a format compliant with style, or represents a number less than System.Half.MinValue or greater than System.Half.MaxValue. This parameter is passed uninitialized. |
true if s was converted successfully; otherwise, false.
Converts the numeric value of this instance to its equivalent string representation.
A string that represents the value of this instance.
IFormatProvider)Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
| Name | Type | Description |
|---|---|---|
formatProvider | IFormatProvider | An System.IFormatProvider that supplies culture-specific formatting information. |
The string representation of the value of this instance as specified by provider.
String)Converts the numeric value of this instance to its equivalent string representation, using the specified format.
| Name | Type | Description |
|---|---|---|
format | String | A numeric format string. |
The string representation of the value of this instance as specified by format.
String, IFormatProvider)Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.
| Name | Type | Description |
|---|---|---|
format | String | A numeric format string. |
formatProvider | IFormatProvider | An System.IFormatProvider that supplies culture-specific formatting information. |
The string representation of the value of this instance as specified by format and provider.
Internal representation of the half-precision floating-point number.
Represents the smallest positive System.Half value greater than zero. This field is constant.
Represents the largest possible value of System.Half. This field is constant.
Represents the smallest possible value of System.Half. This field is constant.
Represents not a number (NaN). This field is constant.
Represents negative infinity. This field is constant.
Represents positive infinity. This field is constant.
Single)