]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Don't redefine INFINITY nor NAN
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 15 Dec 2024 01:56:34 +0000 (09:56 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 22 Dec 2024 04:44:42 +0000 (12:44 +0800)
Since math/math.h isn't a system header, clang issues errors:

In file included from test-flt-eval-method.c:20:
In file included from ../include/math.h:7:
../math/math.h:91:11: error: 'INFINITY' macro redefined [-Werror,-Wmacro-redefined]
   91 | #  define INFINITY (__builtin_inff ())
      |           ^
/usr/bin/../lib/clang/19/include/float.h:173:11: note: previous definition is here
  173 | #  define INFINITY (__builtin_inff())
      |           ^
In file included from test-flt-eval-method.c:20:
In file included from ../include/math.h:7:
../math/math.h:98:11: error: 'NAN' macro redefined [-Werror,-Wmacro-redefined]
   98 | #  define NAN (__builtin_nanf (""))
      |           ^
/usr/bin/../lib/clang/19/include/float.h:174:11: note: previous definition is here
  174 | #  define NAN (__builtin_nanf(""))

Don't define INFINITY nor NAN if they are defined.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
math/math.h

index 599ca3ae79a63b995807a59a39ee44fbeeb35179..5e085fdf9aab8cdad8286191e575178e48e7a886 100644 (file)
@@ -87,20 +87,24 @@ __BEGIN_DECLS
 
 #ifdef __USE_ISOC99
 /* IEEE positive infinity.  */
-# if __GNUC_PREREQ (3, 3)
-#  define INFINITY (__builtin_inff ())
-# else
-#  define INFINITY HUGE_VALF
+# ifndef INFINITY
+#  if __GNUC_PREREQ (3, 3)
+#   define INFINITY (__builtin_inff ())
+#  else
+#   define INFINITY HUGE_VALF
+#  endif
 # endif
 
 /* IEEE Not A Number.  */
-# if __GNUC_PREREQ (3, 3)
-#  define NAN (__builtin_nanf (""))
-# else
+# ifndef NAN
+#  if __GNUC_PREREQ (3, 3)
+#   define NAN (__builtin_nanf (""))
+#  else
 /* This will raise an "invalid" exception outside static initializers,
    but is the best that can be done in ISO C while remaining a
    constant expression.  */
-#  define NAN (0.0f / 0.0f)
+#   define NAN (0.0f / 0.0f)
+#  endif
 # endif
 #endif /* __USE_ISOC99 */