shithub: npe

Download patch

ref: 686729f16636fe0310dcb4b3108a572b25c88106
parent: 4fa9b9a395c8ea38e83d84e0d483fe3a329958ea
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat May 6 19:15:24 EDT 2023

leave fpu flags alone; more precise/portable versions of log2/exp2

--- a/libnpe/_main.c
+++ b/libnpe/_main.c
@@ -15,8 +15,6 @@
 void
 threadmain(int argc, char *argv[])
 {
-	setfcr(getfcr() & ~(FPINVAL|FPOVFL));
-
 	exit = npe_threadexit;
 
 	argv0 = *argv; /* for sdl to set at least some kind of label */
--- a/libnpe/_npe.h
+++ b/libnpe/_npe.h
@@ -1,3 +1,2 @@
-#define ln2o1 1.4426950408889634073599
 #define hugeF 3.4028234e+38
 #define hugeD 1.79769313486231e+308
--- a/libnpe/exp2.c
+++ b/libnpe/exp2.c
@@ -4,5 +4,8 @@
 double
 exp2(double x)
 {
-	return exp(x/ln2o1);
+	static double ln2c = 0.0;
+	if(ln2c == 0.0)
+		ln2c = log(2.0);
+	return exp(x*ln2c);
 }
--- a/libnpe/log2.c
+++ b/libnpe/log2.c
@@ -4,12 +4,15 @@
 double
 log2(double x)
 {
+	static double ln2c = 0.0;
 	if(x == 0)
 		return -hugeD;
 	if(x < 0 || isNaN(x))
 		return NaN();
+	if(ln2c == 0.0)
+		ln2c = log(2.0);
 
-	return log(x)*ln2o1;
+	return log(x)/ln2c;
 }
 
 float
--- a/libnpe_sdl2/audio.c
+++ b/libnpe_sdl2/audio.c
@@ -201,7 +201,6 @@
 			dup(p[0], rec ? 1 : 0); close(p[0]);
 			close(p[1]);
 			//close(2);
-			setfcr(FPPDBL|FPRNR|FPINVAL|FPZDIV|FPOVFL);
 			if(execl("/bin/audio/pcmconv", "pcmconv", rec ? "-o" : "-i", spec, nil) != 0)
 				exits("%r");
 		}else if(a->pidconv < 0){