pub type RugStrictFinite<const PRECISION: u32> = NumKernelStrictFinite<Float, PRECISION>;
Expand description
A type alias for a numerical kernel that uses rug
for arbitrary-precision arithmetic with strict finiteness checks.
This policy is a specialization of NumKernelStrictFinite
for the rug
backend.
It bundles the raw rug
types (rug::Float
and rug::Complex
) with their corresponding
validation logic, StrictFinitePolicy
.
The primary role of this policy is to serve as the generic parameter for the main validated
types, RealRugStrictFinite<PRECISION>
and ComplexRugStrictFinite<PRECISION>
, thereby
defining their behavior and ensuring their correctness.
§Validation
This policy enforces the following rules on the underlying rug::Float
values, for both
real numbers and the components of complex numbers:
- Finiteness: The value must not be
NaN
orInfinity
. - Precision: The precision of the
rug::Float
must exactly match thePRECISION
constant specified in the type. This is a critical check forrug
types.
§Example
While you typically won’t use RugStrictFinite
directly, it’s the engine that
powers the validated rug
types.
use num_valid::{RealRugStrictFinite, ComplexRugStrictFinite};
use rug::{Float, Complex};
use try_create::TryNew;
const PRECISION: u32 = 100;
// This works because the value is finite and has the correct precision.
let valid_real = RealRugStrictFinite::<PRECISION>::try_new(Float::with_val(PRECISION, 3.14)).unwrap();
// This fails because the precision is wrong.
let wrong_precision_real = RealRugStrictFinite::<PRECISION>::try_new(Float::with_val(PRECISION + 1, 3.14));
assert!(wrong_precision_real.is_err());
// This fails because the value is NaN.
let nan_real = RealRugStrictFinite::<PRECISION>::try_new(Float::with_val(PRECISION, f64::NAN));
assert!(nan_real.is_err());
// The same rules apply to complex numbers.
let valid_complex = ComplexRugStrictFinite::<PRECISION>::try_new(
Complex::with_val(PRECISION, (1.0, 2.0))
).unwrap();
let invalid_complex = ComplexRugStrictFinite::<PRECISION>::try_new(
Complex::with_val(PRECISION, (1.0, f64::INFINITY))
);
assert!(invalid_complex.is_err());
Aliased Type§
pub struct RugStrictFinite<const PRECISION: u32> { /* private fields */ }