From 9d8ed3a7adf3023ddb2d6b6b6ed3ff483a52180c Mon Sep 17 00:00:00 2001 From: Igor null Date: Mon, 1 Jul 2019 17:10:44 +0300 Subject: [PATCH 1/3] Fix incorrect f32<->f64 casting in j1f/y1f --- src/math/j1f.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/math/j1f.rs b/src/math/j1f.rs index 83ac1ac..14e4ef5 100644 --- a/src/math/j1f.rs +++ b/src/math/j1f.rs @@ -49,7 +49,7 @@ fn common(ix: u32, x: f32, y1: bool, sign: bool) -> f32 { if sign { cc = -cc; } - return INVSQRTPI * (cc as f32) / sqrtf(x); + return (((INVSQRTPI as f64) * cc) / (sqrtf(x) as f64)) as f32; } /* R0/S0 on [0,2] */ @@ -356,3 +356,17 @@ fn qonef(x: f32) -> f32 { s = 1.0 + z * (q[0] + z * (q[1] + z * (q[2] + z * (q[3] + z * (q[4] + z * q[5]))))); return (0.375 + r / s) / x; } + +#[test] +fn test_j1f_2488() { + // 0x401F3E49 + assert_eq!( + j1f(2.4881766_f32), + 0.49999475_f32); +} +#[test] +fn test_y1f_2002() { + assert_eq!( + y1f(2.0000002_f32), + -0.10703229_f32); +} From 7b7d7cedf2f978fdfcf2db692a8e14cb0313f943 Mon Sep 17 00:00:00 2001 From: Igor null Date: Mon, 1 Jul 2019 17:18:59 +0300 Subject: [PATCH 2/3] fixed formatting in tests --- src/math/j1f.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/math/j1f.rs b/src/math/j1f.rs index 14e4ef5..d165ce3 100644 --- a/src/math/j1f.rs +++ b/src/math/j1f.rs @@ -360,13 +360,9 @@ fn qonef(x: f32) -> f32 { #[test] fn test_j1f_2488() { // 0x401F3E49 - assert_eq!( - j1f(2.4881766_f32), - 0.49999475_f32); + assert_eq!(j1f(2.4881766_f32), 0.49999475_f32); } #[test] fn test_y1f_2002() { - assert_eq!( - y1f(2.0000002_f32), - -0.10703229_f32); + assert_eq!(y1f(2.0000002_f32), -0.10703229_f32); } From 3f23cac465af35a8b5efb2620bab2f7d1cd8986d Mon Sep 17 00:00:00 2001 From: Igor null Date: Mon, 1 Jul 2019 17:21:43 +0300 Subject: [PATCH 3/3] separate tests into #[cfg(test)] mod --- src/math/j1f.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/math/j1f.rs b/src/math/j1f.rs index d165ce3..5095894 100644 --- a/src/math/j1f.rs +++ b/src/math/j1f.rs @@ -357,12 +357,16 @@ fn qonef(x: f32) -> f32 { return (0.375 + r / s) / x; } -#[test] -fn test_j1f_2488() { - // 0x401F3E49 - assert_eq!(j1f(2.4881766_f32), 0.49999475_f32); -} -#[test] -fn test_y1f_2002() { - assert_eq!(y1f(2.0000002_f32), -0.10703229_f32); +#[cfg(test)] +mod tests { + use super::{j1f, y1f}; + #[test] + fn test_j1f_2488() { + // 0x401F3E49 + assert_eq!(j1f(2.4881766_f32), 0.49999475_f32); + } + #[test] + fn test_y1f_2002() { + assert_eq!(y1f(2.0000002_f32), -0.10703229_f32); + } }