ref: fb2a06c91f60a948687939741aa884b17219f715
parent: 2fd5ae3c5599fdd067ed11f3a58fb03da587db28
author: S. Gilles <sgilles@math.umd.edu>
date: Wed May 1 11:51:51 EDT 2019
Add fltXXfromuintXX to ancillary math script.
--- 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);
+}