# HG changeset patch # User Tuomo Valkonen # Date 1746120558 18000 # Node ID acc344c20fa3f086a7378a2e3a0e30ed1b4895af # Parent 495448cca603576ff48a3fc827e515bc0313589a numseal diff -r 495448cca603 -r acc344c20fa3 src/types.rs --- a/src/types.rs Thu May 01 08:40:33 2025 -0500 +++ b/src/types.rs Thu May 01 12:29:18 2025 -0500 @@ -10,15 +10,12 @@ */ //use trait_set::trait_set; +pub use num_traits::cast::AsPrimitive; pub use num_traits::Float as NumTraitsFloat; // needed to re-export functions. -pub use num_traits::cast::AsPrimitive; pub use simba::scalar::{ - ClosedAdd, ClosedAddAssign, + ClosedAdd, ClosedAddAssign, ClosedDiv, ClosedDivAssign, ClosedMul, ClosedMulAssign, ClosedNeg, ClosedSub, ClosedSubAssign, - ClosedMul, ClosedMulAssign, - ClosedDiv, ClosedDivAssign, - ClosedNeg }; /// Typical integer type @@ -34,8 +31,12 @@ pub type float = f64; /// Casts of abstract numerical types to others via the standard `as` keyword. -pub trait CastFrom : num_traits::cast::AsPrimitive { - fn cast_from(other : T) -> Self; +pub trait CastFrom: num_traits::cast::AsPrimitive { + fn cast_from(other: T) -> Self; +} + +mod private { + pub trait NumSeal {} } macro_rules! impl_casts { @@ -58,53 +59,72 @@ f32 f64); /// Trait for general numeric types -pub trait Num : 'static + Copy + Sync + Send + num::Num + num_traits::NumAssign - + std::iter::Sum + std::iter::Product - + std::fmt::Debug + std::fmt::Display + serde::Serialize - + CastFrom + CastFrom + CastFrom + CastFrom - + CastFrom + CastFrom - + CastFrom + CastFrom + CastFrom + CastFrom - + CastFrom + CastFrom - + CastFrom + CastFrom - + crate::instance::Space { - - const ZERO : Self; - const ONE : Self; - const TWO : Self; +pub trait Num: + 'static + + Copy + + Sync + + Send + + num::Num + + num_traits::NumAssign + + std::iter::Sum + + std::iter::Product + + std::fmt::Debug + + std::fmt::Display + + serde::Serialize + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + CastFrom + + crate::instance::Space + + private::NumSeal +{ + const ZERO: Self; + const ONE: Self; + const TWO: Self; /// Generic version of `Self::MAX` - const RANGE_MAX : Self; + const RANGE_MAX: Self; /// Generic version of `Self::MIN` - const RANGE_MIN : Self; + const RANGE_MIN: Self; } /// Trait for signed numeric types -pub trait SignedNum : Num + num::Signed + std::ops::Neg {} -impl> SignedNum for U { } +pub trait SignedNum: Num + num::Signed + std::ops::Neg {} +impl> SignedNum for U {} /// Trait for floating point numbers -pub trait Float : SignedNum + num::Float /*+ From*/ { +pub trait Float: SignedNum + num::Float /*+ From*/ { // An unsigned integer that can be used for indexing operations and // converted to F without loss. //type CompatibleSize : CompatibleUnsigned; - const PI : Self; - const E : Self; - const EPSILON : Self; - const SQRT_2 : Self; - const INFINITY : Self; - const NEG_INFINITY : Self; - const NAN : Self; - const FRAC_2_SQRT_PI : Self; + const PI: Self; + const E: Self; + const EPSILON: Self; + const SQRT_2: Self; + const INFINITY: Self; + const NEG_INFINITY: Self; + const NAN: Self; + const FRAC_2_SQRT_PI: Self; } /// Trait for integers -pub trait Integer : Num + num::Integer {} +pub trait Integer: Num + num::Integer {} /// Trait for unsigned integers -pub trait Unsigned : Num + Integer + num::Unsigned {} +pub trait Unsigned: Num + Integer + num::Unsigned {} /// Trait for signed integers -pub trait Signed : SignedNum + Integer {} +pub trait Signed: SignedNum + Integer {} macro_rules! impl_num_consts { ($($type:ty)*) => { $( @@ -123,6 +143,7 @@ impl_num_consts!($type); impl Integer for $type {} impl $signed for $type {} + impl private::NumSeal for $type {} )* } } @@ -137,14 +158,14 @@ #[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))] type CompatibleSize = usize;*/ - const PI : Self = std::f64::consts::PI; - const E : Self = std::f64::consts::E; - const EPSILON : Self = std::f64::EPSILON; - const SQRT_2 : Self = std::f64::consts::SQRT_2; - const INFINITY : Self = std::f64::INFINITY; - const NEG_INFINITY : Self = std::f64::NEG_INFINITY; - const NAN : Self = std::f64::NAN; - const FRAC_2_SQRT_PI : Self = std::f64::consts::FRAC_2_SQRT_PI; + const PI: Self = std::f64::consts::PI; + const E: Self = std::f64::consts::E; + const EPSILON: Self = std::f64::EPSILON; + const SQRT_2: Self = std::f64::consts::SQRT_2; + const INFINITY: Self = std::f64::INFINITY; + const NEG_INFINITY: Self = std::f64::NEG_INFINITY; + const NAN: Self = std::f64::NAN; + const FRAC_2_SQRT_PI: Self = std::f64::consts::FRAC_2_SQRT_PI; } impl Float for f32 { @@ -155,20 +176,22 @@ type CompatibleSize = usize; */ - const PI : Self = std::f32::consts::PI; - const E : Self = std::f32::consts::E; - const EPSILON : Self = std::f32::EPSILON; - const SQRT_2 : Self = std::f32::consts::SQRT_2; - const INFINITY : Self = std::f32::INFINITY; - const NEG_INFINITY : Self = std::f32::NEG_INFINITY; - const NAN : Self = std::f32::NAN; - const FRAC_2_SQRT_PI : Self = std::f32::consts::FRAC_2_SQRT_PI; + const PI: Self = std::f32::consts::PI; + const E: Self = std::f32::consts::E; + const EPSILON: Self = std::f32::EPSILON; + const SQRT_2: Self = std::f32::consts::SQRT_2; + const INFINITY: Self = std::f32::INFINITY; + const NEG_INFINITY: Self = std::f32::NEG_INFINITY; + const NAN: Self = std::f32::NAN; + const FRAC_2_SQRT_PI: Self = std::f32::consts::FRAC_2_SQRT_PI; } +impl private::NumSeal for f32 {} +impl private::NumSeal for f64 {} + /* trait_set! { pub trait CompatibleUnsigned = Unsigned + Into; pub trait CompatibleSigned = Signed + Into; } */ -