Constants

Trait Constants 

Source
pub trait Constants: Sized {
Show 16 methods // Required methods fn epsilon() -> Self; fn negative_one() -> Self; fn one_div_2() -> Self; fn pi() -> Self; fn two_pi() -> Self; fn pi_div_2() -> Self; fn two() -> Self; fn max_finite() -> Self; fn min_finite() -> Self; fn ln_2() -> Self; fn ln_10() -> Self; fn log10_2() -> Self; fn log2_10() -> Self; fn log2_e() -> Self; fn log10_e() -> Self; fn e() -> Self;
}
Expand description

Provides fundamental mathematical constants for floating-point scalar types.

This trait defines methods to obtain commonly used mathematical constants in the appropriate precision and type for the implementing scalar type. All constants are guaranteed to be finite and valid according to the scalar’s validation policy.

§Design Principles

  • Type-Appropriate Precision: Constants are provided at the precision of the implementing type (e.g., f64 precision for native types, arbitrary precision for rug types).
  • Validation Compliance: All returned constants are guaranteed to pass the validation policy of the implementing type.
  • Mathematical Accuracy: Constants use the most accurate representation available for the underlying numerical type.

§Usage Examples

use num_valid::{RealNative64StrictFinite, Constants, functions::Exp};
use try_create::TryNew;

// Get mathematical constants
let pi = RealNative64StrictFinite::pi();
let e = RealNative64StrictFinite::e();
let eps = RealNative64StrictFinite::epsilon();

// Use in calculations
let circle_area = pi.clone() * &(pi * RealNative64StrictFinite::two());
let exp_1 = e.exp(); // e^e

§Backend-Specific Behavior

§Native f64 Backend

  • Uses standard library constants like std::f64::consts::PI
  • IEEE 754 double precision (53-bit significand)
  • Hardware-optimized representations

§Arbitrary-Precision (rug) Backend

  • Constants computed at compile-time specified precision
  • Exact representations within precision limits
  • May use higher-precision intermediate calculations

Required Methods§

Source

fn epsilon() -> Self

Machine epsilon value for Self.

This is the difference between 1.0 and the next larger representable number. It represents the relative precision of the floating-point format.

§Examples
use num_valid::{RealNative64StrictFinite, Constants};

let eps = RealNative64StrictFinite::epsilon();
// For f64, this is approximately 2.220446049250313e-16
Source

fn negative_one() -> Self

Build and return the (floating point) value -1. represented by the proper type.

Source

fn one_div_2() -> Self

Build and return the (floating point) value 0.5 represented by the proper type.

Source

fn pi() -> Self

Build and return the (floating point) value π represented by the proper type.

Source

fn two_pi() -> Self

Build and return the (floating point) value 2 π represented by the proper type.

Source

fn pi_div_2() -> Self

Build and return the (floating point) value π/2 represented by the proper type.

Source

fn two() -> Self

Build and return the (floating point) value 2. represented by the proper type.

Source

fn max_finite() -> Self

Build and return the maximum finite value allowed by the current floating point representation.

Source

fn min_finite() -> Self

Build and return the minimum finite (i.e., the most negative) value allowed by the current floating point representation.

Source

fn ln_2() -> Self

Build and return the natural logarithm of 2, i.e. the (floating point) value ln(2), represented by the proper type.

Source

fn ln_10() -> Self

Build and return the natural logarithm of 10, i.e. the (floating point) value ln(10), represented by the proper type.

Source

fn log10_2() -> Self

Build and return the base-10 logarithm of 2, i.e. the (floating point) value Log_10(2), represented by the proper type.

Source

fn log2_10() -> Self

Build and return the base-2 logarithm of 10, i.e. the (floating point) value Log_2(10), represented by the proper type.

Source

fn log2_e() -> Self

Build and return the base-2 logarithm of e, i.e. the (floating point) value Log_2(e), represented by the proper type.

Source

fn log10_e() -> Self

Build and return the base-10 logarithm of e, i.e. the (floating point) value Log_10(e), represented by the proper type.

Source

fn e() -> Self

Build and return the (floating point) value e represented by the proper type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Constants for f64

Source§

fn epsilon() -> Self

Machine epsilon value for f64.

This is the difference between 1.0 and the next larger representable number.

Source§

fn negative_one() -> Self

Build and return the (floating point) value -1. represented by a f64.

Source§

fn one_div_2() -> Self

Build and return the (floating point) value 0.5 represented by the proper type.

Source§

fn two() -> Self

Build and return the (floating point) value 2.0.

Source§

fn max_finite() -> Self

Build and return the maximum finite value allowed by the current floating point representation.

Source§

fn min_finite() -> Self

Build and return the minimum finite (i.e., the most negative) value allowed by the current floating point representation.

Source§

fn pi() -> Self

Build and return the (floating point) value π.

Source§

fn two_pi() -> Self

Build and return the (floating point) value 2 π.

Source§

fn pi_div_2() -> Self

Build and return the (floating point) value π/2.

Source§

fn ln_2() -> Self

Build and return the natural logarithm of 2, i.e. the (floating point) value ln(2).

Source§

fn ln_10() -> Self

Build and return the natural logarithm of 10, i.e. the (floating point) value ln(10).

Source§

fn log10_2() -> Self

Build and return the base-10 logarithm of 2, i.e. the (floating point) value Log_10(2).

Source§

fn log2_10() -> Self

Build and return the base-2 logarithm of 10, i.e. the (floating point) value Log_2(10).

Source§

fn log2_e() -> Self

Build and return the base-2 logarithm of e, i.e. the (floating point) value Log_2(e).

Source§

fn log10_e() -> Self

Build and return the base-10 logarithm of e, i.e. the (floating point) value Log_10(e).

Source§

fn e() -> Self

Build and return the (floating point) value e represented by the proper type.

Implementors§