summaryrefslogtreecommitdiff
path: root/lib/math
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2018-06-30 17:22:21 -0400
committerS. Gilles <sgilles@math.umd.edu>2018-06-30 17:22:21 -0400
commit0f79e7dd998f35f84ce794cc5adeaad683ac0022 (patch)
treeee210390c470e882065ab777be9c1347ef021072 /lib/math
parent5a6878701b5066d0143b0a2e21be35ce7f3d8976 (diff)
downloadmc-0f79e7dd998f35f84ce794cc5adeaad683ac0022.tar.gz
Remove a sort or two in sin/cos.
Diffstat (limited to 'lib/math')
-rw-r--r--lib/math/sin-impl.myr13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/math/sin-impl.myr b/lib/math/sin-impl.myr
index ca6dafd..8f52c11 100644
--- a/lib/math/sin-impl.myr
+++ b/lib/math/sin-impl.myr
@@ -521,7 +521,8 @@ const w64 = {x : flt64, want_sin : bool, want_cos : bool
sin(delta); the degree 2 coefficient is near 0, so delta_2
only shows up in deg 1
*/
- sin_delta = horner_polyu(delta1, sin_coeff[:]) + delta2 * std.flt64frombits(sin_coeff[1])
+ sin_delta = horner_polyu(delta1, sin_coeff[:])
+ sin_delta += delta2 * std.flt64frombits(sin_coeff[1])
/*
cos(delta); delta_2 shows up in deg 1 and 2; the term
@@ -537,7 +538,6 @@ const w64 = {x : flt64, want_sin : bool, want_cos : bool
(q[2], q[3]) = two_by_two(std.flt64frombits(cos_xi), sin_delta)
std.sort(q[:], fltabscmp)
- /* TODO: use double-compensation instead */
(sin_ret, sin_ret2) = double_compensated_sum(q[:])
;;
@@ -546,9 +546,14 @@ const w64 = {x : flt64, want_sin : bool, want_cos : bool
(q[2], q[3]) = two_by_two(std.flt64frombits(sin_xi), sin_delta)
q[2] = -q[2]
q[3] = -q[3]
- std.sort(q[:], fltabscmp)
- /* TODO: use double-compensation instead */
+ /*
+ No need to sort; cos_xi and sin_xi are in [0,1],
+ cos_delta is close to 1, sin_delta is close to
+ 0.
+ */
+ std.swap(&q[1], &q[2])
+
(cos_ret, cos_ret2) = double_compensated_sum(q[:])
;;