Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

rem_pio2: actually return medium value for x ~ 2pi/2 #165

Merged
merged 3 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/math/rem_pio2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) {
/* |x| ~<= 5pi/4 */
if (ix & 0xfffff) == 0x921fb {
/* |x| ~= pi/2 or 2pi/2 */
medium(x, ix); /* cancellation -- use medium case */
return medium(x, ix); /* cancellation -- use medium case */
}
if ix <= 0x4002d97c {
/* |x| ~<= 3pi/4 */
Expand Down Expand Up @@ -185,3 +185,23 @@ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) {
}
(n, ty[0], ty[1])
}

#[test]
fn test_near_pi() {
assert_eq!(
rem_pio2(3.141592025756836),
(2, -6.278329573009626e-7, -2.1125998133974653e-23)
);
assert_eq!(
rem_pio2(3.141592033207416),
(2, -6.20382377148128e-7, -2.1125998133974653e-23)
);
assert_eq!(
rem_pio2(3.141592144966125),
(2, -5.086236681942706e-7, -2.1125998133974653e-23)
);
assert_eq!(
rem_pio2(3.141592979431152),
(2, 3.2584135866119817e-7, -2.1125998133974653e-23)
);
}
7 changes: 7 additions & 0 deletions src/math/sin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,10 @@ pub fn sin(x: f64) -> f64 {
_ => -k_cos(y0, y1),
}
}

#[test]
fn test_near_pi() {
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
assert_eq!(sin(x), sx);
}