Skip to content

Commit de8ed2d

Browse files
authored
Merge pull request rust-lang#165 from m1el/rem_pio2_ret_medium
rem_pio2: actually return medium value for x ~ 2pi/2
2 parents d3f1dba + 355f941 commit de8ed2d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/math/rem_pio2.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) {
8585
/* |x| ~<= 5pi/4 */
8686
if (ix & 0xfffff) == 0x921fb {
8787
/* |x| ~= pi/2 or 2pi/2 */
88-
medium(x, ix); /* cancellation -- use medium case */
88+
return medium(x, ix); /* cancellation -- use medium case */
8989
}
9090
if ix <= 0x4002d97c {
9191
/* |x| ~<= 3pi/4 */
@@ -185,3 +185,23 @@ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) {
185185
}
186186
(n, ty[0], ty[1])
187187
}
188+
189+
#[test]
190+
fn test_near_pi() {
191+
assert_eq!(
192+
rem_pio2(3.141592025756836),
193+
(2, -6.278329573009626e-7, -2.1125998133974653e-23)
194+
);
195+
assert_eq!(
196+
rem_pio2(3.141592033207416),
197+
(2, -6.20382377148128e-7, -2.1125998133974653e-23)
198+
);
199+
assert_eq!(
200+
rem_pio2(3.141592144966125),
201+
(2, -5.086236681942706e-7, -2.1125998133974653e-23)
202+
);
203+
assert_eq!(
204+
rem_pio2(3.141592979431152),
205+
(2, 3.2584135866119817e-7, -2.1125998133974653e-23)
206+
);
207+
}

src/math/sin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,10 @@ pub fn sin(x: f64) -> f64 {
7777
_ => -k_cos(y0, y1),
7878
}
7979
}
80+
81+
#[test]
82+
fn test_near_pi() {
83+
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
84+
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
85+
assert_eq!(sin(x), sx);
86+
}

0 commit comments

Comments
 (0)