OSDN Git Service

math: add double precision error handling functions
authorSzabolcs Nagy <nsz@port70.net>
Fri, 30 Nov 2018 21:15:23 +0000 (21:15 +0000)
committerRich Felker <dalias@aerifal.cx>
Wed, 17 Apr 2019 17:08:45 +0000 (13:08 -0400)
src/internal/libm.h
src/math/__math_divzero.c [new file with mode: 0644]
src/math/__math_invalid.c [new file with mode: 0644]
src/math/__math_oflow.c [new file with mode: 0644]
src/math/__math_uflow.c [new file with mode: 0644]
src/math/__math_xflow.c [new file with mode: 0644]

index a52a0b8..62da4bd 100644 (file)
@@ -222,5 +222,10 @@ hidden float __math_uflowf(uint32_t);
 hidden float __math_oflowf(uint32_t);
 hidden float __math_divzerof(uint32_t);
 hidden float __math_invalidf(float);
+hidden double __math_xflow(uint32_t, double);
+hidden double __math_uflow(uint32_t);
+hidden double __math_oflow(uint32_t);
+hidden double __math_divzero(uint32_t);
+hidden double __math_invalid(double);
 
 #endif
diff --git a/src/math/__math_divzero.c b/src/math/__math_divzero.c
new file mode 100644 (file)
index 0000000..59d2135
--- /dev/null
@@ -0,0 +1,6 @@
+#include "libm.h"
+
+double __math_divzero(uint32_t sign)
+{
+       return fp_barrier(sign ? -1.0 : 1.0) / 0.0;
+}
diff --git a/src/math/__math_invalid.c b/src/math/__math_invalid.c
new file mode 100644 (file)
index 0000000..1774049
--- /dev/null
@@ -0,0 +1,6 @@
+#include "libm.h"
+
+double __math_invalid(double x)
+{
+       return (x - x) / (x - x);
+}
diff --git a/src/math/__math_oflow.c b/src/math/__math_oflow.c
new file mode 100644 (file)
index 0000000..c85dbf9
--- /dev/null
@@ -0,0 +1,6 @@
+#include "libm.h"
+
+double __math_oflow(uint32_t sign)
+{
+       return __math_xflow(sign, 0x1p769);
+}
diff --git a/src/math/__math_uflow.c b/src/math/__math_uflow.c
new file mode 100644 (file)
index 0000000..b90594a
--- /dev/null
@@ -0,0 +1,6 @@
+#include "libm.h"
+
+double __math_uflow(uint32_t sign)
+{
+       return __math_xflow(sign, 0x1p-767);
+}
diff --git a/src/math/__math_xflow.c b/src/math/__math_xflow.c
new file mode 100644 (file)
index 0000000..744203c
--- /dev/null
@@ -0,0 +1,6 @@
+#include "libm.h"
+
+double __math_xflow(uint32_t sign, double y)
+{
+       return eval_as_double(fp_barrier(sign ? -y : y) * y);
+}