1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 23 */ 24 /* 25 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 #ifndef _ISO_MATH_ISO_H 30 #define _ISO_MATH_ISO_H 31 32 #include <sys/feature_tests.h> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 #if !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && !defined(__C99FEATURES__) 39 typedef union _h_val { 40 unsigned long _i[sizeof (double) / sizeof (unsigned long)]; 41 double _d; 42 } _h_val; 43 44 #ifdef __STDC__ 45 extern const _h_val __huge_val; 46 #else 47 extern _h_val __huge_val; 48 #endif 49 #undef HUGE_VAL 50 #define HUGE_VAL __huge_val._d 51 #endif /* !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && ... */ 52 53 /* 54 * Declarations for C (and C++ global namespace) 55 */ 56 57 extern double acos(double); 58 extern double asin(double); 59 extern double atan(double); 60 extern double atan2(double, double); 61 extern double cos(double); 62 extern double sin(double); 63 extern double tan(double); 64 65 extern double cosh(double); 66 extern double sinh(double); 67 extern double tanh(double); 68 69 extern double exp(double); 70 extern double frexp(double, int *); 71 extern double ldexp(double, int); 72 extern double log(double); 73 extern double log10(double); 74 extern double modf(double, double *); 75 76 extern double pow(double, double); 77 extern double sqrt(double); 78 79 extern double ceil(double); 80 extern double fabs(double); 81 extern double floor(double); 82 extern double fmod(double, double); 83 84 /* 85 * ISO C++98 and later require float and long double overloads of 86 * all C90 math functions. The declarations are in the global 87 * namespace. The namespace std gets them via "using ::" aliases 88 * and the float and long double overloads as inlines. 89 * 90 * This global-primary layout ensures that when GCC's <cmath> does 91 * "using ::log" to populate namespace std, only the double form 92 * reaches ::. GCC then appends its integer-covering template to 93 * namespace std, making log(int) unambiguous. 94 */ 95 96 #if __cplusplus >= 199711L 97 98 /* 99 * float variants of above 100 */ 101 extern float acosf(float); 102 extern float asinf(float); 103 extern float atanf(float); 104 extern float atan2f(float, float); 105 extern float ceilf(float); 106 extern float cosf(float); 107 extern float coshf(float); 108 extern float expf(float); 109 extern float fabsf(float); 110 extern float floorf(float); 111 extern float fmodf(float, float); 112 extern float frexpf(float, int *); 113 extern float ldexpf(float, int); 114 extern float logf(float); 115 extern float log10f(float); 116 extern float modff(float, float *); 117 extern float powf(float, float); 118 extern float sinf(float); 119 extern float sinhf(float); 120 extern float sqrtf(float); 121 extern float tanf(float); 122 extern float tanhf(float); 123 124 /* 125 * long double variants of above 126 */ 127 extern long double acosl(long double); 128 extern long double asinl(long double); 129 extern long double atanl(long double); 130 extern long double atan2l(long double, long double); 131 extern long double ceill(long double); 132 extern long double cosl(long double); 133 extern long double coshl(long double); 134 extern long double expl(long double); 135 extern long double fabsl(long double); 136 extern long double floorl(long double); 137 extern long double fmodl(long double, long double); 138 extern long double frexpl(long double, int *); 139 extern long double ldexpl(long double, int); 140 extern long double logl(long double); 141 extern long double log10l(long double); 142 extern long double modfl(long double, long double *); 143 extern long double powl(long double, long double); 144 extern long double sinl(long double); 145 extern long double sinhl(long double); 146 extern long double sqrtl(long double); 147 extern long double tanl(long double); 148 extern long double tanhl(long double); 149 150 #endif /* __cplusplus >= 199711L */ 151 152 #ifdef __cplusplus 153 } 154 #endif 155 156 #if __cplusplus >= 199711L 157 extern "C++" { 158 namespace std { 159 160 /* 161 * Each using declaration brings the double (C-standard) form 162 * into std::. The float and long double overloads are defined 163 * as inlines below. 164 */ 165 using ::acos; 166 using ::asin; 167 using ::atan2; 168 using ::atan; 169 using ::ceil; 170 using ::cos; 171 using ::cosh; 172 using ::exp; 173 using ::fabs; 174 using ::floor; 175 using ::fmod; 176 using ::frexp; 177 using ::ldexp; 178 using ::log10; 179 using ::log; 180 using ::modf; 181 using ::pow; 182 using ::sin; 183 using ::sinh; 184 using ::sqrt; 185 using ::tan; 186 using ::tanh; 187 188 /* 189 * C++98 requires overloads of C90 math functions for float and 190 * long double arguments. These inlines satisfy that requirement 191 * by delegating to the corresponding C99 named variants. 192 */ 193 #undef __X 194 #undef __Y 195 196 /* inline double pow(double, int) not needed */ 197 198 inline float acos(float __X) { return acosf(__X); } 199 inline float asin(float __X) { return asinf(__X); } 200 inline float atan(float __X) { return atanf(__X); } 201 inline float atan2(float __X, float __Y) { return atan2f(__X, __Y); } 202 inline float ceil(float __X) { return ceilf(__X); } 203 inline float cos(float __X) { return cosf(__X); } 204 inline float cosh(float __X) { return coshf(__X); } 205 inline float exp(float __X) { return expf(__X); } 206 inline float fabs(float __X) { return fabsf(__X); } 207 inline float floor(float __X) { return floorf(__X); } 208 inline float fmod(float __X, float __Y) { return fmodf(__X, __Y); } 209 inline float frexp(float __X, int *__Y) { return frexpf(__X, __Y); } 210 inline float ldexp(float __X, int __Y) { return ldexpf(__X, __Y); } 211 inline float log(float __X) { return logf(__X); } 212 inline float log10(float __X) { return log10f(__X); } 213 inline float modf(float __X, float *__Y) { return modff(__X, __Y); } 214 inline float pow(float __X, float __Y) { return powf(__X, __Y); } 215 inline float sin(float __X) { return sinf(__X); } 216 inline float sinh(float __X) { return sinhf(__X); } 217 inline float sqrt(float __X) { return sqrtf(__X); } 218 inline float tan(float __X) { return tanf(__X); } 219 inline float tanh(float __X) { return tanhf(__X); } 220 221 inline long double acos(long double __X) { return acosl(__X); } 222 inline long double asin(long double __X) { return asinl(__X); } 223 inline long double atan(long double __X) { return atanl(__X); } 224 225 inline long double atan2(long double __X, long double __Y) { 226 return (atan2l(__X, __Y)); 227 } 228 229 inline long double ceil(long double __X) { return ceill(__X); } 230 inline long double cos(long double __X) { return cosl(__X); } 231 inline long double cosh(long double __X) { return coshl(__X); } 232 inline long double exp(long double __X) { return expl(__X); } 233 inline long double fabs(long double __X) { return fabsl(__X); } 234 inline long double floor(long double __X) { return floorl(__X); } 235 236 inline long double fmod(long double __X, long double __Y) { 237 return (fmodl(__X, __Y)); 238 } 239 240 inline long double frexp(long double __X, int *__Y) { 241 return (frexpl(__X, __Y)); 242 } 243 244 inline long double ldexp(long double __X, int __Y) { 245 return (ldexpl(__X, __Y)); 246 } 247 248 inline long double log(long double __X) { return logl(__X); } 249 inline long double log10(long double __X) { return log10l(__X); } 250 251 inline long double modf(long double __X, long double *__Y) { 252 return (modfl(__X, __Y)); 253 } 254 255 inline long double pow(long double __X, long double __Y) { 256 return (powl(__X, __Y)); 257 } 258 259 inline long double sin(long double __X) { return sinl(__X); } 260 inline long double sinh(long double __X) { return sinhl(__X); } 261 inline long double sqrt(long double __X) { return sqrtl(__X); } 262 inline long double tan(long double __X) { return tanl(__X); } 263 inline long double tanh(long double __X) { return tanhl(__X); } 264 265 /* 266 * For compatibility with GCC and GLIBCXX, let either stdlib.h or math.h 267 * provide both the integer and floating point abs() variants, regardless 268 * which is included first. 269 */ 270 #ifndef _CXX_ABS_FLOAT_DEFINED 271 #define _CXX_ABS_FLOAT_DEFINED 272 inline double abs(double __X) { return fabs(__X); } 273 inline float abs(float __X) { return fabsf(__X); } 274 inline long double abs(long double __X) { return fabsl(__X); } 275 #endif /* !_CXX_ABS_FLOAT_DEFINED */ 276 277 } /* namespace std */ 278 279 } /* extern "C++" */ 280 #endif /* __cplusplus >= 199711L */ 281 282 #endif /* _ISO_MATH_ISO_H */ 283