* [9front] [patch] add log2 to ape
@ 2020-12-06 16:56 Iruatã Souza
2020-12-06 18:49 ` ori
0 siblings, 1 reply; 4+ messages in thread
From: Iruatã Souza @ 2020-12-06 16:56 UTC (permalink / raw)
To: 9front
Hi,
This adds log2 to APE. It is defined in posix and at least Lua expects it.
diff -r 543ad076adbc sys/src/ape/lib/ap/math/log.c
--- a/sys/src/ape/lib/ap/math/log.c Sun Dec 06 15:08:23 2020 +0100
+++ b/sys/src/ape/lib/ap/math/log.c Sun Dec 06 17:45:18 2020 +0100
@@ -10,7 +10,7 @@
#include <math.h>
#include <errno.h>
-#define log2 0.693147180559945309e0
+#define _log2 0.693147180559945309e0
#define ln10o1 .4342944819032518276511
#define sqrto2 0.707106781186547524e0
#define p0 -.240139179559210510e2
@@ -46,7 +46,7 @@
temp = ((p3*zsq + p2)*zsq + p1)*zsq + p0;
temp = temp/(((zsq + q2)*zsq + q1)*zsq + q0);
- temp = temp*z + exp*log2;
+ temp = temp*z + exp*_log2;
return temp;
}
@@ -60,3 +60,9 @@
}
return log(arg) * ln10o1;
}
+
+double
+log2(double arg)
+{
+ return log(x)/_log2;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [9front] [patch] add log2 to ape
2020-12-06 16:56 [9front] [patch] add log2 to ape Iruatã Souza
@ 2020-12-06 18:49 ` ori
2020-12-07 10:16 ` Iruatã Souza
0 siblings, 1 reply; 4+ messages in thread
From: ori @ 2020-12-06 18:49 UTC (permalink / raw)
To: iru.muzgo, 9front
Quoth Iruatã Souza <iru.muzgo@gmail.com>:
> Hi,
>
> +
> +double
> +log2(double arg)
> +{
> + return log(x)/_log2;
> +}
>
In error cases, this divides the error return
by log2. I suspect we don't want to do that.
I'd also rather name all of the constants
consistently. Maybe uppercase the initial
character, instead of giving one of them
an _ prefix.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [9front] [patch] add log2 to ape
2020-12-06 18:49 ` ori
@ 2020-12-07 10:16 ` Iruatã Souza
2020-12-07 11:34 ` Iruatã Souza
0 siblings, 1 reply; 4+ messages in thread
From: Iruatã Souza @ 2020-12-07 10:16 UTC (permalink / raw)
To: ori, 9front
On 06/12/2020 19:49, ori@eigenstate.org wrote:
> In error cases, this divides the error return
> by log2. I suspect we don't want to do that.
>
> I'd also rather name all of the constants
> consistently. Maybe uppercase the initial
> character, instead of giving one of them
> an _ prefix.
The patch is simply wrong, it doesn't even compile correctly!
Sorry for the noise, here is a better one.
diff -r 3497ab777d56 amd64/include/ape/math.h
--- a/amd64/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/amd64/include/ape/math.h Mon Dec 07 11:11:22 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 sys/src/ape/lib/ap/math/log.c
--- a/sys/src/ape/lib/ap/math/log.c Mon Dec 07 00:36:41 2020 +0100
+++ b/sys/src/ape/lib/ap/math/log.c Mon Dec 07 11:11:22 2020 +0100
@@ -10,16 +10,16 @@
#include <math.h>
#include <errno.h>
-#define log2 0.693147180559945309e0
-#define ln10o1 .4342944819032518276511
-#define sqrto2 0.707106781186547524e0
-#define p0 -.240139179559210510e2
-#define p1 0.309572928215376501e2
-#define p2 -.963769093377840513e1
-#define p3 0.421087371217979714e0
-#define q0 -.120069589779605255e2
-#define q1 0.194809660700889731e2
-#define q2 -.891110902798312337e1
+#define Log2 0.693147180559945309e0
+#define Ln10o1 .4342944819032518276511
+#define Sqrto2 0.707106781186547524e0
+#define P0 -.240139179559210510e2
+#define P1 0.309572928215376501e2
+#define P2 -.963769093377840513e1
+#define P3 0.421087371217979714e0
+#define Q0 -.120069589779605255e2
+#define Q1 0.194809660700889731e2
+#define Q2 -.891110902798312337e1
double
log(double arg)
@@ -36,7 +36,7 @@
x *= 2;
exp--;
}
- if(x < sqrto2) {
+ if(x < Sqrto2) {
x *= 2;
exp--;
}
@@ -44,9 +44,9 @@
z = (x-1) / (x+1);
zsq = z*z;
- temp = ((p3*zsq + p2)*zsq + p1)*zsq + p0;
- temp = temp/(((zsq + q2)*zsq + q1)*zsq + q0);
- temp = temp*z + exp*log2;
+ temp = ((P3*zsq + P2)*zsq + P1)*zsq + P0;
+ temp = temp/(((zsq + Q2)*zsq + Q1)*zsq + Q0);
+ temp = temp*z + exp*Log2;
return temp;
}
@@ -58,5 +58,16 @@
errno = (arg==0)? ERANGE : EDOM;
return -HUGE_VAL;
}
- return log(arg) * ln10o1;
+ return log(arg) * Ln10o1;
}
+
+double
+log2(double arg)
+{
+ if(arg <= 0) {
+ errno = (arg==0)? ERANGE : EDOM;
+ return -HUGE_VAL;
+ }
+
+ return log(arg)/Log2;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [9front] [patch] add log2 to ape
2020-12-07 10:16 ` Iruatã Souza
@ 2020-12-07 11:34 ` Iruatã Souza
0 siblings, 0 replies; 4+ messages in thread
From: Iruatã Souza @ 2020-12-07 11:34 UTC (permalink / raw)
To: ori, 9front
On 07/12/2020 11:16, Iruatã Souza wrote:
> On 06/12/2020 19:49, ori@eigenstate.org wrote:
>> In error cases, this divides the error return
>> by log2. I suspect we don't want to do that.
>>
>> I'd also rather name all of the constants
>> consistently. Maybe uppercase the initial
>> character, instead of giving one of them
>> an _ prefix.
>
> The patch is simply wrong, it doesn't even compile correctly!
>
> Sorry for the noise, here is a better one.
>
Now changing ape/math.h for all architectures.
diff -r 3497ab777d56 386/include/ape/math.h
--- a/386/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/386/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 68020/include/ape/math.h
--- a/68020/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/68020/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 amd64/include/ape/math.h
--- a/amd64/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/amd64/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 arm/include/ape/math.h
--- a/arm/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/arm/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 arm64/include/ape/math.h
--- a/arm64/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/arm64/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 mips/include/ape/math.h
--- a/mips/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/mips/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 power/include/ape/math.h
--- a/power/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/power/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 sparc/include/ape/math.h
--- a/sparc/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/sparc/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 sparc64/include/ape/math.h
--- a/sparc64/include/ape/math.h Mon Dec 07 00:36:41 2020 +0100
+++ b/sparc64/include/ape/math.h Mon Dec 07 12:29:28 2020 +0100
@@ -26,6 +26,7 @@
extern double ldexp(double, int);
extern double log(double);
extern double log10(double);
+extern double log2(double);
extern double modf(double, double *);
extern double pow(double, double);
extern double sqrt(double);
diff -r 3497ab777d56 sys/src/ape/lib/ap/math/log.c
--- a/sys/src/ape/lib/ap/math/log.c Mon Dec 07 00:36:41 2020 +0100
+++ b/sys/src/ape/lib/ap/math/log.c Mon Dec 07 12:29:28 2020 +0100
@@ -10,16 +10,16 @@
#include <math.h>
#include <errno.h>
-#define log2 0.693147180559945309e0
-#define ln10o1 .4342944819032518276511
-#define sqrto2 0.707106781186547524e0
-#define p0 -.240139179559210510e2
-#define p1 0.309572928215376501e2
-#define p2 -.963769093377840513e1
-#define p3 0.421087371217979714e0
-#define q0 -.120069589779605255e2
-#define q1 0.194809660700889731e2
-#define q2 -.891110902798312337e1
+#define Log2 0.693147180559945309e0
+#define Ln10o1 .4342944819032518276511
+#define Sqrto2 0.707106781186547524e0
+#define P0 -.240139179559210510e2
+#define P1 0.309572928215376501e2
+#define P2 -.963769093377840513e1
+#define P3 0.421087371217979714e0
+#define Q0 -.120069589779605255e2
+#define Q1 0.194809660700889731e2
+#define Q2 -.891110902798312337e1
double
log(double arg)
@@ -36,7 +36,7 @@
x *= 2;
exp--;
}
- if(x < sqrto2) {
+ if(x < Sqrto2) {
x *= 2;
exp--;
}
@@ -44,9 +44,9 @@
z = (x-1) / (x+1);
zsq = z*z;
- temp = ((p3*zsq + p2)*zsq + p1)*zsq + p0;
- temp = temp/(((zsq + q2)*zsq + q1)*zsq + q0);
- temp = temp*z + exp*log2;
+ temp = ((P3*zsq + P2)*zsq + P1)*zsq + P0;
+ temp = temp/(((zsq + Q2)*zsq + Q1)*zsq + Q0);
+ temp = temp*z + exp*Log2;
return temp;
}
@@ -58,5 +58,16 @@
errno = (arg==0)? ERANGE : EDOM;
return -HUGE_VAL;
}
- return log(arg) * ln10o1;
+ return log(arg) * Ln10o1;
}
+
+double
+log2(double arg)
+{
+ if(arg <= 0) {
+ errno = (arg==0)? ERANGE : EDOM;
+ return -HUGE_VAL;
+ }
+
+ return log(arg)/Log2;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-12-07 11:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-06 16:56 [9front] [patch] add log2 to ape Iruatã Souza
2020-12-06 18:49 ` ori
2020-12-07 10:16 ` Iruatã Souza
2020-12-07 11:34 ` Iruatã Souza
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).