Module native64_validated

Module native64_validated 

Source
Expand description

§Validated Native 64-bit Kernel Types

This module provides convenient, pre-configured type aliases for the native f64 kernel. These types wrap f64 and num::Complex<f64> in the RealValidated and ComplexValidated structs, bundling them with specific validation policies.

These type aliases are the primary entry point for users who want to work with validated numbers that provide compile-time guarantees about their properties (e.g., finiteness).

§Policies

Two main policies are provided:

  • Native64StrictFinite: Enforces that all values are finite (not NaN or Infinity) in all build modes. Operations on types using this policy will panic on validation failure in debug builds and return a Result in release builds. This is the safest and most common choice.

  • Native64StrictFiniteInDebug: Also enforces finiteness, but validation checks that would panic are only performed in debug builds. In release builds, these checks are skipped for performance, and operations assume the inputs are valid. This is for performance-critical code where the developer can guarantee the validity of inputs.

§Example

use num_valid::kernels::native64_validated::RealNative64StrictFinite;
use num_valid::functions::Sqrt;
use try_create::TryNew;

// Creation succeeds because 4.0 is a valid, finite number.
let x = RealNative64StrictFinite::try_new(4.0).unwrap();

// Creation fails for non-finite numbers.
assert!(RealNative64StrictFinite::try_new(f64::NAN).is_err());

// Mathematical operations are available through traits.
let sqrt_x = x.sqrt();
assert_eq!(*sqrt_x.as_ref(), 2.0);

Type Aliases§

ComplexNative64StrictFinite
A validated complex number that guarantees its inner f64 parts are finite.
ComplexNative64StrictFiniteInDebug
A validated complex number that checks for finiteness only in debug builds.
Native64StrictFinite
A kernel policy that enforces strict finiteness for f64 and Complex<f64> values.
Native64StrictFiniteInDebug
A kernel policy that enforces strict finiteness for f64 values only in debug builds.
RealNative64StrictFinite
A validated real number that guarantees its inner f64 value is finite.
RealNative64StrictFiniteInDebug
A validated real number that checks for finiteness only in debug builds.