musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/include/math.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012年03月02日 22:35:37 -0500
committerRich Felker <dalias@aerifal.cx>2012年03月02日 22:35:37 -0500
commit405ce58dcf59ecfb3e245fed0b96b1f35fbeaec1 (patch)
tree439834dd49850e97dd9f3761add8d65bdab6f37d /include/math.h
parentb4a07bb469ad5a81ee003b621c362d2e7be38159 (diff)
downloadmusl-405ce58dcf59ecfb3e245fed0b96b1f35fbeaec1.tar.gz
fix nan/infinity macros in math.h, etc.
the previous version not only failed to work in c++, but also failed to produce constant expressions, making the macros useless as initializers for objects of static storage duration. gcc 3.3 and later have builtins for these, which sadly seem to be the most "portable" solution. the alternative definitions produce exceptions (for NAN) and compiler warnings (for INFINITY) on newer versions of gcc.
Diffstat (limited to 'include/math.h')
-rw-r--r--include/math.h 14
1 files changed, 8 insertions, 6 deletions
diff --git a/include/math.h b/include/math.h
index 4c46a055..ae84a731 100644
--- a/include/math.h
+++ b/include/math.h
@@ -12,17 +12,18 @@ extern "C" {
#define __NEED___uint64_t
#include <bits/alltypes.h>
-#define __MAKE_FLOAT(i) (((union { int __i; float __f; }){ .__i = i }).__f)
-
-#define NAN __MAKE_FLOAT(0x7fc00000)
-#define INFINITY __MAKE_FLOAT(0x7f800000)
+#if 100*__GNUC__+__GNUC_MINOR__ >= 303
+#define NAN __builtin_nanf("")
+#define INFINITY __builtin_inff()
+#else
+#define NAN (0.0f/0.0f)
+#define INFINITY 1e40f
+#endif
#define HUGE_VALF INFINITY
#define HUGE_VAL ((double)INFINITY)
#define HUGE_VALL ((long double)INFINITY)
-#define MAXFLOAT __MAKE_FLOAT(0x7f7fffff)
-
#define MATH_ERRNO 1
#define MATH_EXCEPT 2
#define math_errhandling 2
@@ -301,6 +302,7 @@ float truncf(float);
long double truncl(long double);
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#define MAXFLOAT 3.40282347e+38F
#define M_E 2.7182818284590452354 /* e */
#define M_LOG2E 1.4426950408889634074 /* log_2 e */
#define M_LOG10E 0.43429448190325182765 /* log_10 e */
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月02日 10:01:09 +0000

AltStyle によって変換されたページ (->オリジナル) /