use approximate equality with 1 ULP of tolerance
This commit is contained in:
@@ -10,3 +10,9 @@ pub use fabsf::fabsf;
|
|||||||
pub use powf::powf;
|
pub use powf::powf;
|
||||||
pub use scalbnf::scalbnf;
|
pub use scalbnf::scalbnf;
|
||||||
pub use sqrtf::sqrtf;
|
pub use sqrtf::sqrtf;
|
||||||
|
|
||||||
|
/// Approximate equality with 1 ULP of tolerance
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn _eqf(a: u32, b: u32) -> bool {
|
||||||
|
(a as i32).wrapping_sub(b as i32).abs() <= 1
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ macro_rules! f32_f32 {
|
|||||||
let outi = outf.to_bits();
|
let outi = outf.to_bits();
|
||||||
|
|
||||||
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
|
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
|
||||||
outi == expected) {{
|
libm::_eqf(outi, expected)) {{
|
||||||
panic!(
|
panic!(
|
||||||
\"input: {{}}, output: {{}}, expected: {{}}\",
|
\"input: {{}}, output: {{}}, expected: {{}}\",
|
||||||
inp,
|
inp,
|
||||||
@@ -124,7 +124,7 @@ macro_rules! f32f32_f32 {
|
|||||||
let outi = outf.to_bits();
|
let outi = outf.to_bits();
|
||||||
|
|
||||||
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
|
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
|
||||||
outi == expected) {{
|
libm::_eqf(outi, expected)) {{
|
||||||
panic!(
|
panic!(
|
||||||
\"input: {{:?}}, output: {{}}, expected: {{}}\",
|
\"input: {{:?}}, output: {{}}, expected: {{}}\",
|
||||||
(i1, i2),
|
(i1, i2),
|
||||||
@@ -182,7 +182,7 @@ macro_rules! f32i32_f32 {
|
|||||||
let outi = outf.to_bits();
|
let outi = outf.to_bits();
|
||||||
|
|
||||||
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
|
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
|
||||||
outi == expected) {{
|
libm::_eqf(outi, expected)) {{
|
||||||
panic!(
|
panic!(
|
||||||
\"input: {{:?}}, output: {{}}, expected: {{}}\",
|
\"input: {{:?}}, output: {{}}, expected: {{}}\",
|
||||||
(i1, i2),
|
(i1, i2),
|
||||||
|
|||||||
Reference in New Issue
Block a user