Print this page
10881 more C99 math macros should be compiler builtins


  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  23  */
  24 /*
  25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 #ifndef _ISO_MATH_C99_H
  30 #define _ISO_MATH_C99_H
  31 
  32 #include <sys/isa_defs.h>
  33 #include <sys/feature_tests.h>
  34 
  35 #ifdef __cplusplus
  36 extern "C" {
  37 #endif
  38 











  39 #if defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || defined(__C99FEATURES__)
  40 #if defined(__GNUC__)
  41 #undef  HUGE_VAL
  42 #define HUGE_VAL        (__builtin_huge_val())
  43 #undef  HUGE_VALF
  44 #define HUGE_VALF       (__builtin_huge_valf())
  45 #undef  HUGE_VALL
  46 #define HUGE_VALL       (__builtin_huge_vall())
  47 #undef  INFINITY
  48 #define INFINITY        (__builtin_inff())
  49 #undef  NAN
  50 #define NAN             (__builtin_nanf(""))
  51 
  52 /*
  53  * C99 7.12.3 classification macros
  54  */
  55 #undef  isnan
  56 #undef  isinf
  57 #if __GNUC__ >= 4
  58 #define isnan(x)        __builtin_isnan(x)
  59 #define isinf(x)        __builtin_isinf(x)
  60 #else





  61 #define isnan(x)        __extension__( \
  62                         { __typeof(x) __x_n = (x); \
  63                         __builtin_isunordered(__x_n, __x_n); })
  64 #define isinf(x)        __extension__( \
  65                         { __typeof(x) __x_i = (x); \
  66                         __x_i == (__typeof(__x_i)) INFINITY || \
  67                         __x_i == (__typeof(__x_i)) (-INFINITY); })
  68 #endif
  69 #undef  isfinite
  70 #define isfinite(x)     __extension__( \
  71                         { __typeof(x) __x_f = (x); \
  72                         !isnan(__x_f) && !isinf(__x_f); })
  73 #undef  isnormal
  74 #define isnormal(x)     __extension__( \
  75                         { __typeof(x) __x_r = (x); isfinite(__x_r) && \
  76                         (sizeof (__x_r) == sizeof (float) ? \
  77                         __builtin_fabsf(__x_r) >= __FLT_MIN__ : \
  78                         sizeof (__x_r) == sizeof (double) ? \
  79                         __builtin_fabs(__x_r) >= __DBL_MIN__ : \
  80                         __builtin_fabsl(__x_r) >= __LDBL_MIN__); })
  81 #undef  fpclassify
  82 #define fpclassify(x)   __extension__( \
  83                         { __typeof(x) __x_c = (x); \
  84                         isnan(__x_c) ? FP_NAN : \
  85                         isinf(__x_c) ? FP_INFINITE : \
  86                         isnormal(__x_c) ? FP_NORMAL : \
  87                         __x_c == (__typeof(__x_c)) 0 ? FP_ZERO : \
  88                         FP_SUBNORMAL; })
  89 #undef  signbit
  90 #if defined(_BIG_ENDIAN)
  91 #define signbit(x)      __extension__( \
  92                         { __typeof(x) __x_s = (x); \
  93                         (int)(*(unsigned *)&__x_s >> 31); })
  94 #elif defined(_LITTLE_ENDIAN)
  95 #define signbit(x)      __extension__( \
  96                         { __typeof(x) __x_s = (x); \
  97                         (sizeof (__x_s) == sizeof (float) ? \
  98                         (int)(*(unsigned *)&__x_s >> 31) : \
  99                         sizeof (__x_s) == sizeof (double) ? \
 100                         (int)(((unsigned *)&__x_s)[1] >> 31) : \
 101                         (int)(((unsigned short *)&__x_s)[4] >> 15)); })
 102 #endif

 103 
 104 /*
 105  * C99 7.12.14 comparison macros
 106  */
 107 #undef  isgreater
 108 #define isgreater(x, y)         __builtin_isgreater(x, y)
 109 #undef  isgreaterequal
 110 #define isgreaterequal(x, y)    __builtin_isgreaterequal(x, y)
 111 #undef  isless
 112 #define isless(x, y)            __builtin_isless(x, y)
 113 #undef  islessequal
 114 #define islessequal(x, y)       __builtin_islessequal(x, y)
 115 #undef  islessgreater
 116 #define islessgreater(x, y)     __builtin_islessgreater(x, y)
 117 #undef  isunordered
 118 #define isunordered(x, y)       __builtin_isunordered(x, y)
 119 #else   /* defined(__GNUC__) */
 120 #undef  HUGE_VAL
 121 #define HUGE_VAL        __builtin_huge_val
 122 #undef  HUGE_VALF


 164 
 165 #if defined(__EXTENSIONS__) || defined(_STDC_C99) || \
 166         (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
 167         defined(__C99FEATURES__)
 168 #if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ - 0 == 0
 169 typedef float float_t;
 170 typedef double double_t;
 171 #elif __FLT_EVAL_METHOD__ - 0 == 1
 172 typedef double float_t;
 173 typedef double double_t;
 174 #elif __FLT_EVAL_METHOD__ - 0 == 2
 175 typedef long double float_t;
 176 typedef long double double_t;
 177 #elif defined(__sparc) || defined(__amd64)
 178 typedef float float_t;
 179 typedef double double_t;
 180 #elif defined(__i386)
 181 typedef long double float_t;
 182 typedef long double double_t;
 183 #endif
 184 
 185 #undef  FP_ZERO
 186 #define FP_ZERO         0
 187 #undef  FP_SUBNORMAL
 188 #define FP_SUBNORMAL    1
 189 #undef  FP_NORMAL
 190 #define FP_NORMAL       2
 191 #undef  FP_INFINITE
 192 #define FP_INFINITE     3
 193 #undef  FP_NAN
 194 #define FP_NAN          4
 195 
 196 #undef  FP_ILOGB0
 197 #define FP_ILOGB0       (-2147483647)
 198 #undef  FP_ILOGBNAN
 199 #define FP_ILOGBNAN     2147483647
 200 
 201 #undef  MATH_ERRNO
 202 #define MATH_ERRNO      1
 203 #undef  MATH_ERREXCEPT
 204 #define MATH_ERREXCEPT  2
 205 #undef  math_errhandling
 206 #define math_errhandling        MATH_ERREXCEPT
 207 
 208 extern double acosh(double);
 209 extern double asinh(double);
 210 extern double atanh(double);
 211 
 212 extern double exp2(double);
 213 extern double expm1(double);
 214 extern int ilogb(double);




  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  23  */
  24 /*
  25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 #ifndef _ISO_MATH_C99_H
  30 #define _ISO_MATH_C99_H
  31 
  32 #include <sys/isa_defs.h>
  33 #include <sys/feature_tests.h>
  34 
  35 #ifdef __cplusplus
  36 extern "C" {
  37 #endif
  38 
  39 #undef  FP_ZERO
  40 #define FP_ZERO         0
  41 #undef  FP_SUBNORMAL
  42 #define FP_SUBNORMAL    1
  43 #undef  FP_NORMAL
  44 #define FP_NORMAL       2
  45 #undef  FP_INFINITE
  46 #define FP_INFINITE     3
  47 #undef  FP_NAN
  48 #define FP_NAN          4
  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)
  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__); })
  96 #undef  fpclassify
  97 #define fpclassify(x)   __extension__( \
  98                         { __typeof(x) __x_c = (x); \
  99                         isnan(__x_c) ? FP_NAN : \
 100                         isinf(__x_c) ? FP_INFINITE : \
 101                         isnormal(__x_c) ? FP_NORMAL : \
 102                         __x_c == (__typeof(__x_c)) 0 ? FP_ZERO : \
 103                         FP_SUBNORMAL; })
 104 #undef  signbit
 105 #if defined(_BIG_ENDIAN)
 106 #define signbit(x)      __extension__( \
 107                         { __typeof(x) __x_s = (x); \
 108                         (int)(*(unsigned *)&__x_s >> 31); })
 109 #elif defined(_LITTLE_ENDIAN)
 110 #define signbit(x)      __extension__( \
 111                         { __typeof(x) __x_s = (x); \
 112                         (sizeof (__x_s) == sizeof (float) ? \
 113                         (int)(*(unsigned *)&__x_s >> 31) : \
 114                         sizeof (__x_s) == sizeof (double) ? \
 115                         (int)(((unsigned *)&__x_s)[1] >> 31) : \
 116                         (int)(((unsigned short *)&__x_s)[4] >> 15)); })
 117 #endif  /* defined(_BIG_ENDIAN) */
 118 #endif  /* __GNUC__ >= 4 */
 119 
 120 /*
 121  * C99 7.12.14 comparison macros
 122  */
 123 #undef  isgreater
 124 #define isgreater(x, y)         __builtin_isgreater(x, y)
 125 #undef  isgreaterequal
 126 #define isgreaterequal(x, y)    __builtin_isgreaterequal(x, y)
 127 #undef  isless
 128 #define isless(x, y)            __builtin_isless(x, y)
 129 #undef  islessequal
 130 #define islessequal(x, y)       __builtin_islessequal(x, y)
 131 #undef  islessgreater
 132 #define islessgreater(x, y)     __builtin_islessgreater(x, y)
 133 #undef  isunordered
 134 #define isunordered(x, y)       __builtin_isunordered(x, y)
 135 #else   /* defined(__GNUC__) */
 136 #undef  HUGE_VAL
 137 #define HUGE_VAL        __builtin_huge_val
 138 #undef  HUGE_VALF


 180 
 181 #if defined(__EXTENSIONS__) || defined(_STDC_C99) || \
 182         (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
 183         defined(__C99FEATURES__)
 184 #if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ - 0 == 0
 185 typedef float float_t;
 186 typedef double double_t;
 187 #elif __FLT_EVAL_METHOD__ - 0 == 1
 188 typedef double float_t;
 189 typedef double double_t;
 190 #elif __FLT_EVAL_METHOD__ - 0 == 2
 191 typedef long double float_t;
 192 typedef long double double_t;
 193 #elif defined(__sparc) || defined(__amd64)
 194 typedef float float_t;
 195 typedef double double_t;
 196 #elif defined(__i386)
 197 typedef long double float_t;
 198 typedef long double double_t;
 199 #endif











 200 
 201 #undef  FP_ILOGB0
 202 #define FP_ILOGB0       (-2147483647)
 203 #undef  FP_ILOGBNAN
 204 #define FP_ILOGBNAN     2147483647
 205 
 206 #undef  MATH_ERRNO
 207 #define MATH_ERRNO      1
 208 #undef  MATH_ERREXCEPT
 209 #define MATH_ERREXCEPT  2
 210 #undef  math_errhandling
 211 #define math_errhandling        MATH_ERREXCEPT
 212 
 213 extern double acosh(double);
 214 extern double asinh(double);
 215 extern double atanh(double);
 216 
 217 extern double exp2(double);
 218 extern double expm1(double);
 219 extern int ilogb(double);