ref: 0cc431c860f35ea4a751f29c7a7ebdcfdf31df83
parent: f02dd042e341527ab750892bfc919b0883a93dd1
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Mar 17 07:42:35 EDT 2021
log2/log2f: use huge number according to the type
--- a/libnpe/_npe.h
+++ b/libnpe/_npe.h
@@ -2,6 +2,10 @@
Nsec = 1000000000ULL,
};
+#define ln2o1 1.4426950408889634073599
+#define hugeF 3.4028234e+38
+#define hugeD 1.79769313486231e+308
+
uvlong npe_nanosec(void);
void npe_nsleep(uvlong ns);
int npe_mkdirp(char *s, int perm);
--- a/libnpe/exp2.c
+++ b/libnpe/exp2.c
@@ -1,6 +1,5 @@
#include <math.h>
-
-#define ln2o1 1.4426950408889634073599
+#include "_npe.h"
double
exp2(double x)
--- a/libnpe/log2.c
+++ b/libnpe/log2.c
@@ -1,15 +1,22 @@
#include <math.h>
+#include "_npe.h"
-#define ln2o1 1.4426950408889634073599
-#define huge 1.79769313486231e+308
-
double
log2(double x)
{
if(x == 0)
- return -huge;
+ return -hugeD;
if(x < 0 || isNaN(x))
return NaN();
return log(x)*ln2o1;
+}
+
+float
+log2f(float x)
+{
+ if(x == 0)
+ return -hugeF;
+
+ return log2(x);
}