Classification and special values v0.1.0
FloatClass
pub enum FloatClass: int32 {
NotANumber = 0,
Infinite = 1,
Zero = 2,
Subnormal = 3,
Normal = 4
}
The five kinds IEEE 754 sorts every value into.
Copy.
Cases
| Name | Value | Description |
|---|---|---|
NotANumber | 0 | Not a number: the result of an operation with no meaningful answer. |
Infinite | 1 | One of the two infinities. |
Zero | 2 | Positive or negative zero. |
Subnormal | 3 | A value too small to carry a full significand, whose precision degrades toward zero. |
Normal | 4 | An ordinary value at full precision. |
IsNan
pub func IsNan(value: float64) -> bool
pub func IsNan(value: float32) -> bool
Whether value is a NaN.
A NaN is the only value not equal to itself, which is why this needs no bit pattern.
| Overload | Summary |
|---|---|
pub func IsNan(value: float64) -> bool | Whether value is a NaN. |
pub func IsNan(value: float32) -> bool | Determines whether value is a NaN at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | value to test |
Returns: true when value is a NaN
IsInfinite
pub func IsInfinite(value: float64) -> bool
pub func IsInfinite(value: float32) -> bool
Determines whether value is an infinity at float32 precision.
| Overload | Summary |
|---|---|
pub func IsInfinite(value: float64) -> bool | Whether value is one of the two infinities. |
pub func IsInfinite(value: float32) -> bool | Determines whether value is an infinity at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | value to test |
Returns: true when value is positive or negative infinity
IsFinite
pub func IsFinite(value: float64) -> bool
pub func IsFinite(value: float32) -> bool
Whether value is an ordinary number: neither a NaN nor an infinity.
| Overload | Summary |
|---|---|
pub func IsFinite(value: float64) -> bool | Whether value is an ordinary number: neither a NaN nor an infinity. |
pub func IsFinite(value: float32) -> bool | Determines whether value is finite at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | value to test |
Returns: true when value is neither a NaN nor an infinity
IsZero
pub func IsZero(value: float64) -> bool
pub func IsZero(value: float32) -> bool
Whether value is either zero.
Both zeros answer true; SignBit is what tells them apart.
| Overload | Summary |
|---|---|
pub func IsZero(value: float64) -> bool | Whether value is either zero. |
pub func IsZero(value: float32) -> bool | Determines whether value is either signed zero at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | value to test |
Returns: true when value is positive or negative zero
IsSubnormal
pub func IsSubnormal(value: float64) -> bool
pub func IsSubnormal(value: float32) -> bool
Whether value is subnormal: nonzero, but too small to carry a full significand.
| Overload | Summary |
|---|---|
pub func IsSubnormal(value: float64) -> bool | Whether value is subnormal: nonzero, but too small to carry a full significand. |
pub func IsSubnormal(value: float32) -> bool | Determines whether value is subnormal at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | value to test |
Returns: true when value is subnormal
IsNormal
pub func IsNormal(value: float64) -> bool
pub func IsNormal(value: float32) -> bool
Whether value is an ordinary value at full precision.
Zero is not normal, which surprises people and is the definition every IEEE 754 implementation uses.
| Overload | Summary |
|---|---|
pub func IsNormal(value: float64) -> bool | Whether value is an ordinary value at full precision. |
pub func IsNormal(value: float32) -> bool | Determines whether value is normal at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | value to test |
Returns: true when value is normal
Classify
pub func Classify(value: float64) -> FloatClass
pub func Classify(value: float32) -> FloatClass
Which of the five kinds value belongs to.
| Overload | Summary |
|---|---|
pub func Classify(value: float64) -> FloatClass | Which of the five kinds value belongs to. |
pub func Classify(value: float32) -> FloatClass | Classifies value at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | value to classify |
Returns: the IEEE-754 class of value
SignBit
pub func SignBit(value: float64) -> bool
pub func SignBit(value: float32) -> bool
Whether value's sign bit is set.
This is the sign bit, not a comparison: SignBit(-0.0) is true where -0.0 < 0.0 is false, and a negative NaN
answers true where every comparison against it answers false. That is the whole reason to ask by bit.
| Overload | Summary |
|---|---|
pub func SignBit(value: float64) -> bool | Whether value's sign bit is set. |
pub func SignBit(value: float32) -> bool | Determines whether the sign bit of value is set at float32 precision. |
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | value whose sign is inspected |
Returns: true when the sign bit is set
PositiveInfinity64
pub func PositiveInfinity64() -> float64
Positive infinity.
Returns: positive infinity at float64 precision
PositiveInfinity32
pub func PositiveInfinity32() -> float32
Positive infinity at the narrow width.
Returns: positive infinity at float32 precision
QuietNan64
pub func QuietNan64() -> float64
A quiet NaN.
Returns: A quiet NaN at float64 precision
QuietNan32
pub func QuietNan32() -> float32
A quiet NaN at the narrow width.
Returns: A quiet NaN at float32 precision