summaryrefslogtreecommitdiff
path: root/lib/math/scale2-impl.myr
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2018-05-24 09:02:45 -0400
committerS. Gilles <sgilles@math.umd.edu>2018-06-10 13:59:44 -0400
commit4aa0e6c6b8a1a23b144b0382d6156aaa55b2c7fd (patch)
treebda8ef5b4fef6fed767b70ca341841fbb47889b5 /lib/math/scale2-impl.myr
parentce931f082769f332e545cc477bc85c2bbca71ac2 (diff)
downloadmc-4aa0e6c6b8a1a23b144b0382d6156aaa55b2c7fd.tar.gz
Implement powr.
This is an attempt to extend the log algorithm of [Tan90] to compute x^y. I don't intend to keep this algorithm for long, since I didn't succeed very well. It's tremendously slow (worse even than mpfr!), and has some truly terrible edge cases. For example, computing pow(0x3f7ff7f3, 0xc7b58adf) (that is, (0.99987715)^(-92949.74)) returns infinity, when it should be 0x47b1d362 (91046.765), which is a dozen orders of magnitude below the infinity border. In more pedestrian cases, errors of up to ~16 ulps can be observed. For example, powr(0x3f80a83e, 0xc65492ba) = (1.0051343)^(-13604.682) should return 0x0d3304a3, but it gives 0x0d3304b4.
Diffstat (limited to 'lib/math/scale2-impl.myr')
-rw-r--r--lib/math/scale2-impl.myr5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/math/scale2-impl.myr b/lib/math/scale2-impl.myr
index e0683a7..f75aac8 100644
--- a/lib/math/scale2-impl.myr
+++ b/lib/math/scale2-impl.myr
@@ -41,8 +41,11 @@ generic scale2gen = {n : bool, e : @i, s : @u, emin : @i, emax : @i, p : @u, m :
sprime++
;;
eprime = emin - 1
+ elif e + m < emin - p - 2
+ sprime = 0
+ eprime = emin - 1
elif e + m < emin
- sprime = s >> (emin - m - e)
+ sprime = s >> ((emin - m - e) : @u)
if need_round_away(0, (s : uint64), ((emin - m - e) : int64))
sprime++
;;