Skip to content

Commit 4dd3705

Browse files
authored
Merge pull request rust-lang#189 from m1el/j1f-f64-casts
Fix incorrect f32<->f64 casting in j1f/y1f
2 parents 7231718 + 3f23cac commit 4dd3705

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/math/j1f.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn common(ix: u32, x: f32, y1: bool, sign: bool) -> f32 {
4949
if sign {
5050
cc = -cc;
5151
}
52-
return INVSQRTPI * (cc as f32) / sqrtf(x);
52+
return (((INVSQRTPI as f64) * cc) / (sqrtf(x) as f64)) as f32;
5353
}
5454

5555
/* R0/S0 on [0,2] */
@@ -356,3 +356,17 @@ fn qonef(x: f32) -> f32 {
356356
s = 1.0 + z * (q[0] + z * (q[1] + z * (q[2] + z * (q[3] + z * (q[4] + z * q[5])))));
357357
return (0.375 + r / s) / x;
358358
}
359+
360+
#[cfg(test)]
361+
mod tests {
362+
use super::{j1f, y1f};
363+
#[test]
364+
fn test_j1f_2488() {
365+
// 0x401F3E49
366+
assert_eq!(j1f(2.4881766_f32), 0.49999475_f32);
367+
}
368+
#[test]
369+
fn test_y1f_2002() {
370+
assert_eq!(y1f(2.0000002_f32), -0.10703229_f32);
371+
}
372+
}

0 commit comments

Comments
 (0)