IsFinite v0.1.0
Reports whether a value is an ordinary number.
Package: Format
Signature
func IsFinite(value: float64) -> bool;
func IsFinite(value: float32) -> bool;
Parameters
| Name | Type | Description |
|---|---|---|
value | float64 / float32 | The value to test. |
Returns
true when the value is neither a NaN nor an infinity: every real number the type can hold, from the largest finite value down through the subnormals to zero, and the negative of each.
This is exactly the negation of IsNan or IsInfinite — the three partition the values, and every value answers true to precisely one of them. A NaN is not finite: the test is a pair of comparisons against the range of the type, and every comparison against a NaN is false.
As with IsInfinite, the width matters, and the overload is chosen by the argument. A float32 is measured against the float32 range.
Example
import Format::IsFinite;
func Main() -> int {
IsFinite(0.0); // true
IsFinite(-1.5e300); // true
IsFinite(5.0e-324); // true -- the smallest subnormal is still a number
IsFinite(1.0 / 0.0); // false
IsFinite(0.0 / 0.0); // false
IsFinite(3.4028235e38f32); // true -- the largest finite float32
IsFinite(1.0e300); // true -- as a float64
return 0;
}
See also
Format— the package overviewIsNan— whether the value is a NaNIsInfinite— whether the value is one of the two infinitiesToString— what each of the three classes prints as