From: "Iruatã Souza" <iru.muzgo@gmail.com>
To: ori@eigenstate.org, 9front@9front.org
Subject: Re: [9front] [patch] add log2 to ape
Date: Mon, 7 Dec 2020 11:16:17 +0100 [thread overview]
Message-ID: <f7eb1d77-51f1-7aa2-a494-02e21eaf66f2@gmail.com> (raw)
In-Reply-To: <23D0CE12F0A6885C041A6F186B0B2920@eigenstate.org>
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;
+}
next prev parent reply other threads:[~2020-12-07 10:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-06 16:56 Iruatã Souza
2020-12-06 18:49 ` ori
2020-12-07 10:16 ` Iruatã Souza [this message]
2020-12-07 11:34 ` Iruatã Souza
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f7eb1d77-51f1-7aa2-a494-02e21eaf66f2@gmail.com \
--to=iru.muzgo@gmail.com \
--cc=9front@9front.org \
--cc=ori@eigenstate.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).