-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
fabsf16
, fabsf128
, copysignf16
, and copysignf128
Use the generic implementations to provide these simple methods.
- Loading branch information
Showing
8 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// Sign of Y, magnitude of X (f128) | ||
/// | ||
/// 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(x, y) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// Sign of Y, magnitude of X (f16) | ||
/// | ||
/// 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(x, y) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// Absolute value (magnitude) (f128) | ||
/// | ||
/// Calculates the absolute value (magnitude) of the argument `x`, | ||
/// by direct manipulation of the bit representation of `x`. | ||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] | ||
pub fn fabsf128(x: f128) -> f128 { | ||
select_implementation! { | ||
name: fabsf, | ||
use_intrinsic: target_arch = "wasm32", | ||
args: x, | ||
} | ||
|
||
super::generic::fabs(x) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn sanity_check() { | ||
assert_eq!(fabsf128(-1.0), 1.0); | ||
assert_eq!(fabsf128(2.8), 2.8); | ||
} | ||
|
||
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs | ||
#[test] | ||
fn spec_tests() { | ||
assert!(fabsf128(f128::NAN).is_nan()); | ||
for f in [0.0, -0.0].iter().copied() { | ||
assert_eq!(fabsf128(f), 0.0); | ||
} | ||
for f in [f128::INFINITY, f128::NEG_INFINITY].iter().copied() { | ||
assert_eq!(fabsf128(f), f128::INFINITY); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// Absolute value (magnitude) (f16) | ||
/// | ||
/// Calculates the absolute value (magnitude) of the argument `x`, | ||
/// by direct manipulation of the bit representation of `x`. | ||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] | ||
pub fn fabsf16(x: f16) -> f16 { | ||
select_implementation! { | ||
name: fabsf, | ||
use_intrinsic: target_arch = "wasm32", | ||
args: x, | ||
} | ||
|
||
super::generic::fabs(x) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn sanity_check() { | ||
assert_eq!(fabsf16(-1.0), 1.0); | ||
assert_eq!(fabsf16(2.8), 2.8); | ||
} | ||
|
||
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs | ||
#[test] | ||
fn spec_tests() { | ||
assert!(fabsf16(f16::NAN).is_nan()); | ||
for f in [0.0, -0.0].iter().copied() { | ||
assert_eq!(fabsf16(f), 0.0); | ||
} | ||
for f in [f16::INFINITY, f16::NEG_INFINITY].iter().copied() { | ||
assert_eq!(fabsf16(f), f16::INFINITY); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters