diff --git a/src/libm_helper.rs b/src/libm_helper.rs index 52d0c4c2..dfaff8a0 100644 --- a/src/libm_helper.rs +++ b/src/libm_helper.rs @@ -30,7 +30,7 @@ macro_rules! libm_helper { } }; - ({$($func:tt);*}) => { + ({$($func:tt;)*}) => { $( libm_helper! { $func } )* @@ -103,7 +103,7 @@ libm_helper! { (fn trunc(x: f32) -> (f32); => truncf); (fn y0(x: f32) -> (f32); => y0f); (fn y1(x: f32) -> (f32); => y1f); - (fn yn(n: i32, x: f32) -> (f32); => ynf) + (fn yn(n: i32, x: f32) -> (f32); => ynf); } } @@ -166,6 +166,24 @@ libm_helper! { (fn trunc(x: f64) -> (f64); => trunc); (fn y0(x: f64) -> (f64); => y0); (fn y1(x: f64) -> (f64); => y1); - (fn yn(n: i32, x: f64) -> (f64); => yn) + (fn yn(n: i32, x: f64) -> (f64); => yn); + } +} + +#[cfg(f16_enabled)] +libm_helper! { + f16, + funcs: { + (fn abs(x: f16) -> (f16); => fabsf16); + (fn copysign(x: f16, y: f16) -> (f16); => copysignf16); + } +} + +#[cfg(f128_enabled)] +libm_helper! { + f128, + funcs: { + (fn abs(x: f128) -> (f128); => fabsf128); + (fn copysign(x: f128, y: f128) -> (f128); => copysignf128); } } diff --git a/src/math/copysignf128.rs b/src/math/copysignf128.rs new file mode 100644 index 00000000..58a8d938 --- /dev/null +++ b/src/math/copysignf128.rs @@ -0,0 +1,8 @@ +/// Sign of Y, magnitude of X (f32) +/// +/// Constructs a number with the magnitude (absolute value) of its +/// first argument, `x`, and the sign of its second argument, `y`. +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn copysignf128(x: f128, y: f128) -> f128 { + super::generic::copysign::copysign(x, y) +} diff --git a/src/math/copysignf16.rs b/src/math/copysignf16.rs new file mode 100644 index 00000000..6b4dcdd7 --- /dev/null +++ b/src/math/copysignf16.rs @@ -0,0 +1,8 @@ +/// Sign of Y, magnitude of X (f32) +/// +/// Constructs a number with the magnitude (absolute value) of its +/// first argument, `x`, and the sign of its second argument, `y`. +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn copysignf16(x: f16, y: f16) -> f16 { + super::generic::copysign::copysign(x, y) +} diff --git a/src/math/fabsf128.rs b/src/math/fabsf128.rs new file mode 100644 index 00000000..80f8cb6e --- /dev/null +++ b/src/math/fabsf128.rs @@ -0,0 +1,5 @@ +/// Absolute value (magnitude) of a `f128` value. +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fabsf128(x: f128) -> f128 { + super::generic::abs::abs(x) +} diff --git a/src/math/fabsf16.rs b/src/math/fabsf16.rs new file mode 100644 index 00000000..e2cd4a4e --- /dev/null +++ b/src/math/fabsf16.rs @@ -0,0 +1,5 @@ +/// Absolute value (magnitude) of a `f16` value. +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fabsf16(x: f16) -> f16 { + super::generic::abs::abs(x) +} diff --git a/src/math/mod.rs b/src/math/mod.rs index 510206ae..6f6e193b 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -302,6 +302,26 @@ pub use self::tgammaf::tgammaf; pub use self::trunc::trunc; pub use self::truncf::truncf; +cfg_if! { + if #[cfg(f16_enabled)] { + mod copysignf16; + mod fabsf16; + + pub use self::fabsf16::fabsf16; + pub use self::copysignf16::copysignf16; + } +} + +cfg_if! { + if #[cfg(f128_enabled)] { + mod copysignf128; + mod fabsf128; + + pub use self::fabsf128::fabsf128; + pub use self::copysignf128::copysignf128; + } +} + // Private modules mod expo2; mod fenv;