Print this page
11175 libm should use signbit() correctly
11188 c99 math macros should return strictly backward compatible values


  49 
  50 #if defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || defined(__C99FEATURES__)
  51 #if defined(__GNUC__)
  52 #undef  HUGE_VAL
  53 #define HUGE_VAL        (__builtin_huge_val())
  54 #undef  HUGE_VALF
  55 #define HUGE_VALF       (__builtin_huge_valf())
  56 #undef  HUGE_VALL
  57 #define HUGE_VALL       (__builtin_huge_vall())
  58 #undef  INFINITY
  59 #define INFINITY        (__builtin_inff())
  60 #undef  NAN
  61 #define NAN             (__builtin_nanf(""))
  62 
  63 /*
  64  * C99 7.12.3 classification macros
  65  */
  66 #undef  isnan
  67 #undef  isinf
  68 #if __GNUC__ >= 4
  69 #define isnan(x)        __builtin_isnan(x)
  70 #define isinf(x)        __builtin_isinf(x)
  71 #define fpclassify(x)   __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, \
  72     FP_SUBNORMAL, FP_ZERO, x)
  73 #define isfinite(x)     __builtin_isfinite(x)
  74 #define isnormal(x)     __builtin_isnormal(x)
  75 #define signbit(x)      (__builtin_signbit(x) > 0)


  76 #else  /* __GNUC__ >= 4 */
  77 #define isnan(x)        __extension__( \
  78                         { __typeof(x) __x_n = (x); \
  79                         __builtin_isunordered(__x_n, __x_n); })
  80 #define isinf(x)        __extension__( \
  81                         { __typeof(x) __x_i = (x); \
  82                         __x_i == (__typeof(__x_i)) INFINITY || \
  83                         __x_i == (__typeof(__x_i)) (-INFINITY); })
  84 #undef  isfinite
  85 #define isfinite(x)     __extension__( \
  86                         { __typeof(x) __x_f = (x); \
  87                         !isnan(__x_f) && !isinf(__x_f); })
  88 #undef  isnormal
  89 #define isnormal(x)     __extension__( \
  90                         { __typeof(x) __x_r = (x); isfinite(__x_r) && \
  91                         (sizeof (__x_r) == sizeof (float) ? \
  92                         __builtin_fabsf(__x_r) >= __FLT_MIN__ : \
  93                         sizeof (__x_r) == sizeof (double) ? \
  94                         __builtin_fabs(__x_r) >= __DBL_MIN__ : \
  95                         __builtin_fabsl(__x_r) >= __LDBL_MIN__); })




  49 
  50 #if defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || defined(__C99FEATURES__)
  51 #if defined(__GNUC__)
  52 #undef  HUGE_VAL
  53 #define HUGE_VAL        (__builtin_huge_val())
  54 #undef  HUGE_VALF
  55 #define HUGE_VALF       (__builtin_huge_valf())
  56 #undef  HUGE_VALL
  57 #define HUGE_VALL       (__builtin_huge_vall())
  58 #undef  INFINITY
  59 #define INFINITY        (__builtin_inff())
  60 #undef  NAN
  61 #define NAN             (__builtin_nanf(""))
  62 
  63 /*
  64  * C99 7.12.3 classification macros
  65  */
  66 #undef  isnan
  67 #undef  isinf
  68 #if __GNUC__ >= 4


  69 #define fpclassify(x)   __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, \
  70     FP_SUBNORMAL, FP_ZERO, x)
  71 #define isnan(x)        __builtin_isnan(x)
  72 #define isinf(x)        __builtin_isinf(x)
  73 #define isfinite(x)     (__builtin_isfinite(x) != 0)
  74 #define isnormal(x)     (__builtin_isnormal(x) != 0)
  75 #define signbit(x)      (__builtin_signbit(x) != 0)
  76 #else  /* __GNUC__ >= 4 */
  77 #define isnan(x)        __extension__( \
  78                         { __typeof(x) __x_n = (x); \
  79                         __builtin_isunordered(__x_n, __x_n); })
  80 #define isinf(x)        __extension__( \
  81                         { __typeof(x) __x_i = (x); \
  82                         __x_i == (__typeof(__x_i)) INFINITY || \
  83                         __x_i == (__typeof(__x_i)) (-INFINITY); })
  84 #undef  isfinite
  85 #define isfinite(x)     __extension__( \
  86                         { __typeof(x) __x_f = (x); \
  87                         !isnan(__x_f) && !isinf(__x_f); })
  88 #undef  isnormal
  89 #define isnormal(x)     __extension__( \
  90                         { __typeof(x) __x_r = (x); isfinite(__x_r) && \
  91                         (sizeof (__x_r) == sizeof (float) ? \
  92                         __builtin_fabsf(__x_r) >= __FLT_MIN__ : \
  93                         sizeof (__x_r) == sizeof (double) ? \
  94                         __builtin_fabs(__x_r) >= __DBL_MIN__ : \
  95                         __builtin_fabsl(__x_r) >= __LDBL_MIN__); })