summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2019-05-01 15:51:51 -0400
committerS. Gilles <sgilles@math.umd.edu>2019-05-01 15:51:51 -0400
commitfb2a06c91f60a948687939741aa884b17219f715 (patch)
tree778cf1938eb5b0d2dfa74ac99d2f15f45f802645 /lib
parent2fd5ae3c5599fdd067ed11f3a58fb03da587db28 (diff)
downloadmc-fb2a06c91f60a948687939741aa884b17219f715.tar.gz
Add fltXXfromuintXX to ancillary math script.
Diffstat (limited to 'lib')
-rw-r--r--lib/math/ancillary/ulp.gp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/math/ancillary/ulp.gp b/lib/math/ancillary/ulp.gp
index bf86208..9a4b155 100644
--- a/lib/math/ancillary/ulp.gp
+++ b/lib/math/ancillary/ulp.gp
@@ -25,3 +25,25 @@
{ err64(x, y) =
return(abs(x-y)/ulp64(x));
}
+
+{ flt32fromuint32(a) = my(n, e, s);
+ n = bitand(a, 0x80000000) != 0;
+ e = bitand(a, 0x7f800000) >> 23;
+ s = bitand(a, 0x007fffff);
+
+ if(e != 0, s = bitor(s, 0x00800000),);
+ s = s * 2.0^(-23);
+ e = e - 127;
+ return((-1)^n * s * 2^(e));
+}
+
+{ flt64fromuint64(a) = my(n, e, s);
+ n = bitand(a, 0x8000000000000000) != 0;
+ e = bitand(a, 0x7ff0000000000000) >> 52;
+ s = bitand(a, 0x000fffffffffffff);
+
+ if(e != 0, s = bitor(s, 0x0010000000000000),);
+ s = s * 2.0^(-52);
+ e = e - 1023;
+ return((-1)^n * 2^(e) * s);
+}