aboutsummaryrefslogtreecommitdiff
path: root/src/base/math/nan.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/math/nan.c')
-rw-r--r--src/base/math/nan.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/base/math/nan.c b/src/base/math/nan.c
new file mode 100644
index 0000000..c1f85c2
--- /dev/null
+++ b/src/base/math/nan.c
@@ -0,0 +1,54 @@
+#include <u.h>
+#include <base.h>
+
+#define NANEXP (2047<<20)
+#define NANMASK (2047<<20)
+#define NANSIGN (1<<31)
+
+double
+math·NaN(void)
+{
+ sys·DoubleWord a;
+
+ a.hi = NANEXP;
+ a.lo = 1;
+ return a.x;
+}
+
+int
+math·isNaN(double d)
+{
+ sys·DoubleWord a;
+
+ a.x = d;
+ if((a.hi & NANMASK) != NANEXP)
+ return 0;
+ return !math·isInf(d, 0);
+}
+
+double
+math·Inf(int sign)
+{
+ sys·DoubleWord a;
+
+ a.hi = NANEXP;
+ a.lo = 0;
+ if(sign < 0)
+ a.hi |= NANSIGN;
+ return a.x;
+}
+
+int
+math·isInf(double d, int sign)
+{
+ sys·DoubleWord a;
+
+ a.x = d;
+ if(a.lo != 0)
+ return 0;
+ if(a.hi == NANEXP)
+ return sign >= 0;
+ if(a.hi == (NANEXP|NANSIGN))
+ return sign <= 0;
+ return 0;
+}