summaryrefslogtreecommitdiff
path: root/lib/math
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2018-06-28 10:37:51 -0400
committerS. Gilles <sgilles@math.umd.edu>2018-06-28 10:37:51 -0400
commitc57f69776103121107ad70d86a7b0efbc2553daa (patch)
treeb9504f850842c7479532579a0412d1f2a1416456 /lib/math
parentbc7b9cf7c49595c758d68c30ee1179740e269121 (diff)
downloadmc-c57f69776103121107ad70d86a7b0efbc2553daa.tar.gz
Add macros for relative error to lib/math/ancillary.
Diffstat (limited to 'lib/math')
-rw-r--r--lib/math/ancillary/ulp.gp27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/math/ancillary/ulp.gp b/lib/math/ancillary/ulp.gp
new file mode 100644
index 0000000..bf86208
--- /dev/null
+++ b/lib/math/ancillary/ulp.gp
@@ -0,0 +1,27 @@
+/*
+ I always end up need this for debugging
+ */
+
+{ ulp32(a) = my(aa, q);
+ aa = abs(a);
+ if(aa < 2^(-150),return(2^(-126 - 23)),);
+ q = floor(log(aa)/log(2));
+ if(q < -126,q=-126,);
+ return(2^(q-23));
+}
+
+{ ulp64(a) = my(aa, q);
+ aa = abs(a);
+ if(aa < 2^(-2000),return(2^(-1022 - 52)),);
+ q = floor(log(aa)/log(2));
+ if(q < -1022,q=-1022,);
+ return(2^(q-52));
+}
+
+{ err32(x, y) =
+ return(abs(x-y)/ulp32(x));
+}
+
+{ err64(x, y) =
+ return(abs(x-y)/ulp64(x));
+}