rint/rintf instead of roundeven/roundevenf
This commit is contained in:
@@ -39,9 +39,6 @@ mod musl_reference_tests {
|
|||||||
"jnf.rs",
|
"jnf.rs",
|
||||||
"j1.rs",
|
"j1.rs",
|
||||||
"j1f.rs",
|
"j1f.rs",
|
||||||
// musl doens't have these
|
|
||||||
"roundeven.rs",
|
|
||||||
"roundevenf.rs",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
struct Function {
|
struct Function {
|
||||||
|
|||||||
+4
-4
@@ -170,9 +170,9 @@ mod remainder;
|
|||||||
mod remainderf;
|
mod remainderf;
|
||||||
mod remquo;
|
mod remquo;
|
||||||
mod remquof;
|
mod remquof;
|
||||||
|
mod rint;
|
||||||
|
mod rintf;
|
||||||
mod round;
|
mod round;
|
||||||
mod roundeven;
|
|
||||||
mod roundevenf;
|
|
||||||
mod roundf;
|
mod roundf;
|
||||||
mod scalbn;
|
mod scalbn;
|
||||||
mod scalbnf;
|
mod scalbnf;
|
||||||
@@ -286,9 +286,9 @@ pub use self::remainder::remainder;
|
|||||||
pub use self::remainderf::remainderf;
|
pub use self::remainderf::remainderf;
|
||||||
pub use self::remquo::remquo;
|
pub use self::remquo::remquo;
|
||||||
pub use self::remquof::remquof;
|
pub use self::remquof::remquof;
|
||||||
|
pub use self::rint::rint;
|
||||||
|
pub use self::rintf::rintf;
|
||||||
pub use self::round::round;
|
pub use self::round::round;
|
||||||
pub use self::roundeven::roundeven;
|
|
||||||
pub use self::roundevenf::roundevenf;
|
|
||||||
pub use self::roundf::roundf;
|
pub use self::roundf::roundf;
|
||||||
pub use self::scalbn::scalbn;
|
pub use self::scalbn::scalbn;
|
||||||
pub use self::scalbnf::scalbnf;
|
pub use self::scalbnf::scalbnf;
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
// Source: musl libm rint
|
|
||||||
// (equivalent to roundeven when rounding mode is default,
|
|
||||||
// which Rust assumes)
|
|
||||||
|
|
||||||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
||||||
pub fn roundeven(x: f64) -> f64 {
|
pub fn rint(x: f64) -> f64 {
|
||||||
let one_over_e = 1.0 / f64::EPSILON;
|
let one_over_e = 1.0 / f64::EPSILON;
|
||||||
let as_u64: u64 = x.to_bits();
|
let as_u64: u64 = x.to_bits();
|
||||||
let exponent: u64 = as_u64 >> 52 & 0x7ff;
|
let exponent: u64 = as_u64 >> 52 & 0x7ff;
|
||||||
@@ -31,20 +27,20 @@ pub fn roundeven(x: f64) -> f64 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::roundeven;
|
use super::rint;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn negative_zero() {
|
fn negative_zero() {
|
||||||
assert_eq!(roundeven(-0.0_f64).to_bits(), (-0.0_f64).to_bits());
|
assert_eq!(rint(-0.0_f64).to_bits(), (-0.0_f64).to_bits());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sanity_check() {
|
fn sanity_check() {
|
||||||
assert_eq!(roundeven(-1.0), -1.0);
|
assert_eq!(rint(-1.0), -1.0);
|
||||||
assert_eq!(roundeven(2.8), 3.0);
|
assert_eq!(rint(2.8), 3.0);
|
||||||
assert_eq!(roundeven(-0.5), -0.0);
|
assert_eq!(rint(-0.5), -0.0);
|
||||||
assert_eq!(roundeven(0.5), 0.0);
|
assert_eq!(rint(0.5), 0.0);
|
||||||
assert_eq!(roundeven(-1.5), -2.0);
|
assert_eq!(rint(-1.5), -2.0);
|
||||||
assert_eq!(roundeven(1.5), 2.0);
|
assert_eq!(rint(1.5), 2.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
// Source: musl libm rintf
|
|
||||||
// (equivalent to roundevenf when rounding mode is default,
|
|
||||||
// which Rust assumes)
|
|
||||||
|
|
||||||
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
|
||||||
pub fn roundevenf(x: f32) -> f32 {
|
pub fn rintf(x: f32) -> f32 {
|
||||||
let one_over_e = 1.0 / f32::EPSILON;
|
let one_over_e = 1.0 / f32::EPSILON;
|
||||||
let as_u32: u32 = x.to_bits();
|
let as_u32: u32 = x.to_bits();
|
||||||
let exponent: u32 = as_u32 >> 23 & 0xff;
|
let exponent: u32 = as_u32 >> 23 & 0xff;
|
||||||
@@ -31,20 +27,20 @@ pub fn roundevenf(x: f32) -> f32 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::roundevenf;
|
use super::rintf;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn negative_zero() {
|
fn negative_zero() {
|
||||||
assert_eq!(roundevenf(-0.0_f32).to_bits(), (-0.0_f32).to_bits());
|
assert_eq!(rintf(-0.0_f32).to_bits(), (-0.0_f32).to_bits());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sanity_check() {
|
fn sanity_check() {
|
||||||
assert_eq!(roundevenf(-1.0), -1.0);
|
assert_eq!(rintf(-1.0), -1.0);
|
||||||
assert_eq!(roundevenf(2.8), 3.0);
|
assert_eq!(rintf(2.8), 3.0);
|
||||||
assert_eq!(roundevenf(-0.5), -0.0);
|
assert_eq!(rintf(-0.5), -0.0);
|
||||||
assert_eq!(roundevenf(0.5), 0.0);
|
assert_eq!(rintf(0.5), 0.0);
|
||||||
assert_eq!(roundevenf(-1.5), -2.0);
|
assert_eq!(rintf(-1.5), -2.0);
|
||||||
assert_eq!(roundevenf(1.5), 2.0);
|
assert_eq!(rintf(1.5), 2.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user