shithub: sl

Download patch

ref: f5817e38d5aee775a8548c9be4e804b910a8090b
parent: d08addceab3e0ed3a48d54ce3ea14f8703e6eeb2
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Jan 21 20:37:46 EST 2025

turn +nan.0 and +inf.0 into constants

--- a/meson.build
+++ b/meson.build
@@ -65,7 +65,7 @@
 endif
 
 src_common = [
-	'nan.c',
+	'nan_posix.c',
 ]
 
 inc = [include_directories('3rd', '3rd/mp', '3rd/utf', '3rd/brieflz')]
--- a/mkfile
+++ b/mkfile
@@ -36,7 +36,7 @@
 	htable.$O\
 	ios.$O\
 	iostream.$O\
-	nan.$O\
+	nan_plan9.$O\
 	opcodes.$O\
 	operators.$O\
 	print.$O\
--- a/nan.c
+++ /dev/null
@@ -1,18 +1,0 @@
-#include "platform.h"
-#include "nan.h"
-#include "ieee754.h"
-
-double D_PNAN, D_NNAN, D_PINF, D_NINF;
-
-void
-nan_init(void)
-{
-	D_PNAN = D_NNAN = strtod("+NaN", nil);
-	D_PINF = D_NINF = strtod("+Inf", nil);
-
-	union ieee754_double *d;
-	d = (union ieee754_double *)&D_NNAN;
-	d->ieee.negative = 1;
-	d = (union ieee754_double *)&D_NINF;
-	d->ieee.negative = 1;
-}
--- a/nan.h
+++ b/nan.h
@@ -1,3 +1,11 @@
-extern double D_PNAN, D_NNAN, D_PINF, D_NINF;
+#pragma once
+
+#if defined(__plan9__)
+extern double D_PNAN, D_PINF;
+#else
+#define D_PNAN __builtin_nan("")
+#define D_PINF __builtin_inf()
+#endif
+extern double D_NNAN, D_NINF;
 
 void nan_init(void);
--- /dev/null
+++ b/nan_plan9.c
@@ -1,0 +1,18 @@
+#include "platform.h"
+#include "nan.h"
+#include "ieee754.h"
+
+double D_PNAN, D_NNAN, D_PINF, D_NINF;
+
+void
+nan_init(void)
+{
+	D_PNAN = D_NNAN = strtod("+NaN", nil);
+	D_PINF = D_NINF = strtod("+Inf", nil);
+
+	union ieee754_double *d;
+	d = (union ieee754_double *)&D_NNAN;
+	d->ieee.negative = 1;
+	d = (union ieee754_double *)&D_NINF;
+	d->ieee.negative = 1;
+}
--- /dev/null
+++ b/nan_posix.c
@@ -1,0 +1,15 @@
+#include "platform.h"
+#include "nan.h"
+#include "ieee754.h"
+
+double D_NNAN = D_PNAN, D_NINF = D_PINF;
+
+void
+nan_init(void)
+{
+	union ieee754_double *d;
+	d = (union ieee754_double *)&D_NNAN;
+	d->ieee.negative = 1;
+	d = (union ieee754_double *)&D_NINF;
+	d->ieee.negative = 1;
+}