Float classification v0.1.0
IsNaN<T>
pub func IsNaN<T>(value: T) -> bool
Whether the value is not a number.
value is read by value. Returns true for every NaN, quiet or signaling, and false for everything else --
including both infinities, which are outside the finite range but are still ordered against it.
Cannot fail. Runs in constant time and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the integer or floating-point type, deduced from the arguments |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value to act on |
Returns: whether the value is a NaN, which no comparison can tell you
IsZero<T>
pub func IsZero<T>(value: T) -> bool
Whether the value is either zero.
value is read by value. Both +0.0 and -0.0 report true, since the two compare equal; IsNegativeZero
separates them. A NaN and an infinity report false, because subtracting either from itself gives a NaN.
Cannot fail. Runs in constant time and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the integer or floating-point type, deduced from the arguments |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value to act on |
Returns: whether the value is either signed zero
IsInfinite<T>
pub func IsInfinite<T>(value: T) -> bool
Whether the value is an infinity, of either sign.
value is read by value. A zero is excluded explicitly: it is the other value that doubles to itself.
Cannot fail. Runs in constant time and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the integer or floating-point type, deduced from the arguments |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value to act on |
Returns: whether the value is either infinity
IsFinite<T>
pub func IsFinite<T>(value: T) -> bool
Whether the value is an ordinary number: neither a NaN nor an infinity.
value is read by value. Every zero and every subnormal is finite.
Cannot fail. Runs in constant time and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the integer or floating-point type, deduced from the arguments |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value to act on |
Returns: whether the value is neither infinite nor a NaN
IsNegativeZero<T>
pub func IsNegativeZero<T>(value: T) -> bool
Whether the value is the zero that carries a minus sign.
value is read by value. -0.0 reports true and +0.0 reports false, though the two compare equal; every
other value, NaN included, reports false.
The sign of a zero is invisible to comparison, so it is read from the infinity the zero divides into: 1 / -0.0
is negative infinity and 1 / +0.0 is positive infinity. The division is exact and traps nothing, because
dividing by zero is a defined floating-point operation rather than an error.
Cannot fail. Runs in constant time and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the integer or floating-point type, deduced from the arguments |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value to act on |
Returns: whether the value is negative zero specifically, which == 0.0 cannot distinguish
IsSignNegative<T>
pub func IsSignNegative<T>(value: T) -> bool
Whether the value carries a minus sign.
value is read by value. Every negative number reports true, and so does -0.0 — which is why this is named
for the sign rather than for the comparison: -0.0 < 0 is false. A NaN reports false whichever sign its
encoding carries, since a NaN is outside the ordering and its sign has no arithmetic meaning.
Cannot fail. Runs in constant time and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the integer or floating-point type, deduced from the arguments |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value to act on |
Returns: whether the sign bit is set, which it is for negative zero and for a negative NaN
IsSignPositive<T>
pub func IsSignPositive<T>(value: T) -> bool
Whether the value carries a plus sign.
value is read by value. Every positive number reports true, and so does +0.0. A NaN reports false, so this
is not the negation of IsSignNegative: a NaN carries neither sign for these purposes.
Cannot fail. Runs in constant time and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the integer or floating-point type, deduced from the arguments |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value to act on |
Returns: whether the sign bit is clear
SignOf<T>
pub func SignOf<T>(value: T) -> T
The value's sign as one of -1, +1, or the zero it started from.
value is read by value; the answer is returned by copy in the same type. A zero returns itself, so -0.0
returns -0.0 and its sign is not lost. A NaN returns itself, since it has no sign to report.
Cannot fail. Runs in constant time and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the integer or floating-point type, deduced from the arguments |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value to act on |
Returns: -1, 0 or 1 as the value is negative, either zero, or positive