public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fixed inaccuracy of j0f (BZ #28185)
@ 2021-08-04  9:46 Paul Zimmermann
  2021-08-04 10:46 ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Zimmermann @ 2021-08-04  9:46 UTC (permalink / raw)
  To: libc-alpha

The largest errors over the full binary32 range are after this
patch (on x86_64):

RNDN: libm wrong by up to 9.00e+00 ulp(s) [9] for x=0x1.04c39cp+6
RNDZ: libm wrong by up to 9.00e+00 ulp(s) [9] for x=0x1.04c39cp+6
RNDU: libm wrong by up to 9.00e+00 ulp(s) [9] for x=0x1.04c39cp+6
RNDD: libm wrong by up to 8.98e+00 ulp(s) [9] for x=0x1.4b7066p+7

Some constants used in the code are also changed to "static const".
---
 sysdeps/ieee754/flt-32/e_j0f.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sysdeps/ieee754/flt-32/e_j0f.c b/sysdeps/ieee754/flt-32/e_j0f.c
index 462518c365..080395eab5 100644
--- a/sysdeps/ieee754/flt-32/e_j0f.c
+++ b/sysdeps/ieee754/flt-32/e_j0f.c
@@ -40,7 +40,7 @@ S04  =  1.1661400734e-09; /* 0x30a045e8 */
 static const float zero = 0.0;
 
 /* This is the nearest approximation of the first zero of j0.  */
-#define FIRST_ZERO_J0 0xf.26247p-28f
+#define FIRST_ZERO_J0 0x1.33d152p+1f
 
 #define SMALL_SIZE 64
 
@@ -212,7 +212,7 @@ j0f_asympt (float x)
   /* Now x - pi/4 - alpha0 = h + n*pi/2 mod (2*pi).  */
   float xr = (float) h;
   n = n & 3;
-  float cst = 0xc.c422ap-4; /* sqrt(2/pi) rounded to nearest  */
+  static const float cst = 0xc.c422ap-4f; /* sqrt(2/pi) rounded to nearest  */
   float t = cst / sqrtf (x) * (float) beta0;
   if (n == 0)
     return t * __cosf (xr);
@@ -286,7 +286,7 @@ __ieee754_j0f(float x)
                 /* The following threshold is optimal: for x=0x1.3b58dep+1
                    and rounding upwards, |cc|=0x1.579b26p-4 and z is 10 ulps
                    far from the correctly rounded value.  */
-                float threshold = 0x1.579b26p-4;
+                static const float threshold = 0x1.579b26p-4f;
                 if (fabsf (cc) > threshold)
                   return z;
                 else
@@ -493,7 +493,7 @@ y0f_asympt (float x)
   /* Now x - pi/4 - alpha0 = h + n*pi/2 mod (2*pi).  */
   float xr = (float) h;
   n = n & 3;
-  float cst = 0xc.c422ap-4; /* sqrt(2/pi) rounded to nearest  */
+  static const float cst = 0xc.c422ap-4; /* sqrt(2/pi) rounded to nearest  */
   float t = cst / sqrtf (x) * (float) beta0;
   if (n == 0)
     return t * __sinf (xr);
@@ -584,7 +584,7 @@ __ieee754_y0f(float x)
                 z = (invsqrtpi*ss)/sqrtf(x);
                 /* The following threshold is optimal (determined on
                    aarch64-linux-gnu).  */
-                float threshold = 0x1.be585ap-4;
+                static const float threshold = 0x1.be585ap-4;
                 if (fabsf (ss) > threshold)
                   return z;
                 else
-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-05  8:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04  9:46 [PATCH] Fixed inaccuracy of j0f (BZ #28185) Paul Zimmermann
2021-08-04 10:46 ` Florian Weimer
2021-08-04 11:22   ` Paul Zimmermann
2021-08-04 17:36     ` Joseph Myers
2021-08-05  8:44       ` Paul Zimmermann

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 read-only IMAP folder(s) and NNTP newsgroup(s).