diff --git a/Cargo.lock b/Cargo.lock index 2622881..6687c98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,7 @@ dependencies = [ [[package]] name = "binding" version = "0.1.0" -source = "git+ssh://git@gitlab.com/CyberMages/Core/binding#8b5d5a9c57a7f87b26bb741067babb7a0b765ae7" +source = "git+ssh://git@gitlab.com/CyberMages/Core/binding#d408d4b239e5da791507f1624b9e98b74eaba75e" dependencies = [ "scribe 0.5.0 (git+ssh://git@gitlab.com/CyberMages/Core/scribe.git)", ] @@ -17,7 +17,7 @@ dependencies = [ [[package]] name = "pact" version = "0.1.0" -source = "git+ssh://git@gitlab.com/CyberMages/Core/pact#6fc48f7a2d8c8bc049418d1f8ede206cb8818d53" +source = "git+ssh://git@gitlab.com/CyberMages/Core/pact#4c817749dc7ea4185bbf2c44bad142399561b3fc" dependencies = [ "binding 0.1.0 (git+ssh://git@gitlab.com/CyberMages/Core/binding)", "scribe 0.5.0 (git+ssh://git@gitlab.com/CyberMages/Core/scribe.git)", @@ -32,7 +32,7 @@ source = "git+ssh://git@gitlab.com/CyberMages/Core/scribe.git#483ccd455c635e4975 [[package]] name = "weave" version = "0.1.0" -source = "git+ssh://git@gitlab.com/CyberMages/Core/weave.git#b0f38fb13bc7d1ed937fa51e499b602cb175c52b" +source = "git+ssh://git@gitlab.com/CyberMages/Core/weave.git#6813b8c17f4b705f62c6092ddd3e8ac933b5af18" dependencies = [ "scribe 0.5.0 (git+ssh://git@gitlab.com/CyberMages/Core/scribe.git)", ] diff --git a/src/number.rs b/src/number.rs index b643e99..799e488 100644 --- a/src/number.rs +++ b/src/number.rs @@ -1,4 +1,4 @@ -use std::cmp::PartialEq; +use std::cmp::{PartialEq, PartialOrd}; use std::fmt::{Debug, Display}; use std::mem::size_of; use std::ops::{Add, Sub, Mul, Div, Rem}; @@ -30,31 +30,33 @@ pub trait Number : Zero + One + Add + Sub + + /// Returns the maximum of the two numbers. /// - fn max(self, other: Self) -> Self - { - if self >= other - { - self - } - else - { - other - } - } + /// ``` + /// use ::sigils::Number; + /// + /// let x: f64; + /// let y: f64; + /// + /// x = 1.0f64; + /// y = 2.0f64; + /// assert_eq!(x.maximum(y), y); + /// ``` + fn maximum(self, other: Self) -> Self; + /// Returns the minimum of the two numbers. /// - fn min(self, other: Self) -> Self - { - if self <= other - { - self - } - else - { - other - } - } + /// ``` + /// use ::sigils::Number; + /// + /// let x: i16; + /// let y: i16; + /// + /// x = 22i16; + /// y = 55i16; + /// assert_eq!(x.minimum(y), x); + /// ``` + fn minimum(self, other: Self) -> Self; /// Create a number from a given string and base radix. /// @@ -797,6 +799,30 @@ macro_rules! int_number_trait_impl + fn maximum(self, other: Self) -> Self + { + if self >= other + { + self + } + else + { + other + } + } + + fn minimum(self, other: Self) -> Self + { + if self <= other + { + self + } + else + { + other + } + } + fn from_str_radix(src: &str, radix: u32) -> Result { @@ -810,7 +836,8 @@ macro_rules! int_number_trait_impl /// base float types in rust. macro_rules! float_number_trait_impl { - ($traitName: ident for $varType: ty, $min: expr, $max: expr) => + ($traitName: ident for $varType: ty, $min: expr, $max: expr, + $minFunc: ident, $maxFunc: ident) => { impl $traitName for $varType { @@ -823,6 +850,22 @@ macro_rules! float_number_trait_impl + fn maximum(self, other: Self) -> Self + { + unsafe + { + ::pact::math::$maxFunc(self, other) as Self + } + } + + fn minimum(self, other: Self) -> Self + { + unsafe + { + ::pact::math::$minFunc(self, other) as Self + } + } + fn from_str_radix(src: &str, radix: u32) -> Result { @@ -850,9 +893,11 @@ int_number_trait_impl!(Number for i32, -2147483648i32, 2147483647i32); int_number_trait_impl!(Number for i64, -9223372036854775808i64, 9223372036854775807i64); float_number_trait_impl!(Number for f32, -3.40282347e+38f32, - 3.40282347e+38f32); + 3.40282347e+38f32, + fminf, fmaxf); float_number_trait_impl!(Number for f64, -1.7976931348623157e+308f64, - 1.7976931348623157e+308f64); + 1.7976931348623157e+308f64, + fmin, fmax); #[cfg(target_pointer_width = "8")] int_number_trait_impl!(Number for usize, 0usize, 255usize); diff --git a/src/real.rs b/src/real.rs index c609ba2..14dd279 100644 --- a/src/real.rs +++ b/src/real.rs @@ -1,8 +1,8 @@ -use ::binding::{CDouble, CFloat, CInt}; - use std::num::FpCategory; use std::ops::Neg; +use binding::{CDouble, CFloat, CInt}; + use ::constants::Constants; use ::number::Number; use ::one::One; @@ -740,7 +740,7 @@ impl Real for f32 { unsafe { - ::pact::fmaf(self as CFloat, a as CFloat, b as CFloat) as Self + ::pact::math::fmaf(self as CFloat, a as CFloat, b as CFloat) as Self } } @@ -748,7 +748,7 @@ impl Real for f32 { unsafe { - ::pact::powf(self as CFloat, n as CFloat) as Self + ::pact::math::powf(self as CFloat, n as CFloat) as Self } } @@ -756,7 +756,7 @@ impl Real for f32 { unsafe { - ::pact::ceilf(self as CFloat) as Self + ::pact::math::ceilf(self as CFloat) as Self } } @@ -764,7 +764,7 @@ impl Real for f32 { unsafe { - ::pact::floorf(self as CFloat) as Self + ::pact::math::floorf(self as CFloat) as Self } } @@ -772,7 +772,7 @@ impl Real for f32 { unsafe { - ::pact::roundf(self as CFloat) as Self + ::pact::math::roundf(self as CFloat) as Self } } @@ -780,7 +780,7 @@ impl Real for f32 { unsafe { - ::pact::truncf(self as CFloat) as Self + ::pact::math::truncf(self as CFloat) as Self } } @@ -792,7 +792,7 @@ impl Real for f32 unsafe { - ::pact::modff(self as CFloat, &mut integer) as Self + ::pact::math::modff(self as CFloat, &mut integer) as Self } } @@ -800,7 +800,7 @@ impl Real for f32 { unsafe { - ::pact::fabsf(self as CFloat) as Self + ::pact::math::fabsf(self as CFloat) as Self } } @@ -813,7 +813,7 @@ impl Real for f32 { unsafe { - ::pact::sqrtf(self as CFloat) as Self + ::pact::math::sqrtf(self as CFloat) as Self } } @@ -821,7 +821,7 @@ impl Real for f32 { unsafe { - ::pact::cbrtf(self as CFloat) as Self + ::pact::math::cbrtf(self as CFloat) as Self } } @@ -829,7 +829,7 @@ impl Real for f32 { unsafe { - ::pact::expf(self as CFloat) as Self + ::pact::math::expf(self as CFloat) as Self } } @@ -837,7 +837,7 @@ impl Real for f32 { unsafe { - ::pact::exp2f(self as CFloat) as Self + ::pact::math::exp2f(self as CFloat) as Self } } @@ -845,7 +845,7 @@ impl Real for f32 { unsafe { - ::pact::expm1f(self as CFloat) as Self + ::pact::math::expm1f(self as CFloat) as Self } } @@ -853,7 +853,7 @@ impl Real for f32 { unsafe { - ::pact::logf(self as CFloat) as Self + ::pact::math::logf(self as CFloat) as Self } } @@ -866,7 +866,7 @@ impl Real for f32 { unsafe { - ::pact::log2f(self as CFloat) as Self + ::pact::math::log2f(self as CFloat) as Self } } @@ -874,7 +874,7 @@ impl Real for f32 { unsafe { - ::pact::log10f(self as CFloat) as Self + ::pact::math::log10f(self as CFloat) as Self } } @@ -882,7 +882,7 @@ impl Real for f32 { unsafe { - ::pact::log1pf(self as CFloat) as Self + ::pact::math::log1pf(self as CFloat) as Self } } } @@ -999,7 +999,7 @@ impl Real for f64 { unsafe { - ::pact::fma(self as CDouble, a as CDouble, b as CDouble) as Self + ::pact::math::fma(self as CDouble, a as CDouble, b as CDouble) as Self } } @@ -1007,7 +1007,7 @@ impl Real for f64 { unsafe { - ::pact::pow(self as CDouble, n as CDouble) as Self + ::pact::math::pow(self as CDouble, n as CDouble) as Self } } @@ -1015,7 +1015,7 @@ impl Real for f64 { unsafe { - ::pact::ceil(self as CDouble) as Self + ::pact::math::ceil(self as CDouble) as Self } } @@ -1023,7 +1023,7 @@ impl Real for f64 { unsafe { - ::pact::floor(self as CDouble) as Self + ::pact::math::floor(self as CDouble) as Self } } @@ -1031,7 +1031,7 @@ impl Real for f64 { unsafe { - ::pact::round(self as CDouble) as Self + ::pact::math::round(self as CDouble) as Self } } @@ -1039,7 +1039,7 @@ impl Real for f64 { unsafe { - ::pact::trunc(self as CDouble) as Self + ::pact::math::trunc(self as CDouble) as Self } } @@ -1051,7 +1051,7 @@ impl Real for f64 unsafe { - ::pact::modf(self as CDouble, &mut integer) as Self + ::pact::math::modf(self as CDouble, &mut integer) as Self } } @@ -1059,7 +1059,7 @@ impl Real for f64 { unsafe { - ::pact::fabs(self as CDouble) as Self + ::pact::math::fabs(self as CDouble) as Self } } @@ -1072,7 +1072,7 @@ impl Real for f64 { unsafe { - ::pact::sqrt(self as CDouble) as Self + ::pact::math::sqrt(self as CDouble) as Self } } @@ -1080,7 +1080,7 @@ impl Real for f64 { unsafe { - ::pact::cbrt(self as CDouble) as Self + ::pact::math::cbrt(self as CDouble) as Self } } @@ -1088,7 +1088,7 @@ impl Real for f64 { unsafe { - ::pact::exp(self as CDouble) as Self + ::pact::math::exp(self as CDouble) as Self } } @@ -1096,7 +1096,7 @@ impl Real for f64 { unsafe { - ::pact::exp2(self as CDouble) as Self + ::pact::math::exp2(self as CDouble) as Self } } @@ -1104,7 +1104,7 @@ impl Real for f64 { unsafe { - ::pact::expm1(self as CDouble) as Self + ::pact::math::expm1(self as CDouble) as Self } } @@ -1112,7 +1112,7 @@ impl Real for f64 { unsafe { - ::pact::log(self as CDouble) as Self + ::pact::math::log(self as CDouble) as Self } } @@ -1125,7 +1125,7 @@ impl Real for f64 { unsafe { - ::pact::log2(self as CDouble) as Self + ::pact::math::log2(self as CDouble) as Self } } @@ -1133,7 +1133,7 @@ impl Real for f64 { unsafe { - ::pact::log10(self as CDouble) as Self + ::pact::math::log10(self as CDouble) as Self } } @@ -1141,7 +1141,7 @@ impl Real for f64 { unsafe { - ::pact::log1p(self as CDouble) as Self + ::pact::math::log1p(self as CDouble) as Self } } } diff --git a/src/trig/trig.rs b/src/trig/trig.rs index c787190..11c5654 100644 --- a/src/trig/trig.rs +++ b/src/trig/trig.rs @@ -1,4 +1,4 @@ -use ::binding::{CDouble, CFloat}; +use binding::{CDouble, CFloat}; use ::real::Real; use ::trig::radian::Radian; @@ -193,7 +193,7 @@ impl Trig for f32 { unsafe { - ::pact::cosf(*arg.into() as CFloat) as Self + ::pact::math::cosf(*arg.into() as CFloat) as Self } } @@ -202,7 +202,7 @@ impl Trig for f32 { unsafe { - ::pact::sinf(*arg.into() as CFloat) as Self + ::pact::math::sinf(*arg.into() as CFloat) as Self } } @@ -211,7 +211,7 @@ impl Trig for f32 { unsafe { - ::pact::tanf(*arg.into() as CFloat) as Self + ::pact::math::tanf(*arg.into() as CFloat) as Self } } @@ -220,7 +220,7 @@ impl Trig for f32 { unsafe { - Radian::new(::pact::acosf(arg as CFloat) as Self).into() + Radian::new(::pact::math::acosf(arg as CFloat) as Self).into() } } @@ -229,7 +229,7 @@ impl Trig for f32 { unsafe { - Radian::new(::pact::asinf(arg as CFloat) as Self).into() + Radian::new(::pact::math::asinf(arg as CFloat) as Self).into() } } @@ -238,7 +238,7 @@ impl Trig for f32 { unsafe { - Radian::new(::pact::atanf(arg as CFloat) as Self).into() + Radian::new(::pact::math::atanf(arg as CFloat) as Self).into() } } @@ -247,7 +247,8 @@ impl Trig for f32 { unsafe { - Radian::new(::pact::atan2f(y as CFloat, x as CFloat) as Self).into() + Radian::new( + ::pact::math::atan2f(y as CFloat, x as CFloat) as Self).into() } } @@ -256,7 +257,7 @@ impl Trig for f32 { unsafe { - ::pact::coshf(arg as CFloat) as Self + ::pact::math::coshf(arg as CFloat) as Self } } @@ -264,7 +265,7 @@ impl Trig for f32 { unsafe { - ::pact::sinhf(arg as CFloat) as Self + ::pact::math::sinhf(arg as CFloat) as Self } } @@ -272,7 +273,7 @@ impl Trig for f32 { unsafe { - ::pact::tanhf(arg as CFloat) as Self + ::pact::math::tanhf(arg as CFloat) as Self } } @@ -280,7 +281,7 @@ impl Trig for f32 { unsafe { - ::pact::acoshf(arg as CFloat) as Self + ::pact::math::acoshf(arg as CFloat) as Self } } @@ -288,7 +289,7 @@ impl Trig for f32 { unsafe { - ::pact::asinhf(arg as CFloat) as Self + ::pact::math::asinhf(arg as CFloat) as Self } } @@ -296,7 +297,7 @@ impl Trig for f32 { unsafe { - ::pact::atanhf(arg as CFloat) as Self + ::pact::math::atanhf(arg as CFloat) as Self } } } @@ -308,7 +309,7 @@ impl Trig for f64 { unsafe { - ::pact::cos(*arg.into() as CDouble) as Self + ::pact::math::cos(*arg.into() as CDouble) as Self } } @@ -317,7 +318,7 @@ impl Trig for f64 { unsafe { - ::pact::sin(*arg.into() as CDouble) as Self + ::pact::math::sin(*arg.into() as CDouble) as Self } } @@ -326,7 +327,7 @@ impl Trig for f64 { unsafe { - ::pact::tan(*arg.into() as CDouble) as Self + ::pact::math::tan(*arg.into() as CDouble) as Self } } @@ -335,7 +336,7 @@ impl Trig for f64 { unsafe { - Radian::new(::pact::acos(arg as CDouble) as Self).into() + Radian::new(::pact::math::acos(arg as CDouble) as Self).into() } } @@ -344,7 +345,7 @@ impl Trig for f64 { unsafe { - Radian::new(::pact::asin(arg as CDouble) as Self).into() + Radian::new(::pact::math::asin(arg as CDouble) as Self).into() } } @@ -353,7 +354,7 @@ impl Trig for f64 { unsafe { - Radian::new(::pact::atan(arg as CDouble) as Self).into() + Radian::new(::pact::math::atan(arg as CDouble) as Self).into() } } @@ -362,7 +363,8 @@ impl Trig for f64 { unsafe { - Radian::new(::pact::atan2(y as CDouble, x as CDouble) as Self).into() + Radian::new( + ::pact::math::atan2(y as CDouble, x as CDouble) as Self).into() } } @@ -371,7 +373,7 @@ impl Trig for f64 { unsafe { - ::pact::cosh(arg as CDouble) as Self + ::pact::math::cosh(arg as CDouble) as Self } } @@ -379,7 +381,7 @@ impl Trig for f64 { unsafe { - ::pact::sinh(arg as CDouble) as Self + ::pact::math::sinh(arg as CDouble) as Self } } @@ -387,7 +389,7 @@ impl Trig for f64 { unsafe { - ::pact::tanh(arg as CDouble) as Self + ::pact::math::tanh(arg as CDouble) as Self } } @@ -395,7 +397,7 @@ impl Trig for f64 { unsafe { - ::pact::acosh(arg as CDouble) as Self + ::pact::math::acosh(arg as CDouble) as Self } } @@ -403,7 +405,7 @@ impl Trig for f64 { unsafe { - ::pact::asinh(arg as CDouble) as Self + ::pact::math::asinh(arg as CDouble) as Self } } @@ -411,7 +413,7 @@ impl Trig for f64 { unsafe { - ::pact::atanh(arg as CDouble) as Self + ::pact::math::atanh(arg as CDouble) as Self } } }