pub trait FpChecks {
// Required methods
fn is_finite(&self) -> bool;
fn is_infinite(&self) -> bool;
fn is_nan(&self) -> bool;
fn is_normal(&self) -> bool;
}
Expand description
Provides a set of fundamental floating-point classification checks.
This trait defines common methods to determine the characteristics of a numerical value,
such as whether it is finite, infinite, NaN (Not a Number), or normal.
It is implemented for standard floating-point types (f64
), complex numbers
(num::Complex<f64>
), and their arbitrary-precision counterparts from the rug
library (via RealRugStrictFinite<P>
and ComplexRugStrictFinite<P>
which internally use rug::Float
and rug::Complex
) when the “rug” feature is enabled.
FpChecks
is often used as a supertrait for more general numerical traits like
FpScalar
, ensuring that types representing floating-point
scalars can be queried for these basic properties. This is essential for
validation policies and writing robust numerical algorithms.
Note that this trait focuses on these specific classifications. For more detailed
categorization (like distinguishing subnormals or zero explicitly through this trait),
types may provide other methods (e.g., classify()
for f64
and rug::Float
,
or is_zero()
from FpScalar
).
Required Methods§
Sourcefn is_finite(&self) -> bool
fn is_finite(&self) -> bool
Returns true
if self
is finite (i.e., not infinite and not NaN).
For complex numbers, this typically means both the real and imaginary parts are finite.
Sourcefn is_infinite(&self) -> bool
fn is_infinite(&self) -> bool
Returns true
if self
is positive infinity or negative infinity.
For complex numbers, this typically means at least one part is infinite, and no part is NaN.