From bdc7f4b4e25f49b4e25578d98d58b113d0e961f1 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 15 Dec 2024 09:56:34 +0800 Subject: [PATCH] Don't redefine INFINITY nor NAN 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 Reviewed-by: Sam James --- math/math.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/math/math.h b/math/math.h index 599ca3ae79..5e085fdf9a 100644 --- a/math/math.h +++ b/math/math.h @@ -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 */