Add roundf16 and roundf128
This commit is contained in:
parent
cdbe65b503
commit
d20a5e82a5
11 changed files with 78 additions and 2 deletions
|
|
@ -9,7 +9,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
|
|||
FloatTy::F16,
|
||||
Signature { args: &[Ty::F16], returns: &[Ty::F16] },
|
||||
None,
|
||||
&["ceilf16", "fabsf16", "floorf16", "rintf16", "sqrtf16", "truncf16"],
|
||||
&["ceilf16", "fabsf16", "floorf16", "rintf16", "roundf16", "sqrtf16", "truncf16"],
|
||||
),
|
||||
(
|
||||
// `fn(f32) -> f32`
|
||||
|
|
@ -40,7 +40,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
|
|||
FloatTy::F128,
|
||||
Signature { args: &[Ty::F128], returns: &[Ty::F128] },
|
||||
None,
|
||||
&["ceilf128", "fabsf128", "floorf128", "rintf128", "sqrtf128", "truncf128"],
|
||||
&["ceilf128", "fabsf128", "floorf128", "rintf128", "roundf128", "sqrtf128", "truncf128"],
|
||||
),
|
||||
(
|
||||
// `(f16, f16) -> f16`
|
||||
|
|
|
|||
|
|
@ -129,6 +129,8 @@ libm_macros::for_each_function! {
|
|||
| floorf16
|
||||
| rintf128
|
||||
| rintf16
|
||||
| roundf128
|
||||
| roundf16
|
||||
| sqrtf128
|
||||
| sqrtf16
|
||||
| truncf128
|
||||
|
|
|
|||
|
|
@ -175,6 +175,8 @@ libm_macros::for_each_function! {
|
|||
rintf16,
|
||||
round,
|
||||
roundf,
|
||||
roundf128,
|
||||
roundf16,
|
||||
scalbn,
|
||||
scalbnf,
|
||||
sincos,sincosf,
|
||||
|
|
@ -247,6 +249,7 @@ impl_no_round! {
|
|||
fabsf16 => abs_mut;
|
||||
floorf16 => floor_mut;
|
||||
rintf16 => round_even_mut; // FIXME: respect rounding mode
|
||||
roundf16 => round_mut;
|
||||
truncf16 => trunc_mut;
|
||||
}
|
||||
|
||||
|
|
@ -256,6 +259,7 @@ impl_no_round! {
|
|||
fabsf128 => abs_mut;
|
||||
floorf128 => floor_mut;
|
||||
rintf128 => round_even_mut; // FIXME: respect rounding mode
|
||||
roundf128 => round_mut;
|
||||
truncf128 => trunc_mut;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,8 @@ libm_macros::for_each_function! {
|
|||
floorf16,
|
||||
rintf128,
|
||||
rintf16,
|
||||
roundf128,
|
||||
roundf16,
|
||||
sqrtf128,
|
||||
sqrtf16,
|
||||
truncf128,
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
|
|||
| floorf16
|
||||
| rintf128
|
||||
| rintf16
|
||||
| roundf128
|
||||
| roundf16
|
||||
| sqrtf128
|
||||
| sqrtf16
|
||||
| truncf128
|
||||
|
|
|
|||
|
|
@ -697,6 +697,20 @@
|
|||
],
|
||||
"type": "f32"
|
||||
},
|
||||
"roundf128": {
|
||||
"sources": [
|
||||
"src/math/generic/round.rs",
|
||||
"src/math/roundf128.rs"
|
||||
],
|
||||
"type": "f128"
|
||||
},
|
||||
"roundf16": {
|
||||
"sources": [
|
||||
"src/math/generic/round.rs",
|
||||
"src/math/roundf16.rs"
|
||||
],
|
||||
"type": "f16"
|
||||
},
|
||||
"scalbn": {
|
||||
"sources": [
|
||||
"src/libm_helper.rs",
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ rintf128
|
|||
rintf16
|
||||
round
|
||||
roundf
|
||||
roundf128
|
||||
roundf16
|
||||
scalbn
|
||||
scalbnf
|
||||
sin
|
||||
|
|
|
|||
|
|
@ -12,6 +12,24 @@ pub fn round<F: Float>(x: F) -> F {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[cfg(f16_enabled)]
|
||||
fn zeroes_f16() {
|
||||
assert_biteq!(round(0.0_f16), 0.0_f16);
|
||||
assert_biteq!(round(-0.0_f16), -0.0_f16);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(f16_enabled)]
|
||||
fn sanity_check_f16() {
|
||||
assert_eq!(round(-1.0_f16), -1.0);
|
||||
assert_eq!(round(2.8_f16), 3.0);
|
||||
assert_eq!(round(-0.5_f16), -1.0);
|
||||
assert_eq!(round(0.5_f16), 1.0);
|
||||
assert_eq!(round(-1.5_f16), -2.0);
|
||||
assert_eq!(round(1.5_f16), 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zeroes_f32() {
|
||||
assert_biteq!(round(0.0_f32), 0.0_f32);
|
||||
|
|
@ -43,4 +61,22 @@ mod tests {
|
|||
assert_eq!(round(-1.5_f64), -2.0);
|
||||
assert_eq!(round(1.5_f64), 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(f128_enabled)]
|
||||
fn zeroes_f128() {
|
||||
assert_biteq!(round(0.0_f128), 0.0_f128);
|
||||
assert_biteq!(round(-0.0_f128), -0.0_f128);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(f128_enabled)]
|
||||
fn sanity_check_f128() {
|
||||
assert_eq!(round(-1.0_f128), -1.0);
|
||||
assert_eq!(round(2.8_f128), 3.0);
|
||||
assert_eq!(round(-0.5_f128), -1.0);
|
||||
assert_eq!(round(0.5_f128), 1.0);
|
||||
assert_eq!(round(-1.5_f128), -2.0);
|
||||
assert_eq!(round(1.5_f128), 2.0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -347,6 +347,7 @@ cfg_if! {
|
|||
mod fdimf16;
|
||||
mod floorf16;
|
||||
mod rintf16;
|
||||
mod roundf16;
|
||||
mod sqrtf16;
|
||||
mod truncf16;
|
||||
|
||||
|
|
@ -356,6 +357,7 @@ cfg_if! {
|
|||
pub use self::fdimf16::fdimf16;
|
||||
pub use self::floorf16::floorf16;
|
||||
pub use self::rintf16::rintf16;
|
||||
pub use self::roundf16::roundf16;
|
||||
pub use self::sqrtf16::sqrtf16;
|
||||
pub use self::truncf16::truncf16;
|
||||
}
|
||||
|
|
@ -369,6 +371,7 @@ cfg_if! {
|
|||
mod fdimf128;
|
||||
mod floorf128;
|
||||
mod rintf128;
|
||||
mod roundf128;
|
||||
mod sqrtf128;
|
||||
mod truncf128;
|
||||
|
||||
|
|
@ -378,6 +381,7 @@ cfg_if! {
|
|||
pub use self::fdimf128::fdimf128;
|
||||
pub use self::floorf128::floorf128;
|
||||
pub use self::rintf128::rintf128;
|
||||
pub use self::roundf128::roundf128;
|
||||
pub use self::sqrtf128::sqrtf128;
|
||||
pub use self::truncf128::truncf128;
|
||||
}
|
||||
|
|
|
|||
5
library/compiler-builtins/libm/src/math/roundf128.rs
Normal file
5
library/compiler-builtins/libm/src/math/roundf128.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/// Round `x` to the nearest integer, breaking ties away from zero.
|
||||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
||||
pub fn roundf128(x: f128) -> f128 {
|
||||
super::generic::round(x)
|
||||
}
|
||||
5
library/compiler-builtins/libm/src/math/roundf16.rs
Normal file
5
library/compiler-builtins/libm/src/math/roundf16.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/// Round `x` to the nearest integer, breaking ties away from zero.
|
||||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
||||
pub fn roundf16(x: f16) -> f16 {
|
||||
super::generic::round(x)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue