public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] math: Properly cast X_TLOSS to float [BZ #28713]
@ 2021-12-23 14:46 H.J. Lu
  0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2021-12-23 14:46 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6e30181b4a3ab6c56da0378b65f4d60504982300

commit 6e30181b4a3ab6c56da0378b65f4d60504982300
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Dec 20 15:00:24 2021 -0800

    math: Properly cast X_TLOSS to float [BZ #28713]
    
    Add
    
     #define AS_FLOAT_CONSTANT_1(x) x##f
     #define AS_FLOAT_CONSTANT(x) AS_FLOAT_CONSTANT_1(x)
    
    to cast X_TLOSS to float at compile-time to fix:
    
    FAIL: math/test-float-j0
    FAIL: math/test-float-jn
    FAIL: math/test-float-y0
    FAIL: math/test-float-y1
    FAIL: math/test-float-yn
    FAIL: math/test-float32-j0
    FAIL: math/test-float32-jn
    FAIL: math/test-float32-y0
    FAIL: math/test-float32-y1
    FAIL: math/test-float32-yn
    
    when compiling with GCC 12.
    
    Reviewed-by: Paul Zimmermann <Paul.Zimmermann@inria.fr>

Diff:
---
 math/math-svid-compat.h | 2 ++
 math/w_j0f_compat.c     | 5 +++--
 math/w_j1f_compat.c     | 5 +++--
 math/w_jnf_compat.c     | 5 +++--
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/math/math-svid-compat.h b/math/math-svid-compat.h
index 5c18cb1b03..876cadde40 100644
--- a/math/math-svid-compat.h
+++ b/math/math-svid-compat.h
@@ -49,6 +49,8 @@ extern int matherr (struct exception *__exc);
 extern int __matherr (struct exception *__exc);
 
 #define X_TLOSS	1.41484755040568800000e+16
+#define AS_FLOAT_CONSTANT_1(x) x##f
+#define AS_FLOAT_CONSTANT(x) AS_FLOAT_CONSTANT_1(x)
 
 /* Types of exceptions in the `type' field.  */
 #define DOMAIN		1
diff --git a/math/w_j0f_compat.c b/math/w_j0f_compat.c
index d375f3bfb0..3257533596 100644
--- a/math/w_j0f_compat.c
+++ b/math/w_j0f_compat.c
@@ -27,7 +27,8 @@
 float
 __j0f (float x)
 {
-  if (__builtin_expect (isgreater (fabsf (x), (float) X_TLOSS), 0)
+  if (__builtin_expect (isgreater (fabsf (x),
+				   AS_FLOAT_CONSTANT (X_TLOSS)), 0)
       && _LIB_VERSION != _IEEE_ && _LIB_VERSION != _POSIX_)
     /* j0(|x|>X_TLOSS) */
     return __kernel_standard_f (x, x, 134);
@@ -42,7 +43,7 @@ float
 __y0f (float x)
 {
   if (__builtin_expect (islessequal (x, 0.0f)
-                        || isgreater (x, (float) X_TLOSS), 0)
+                        || isgreater (x, AS_FLOAT_CONSTANT (X_TLOSS)), 0)
       && _LIB_VERSION != _IEEE_)
     {
       if (x < 0.0f)
diff --git a/math/w_j1f_compat.c b/math/w_j1f_compat.c
index 81e56b771e..025ed3ab46 100644
--- a/math/w_j1f_compat.c
+++ b/math/w_j1f_compat.c
@@ -27,7 +27,8 @@
 float
 __j1f (float x)
 {
-  if (__builtin_expect (isgreater (fabsf (x), X_TLOSS), 0)
+  if (__builtin_expect (isgreater (fabsf (x),
+				   AS_FLOAT_CONSTANT (X_TLOSS)), 0)
       && _LIB_VERSION != _IEEE_ && _LIB_VERSION != _POSIX_)
     /* j1(|x|>X_TLOSS) */
     return __kernel_standard_f (x, x, 136);
@@ -42,7 +43,7 @@ float
 __y1f (float x)
 {
   if (__builtin_expect (islessequal (x, 0.0f)
-			|| isgreater (x, (float) X_TLOSS), 0)
+			|| isgreater (x, AS_FLOAT_CONSTANT (X_TLOSS)), 0)
       && _LIB_VERSION != _IEEE_)
     {
       if (x < 0.0f)
diff --git a/math/w_jnf_compat.c b/math/w_jnf_compat.c
index 296e631566..ee9e80c494 100644
--- a/math/w_jnf_compat.c
+++ b/math/w_jnf_compat.c
@@ -27,7 +27,8 @@
 float
 __jnf (int n, float x)
 {
-  if (__builtin_expect (isgreater (fabsf (x), (float) X_TLOSS), 0)
+  if (__builtin_expect (isgreater (fabsf (x),
+				   AS_FLOAT_CONSTANT (X_TLOSS)), 0)
       && _LIB_VERSION != _IEEE_ && _LIB_VERSION != _POSIX_)
     /* jn(n,|x|>X_TLOSS) */
     return __kernel_standard_f (n, x, 138);
@@ -42,7 +43,7 @@ float
 __ynf (int n, float x)
 {
   if (__builtin_expect (islessequal (x, 0.0f)
-			|| isgreater (x, (float) X_TLOSS), 0)
+			|| isgreater (x, AS_FLOAT_CONSTANT (X_TLOSS)), 0)
       && _LIB_VERSION != _IEEE_)
     {
       if (x < 0.0f)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-23 14:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-23 14:46 [glibc] math: Properly cast X_TLOSS to float [BZ #28713] H.J. Lu

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).