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 * Copyright 2014 Garrett D'Amore <garrett@damore.org> 30 */ 31 32 #ifndef _MATH_H 33 #define _MATH_H 34 35 #include <iso/math_iso.h> 36 #include <iso/math_c99.h> 37 38 #if __cplusplus >= 199711L 39 using std::abs; 40 using std::acos; 41 using std::asin; 42 using std::atan2; 43 using std::atan; 44 using std::ceil; 45 using std::cos; 46 using std::cosh; 47 using std::exp; 48 using std::fabs; 49 using std::floor; 50 using std::fmod; 51 using std::frexp; 52 using std::ldexp; 53 using std::log10; 54 using std::log; 55 using std::modf; 56 using std::pow; 57 using std::sin; 58 using std::sinh; 59 using std::sqrt; 60 using std::tan; 61 using std::tanh; 62 #endif 63 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 #if defined(__cplusplus) 69 #define exception __math_exception 70 #endif 71 72 #if defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || \ 73 !defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE) 74 /* 75 * SVID & X/Open 76 */ 77 #define M_E 2.7182818284590452354 78 #define M_LOG2E 1.4426950408889634074 79 #define M_LOG10E 0.43429448190325182765 80 #define M_LN2 0.69314718055994530942 81 #define M_LN10 2.30258509299404568402 82 #define M_PI 3.14159265358979323846 83 #define M_PI_2 1.57079632679489661923 84 #define M_PI_4 0.78539816339744830962 85 #define M_1_PI 0.31830988618379067154 86 #define M_2_PI 0.63661977236758134308 87 #define M_2_SQRTPI 1.12837916709551257390 88 #define M_SQRT2 1.41421356237309504880 89 #define M_SQRT1_2 0.70710678118654752440 90 91 extern int signgam; 92 93 #define MAXFLOAT ((float)3.40282346638528860e+38) 94 95 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) 96 /* 97 * SVID 98 */ 99 enum version {libm_ieee = -1, c_issue_4, ansi_1, strict_ansi}; 100 101 #ifdef __STDC__ 102 extern const enum version _lib_version; 103 #else 104 extern enum version _lib_version; 105 #endif 106 107 struct exception { 108 int type; 109 char *name; 110 double arg1; 111 double arg2; 112 double retval; 113 }; 114 115 #define HUGE MAXFLOAT 116 117 #define _ABS(x) ((x) < 0 ? -(x) : (x)) 118 119 #define _REDUCE(TYPE, X, XN, C1, C2) { \ 120 double x1 = (double)(TYPE)X, x2 = X - x1; \ 121 X = x1 - (XN) * (C1); X += x2; X -= (XN) * (C2); } 122 123 #define DOMAIN 1 124 #define SING 2 125 #define OVERFLOW 3 126 #define UNDERFLOW 4 127 #define TLOSS 5 128 #define PLOSS 6 129 130 #define _POLY1(x, c) ((c)[0] * (x) + (c)[1]) 131 #define _POLY2(x, c) (_POLY1((x), (c)) * (x) + (c)[2]) 132 #define _POLY3(x, c) (_POLY2((x), (c)) * (x) + (c)[3]) 133 #define _POLY4(x, c) (_POLY3((x), (c)) * (x) + (c)[4]) 134 #define _POLY5(x, c) (_POLY4((x), (c)) * (x) + (c)[5]) 135 #define _POLY6(x, c) (_POLY5((x), (c)) * (x) + (c)[6]) 136 #define _POLY7(x, c) (_POLY6((x), (c)) * (x) + (c)[7]) 137 #define _POLY8(x, c) (_POLY7((x), (c)) * (x) + (c)[8]) 138 #define _POLY9(x, c) (_POLY8((x), (c)) * (x) + (c)[9]) 139 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */ 140 141 /* 142 * SVID & X/Open 143 */ 144 /* BEGIN adopted by C99 */ 145 extern double erf(double); 146 extern double erfc(double); 147 extern double hypot(double, double); 148 extern double lgamma(double); 149 150 #if defined(__MATHERR_ERRNO_DONTCARE) 151 #pragma does_not_read_global_data(erf, erfc, hypot) 152 #pragma does_not_write_global_data(erf, erfc, hypot) 153 #pragma no_side_effect(erf, erfc, hypot) 154 #endif 155 156 #if !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && !defined(__C99FEATURES__) 157 extern int isnan(double); 158 159 #pragma does_not_read_global_data(isnan) 160 #pragma does_not_write_global_data(isnan) 161 #pragma no_side_effect(isnan) 162 #endif 163 /* END adopted by C99 */ 164 165 #if defined(__EXTENSIONS__) || _XOPEN_SOURCE - 0 < 600 166 extern double gamma(double); /* deprecated; use lgamma */ 167 #endif 168 extern double j0(double); 169 extern double j1(double); 170 extern double jn(int, double); 171 extern double y0(double); 172 extern double y1(double); 173 extern double yn(int, double); 174 175 #if defined(__MATHERR_ERRNO_DONTCARE) 176 #pragma does_not_read_global_data(j0, j1, jn, y0, y1, yn) 177 #pragma does_not_write_global_data(j0, j1, jn, y0, y1, yn) 178 #pragma no_side_effect(j0, j1, jn, y0, y1, yn) 179 #endif 180 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || \ 181 _XOPEN_SOURCE - 0 >= 500 || \ 182 defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1 183 /* 184 * SVID & XPG 4.2/5 - removed from XPG7. 185 */ 186 #if !defined(_STRICT_SYMBOLS) || !defined(_XPG7) 187 extern double scalb(double, double); 188 #endif 189 190 #if defined(__MATHERR_ERRNO_DONTCARE) 191 #pragma does_not_read_global_data(scalb) 192 #pragma does_not_write_global_data(scalb) 193 #pragma no_side_effect(scalb) 194 #endif 195 196 /* BEGIN adopted by C99 */ 197 extern double acosh(double); 198 extern double asinh(double); 199 extern double atanh(double); 200 extern double cbrt(double); 201 extern double logb(double); 202 extern double nextafter(double, double); 203 extern double remainder(double, double); 204 205 /* 206 * XPG 4.2/5 207 */ 208 extern double expm1(double); 209 extern int ilogb(double); 210 extern double log1p(double); 211 extern double rint(double); 212 213 #if defined(__MATHERR_ERRNO_DONTCARE) 214 #pragma does_not_read_global_data(acosh, asinh, atanh, cbrt) 215 #pragma does_not_read_global_data(logb, nextafter, remainder) 216 #pragma does_not_read_global_data(expm1, ilogb, log1p, rint) 217 #pragma does_not_write_global_data(acosh, asinh, atanh, cbrt) 218 #pragma does_not_write_global_data(logb, nextafter, remainder) 219 #pragma does_not_write_global_data(expm1, ilogb, log1p, rint) 220 #pragma no_side_effect(acosh, asinh, atanh, cbrt) 221 #pragma no_side_effect(logb, nextafter, remainder) 222 #pragma no_side_effect(expm1, ilogb, log1p, rint) 223 #endif 224 /* END adopted by C99 */ 225 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || ... */ 226 227 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) 228 /* 229 * SVID 230 */ 231 extern int matherr(struct exception *); 232 233 /* 234 * IEEE Test Vector 235 */ 236 extern double significand(double); 237 238 #if defined(__MATHERR_ERRNO_DONTCARE) 239 #pragma does_not_read_global_data(significand) 240 #pragma does_not_write_global_data(significand) 241 #pragma no_side_effect(significand) 242 #endif 243 244 extern int signgamf; /* deprecated; use signgam */ 245 extern int signgaml; /* deprecated; use signgam */ 246 247 extern int isnanf(float); 248 extern int isnanl(long double); 249 extern float gammaf(float); /* deprecated; use lgammaf */ 250 extern float gammaf_r(float, int *); /* deprecated; use lgammaf_r */ 251 extern float j0f(float); 252 extern float j1f(float); 253 extern float jnf(int, float); 254 extern float lgammaf_r(float, int *); 255 extern float scalbf(float, float); 256 extern float significandf(float); 257 extern float y0f(float); 258 extern float y1f(float); 259 extern float ynf(int, float); 260 extern long double gammal(long double); /* deprecated; use lgammal */ 261 extern long double gammal_r(long double, int *); /* deprecated */ 262 extern long double j0l(long double); 263 extern long double j1l(long double); 264 extern long double jnl(int, long double); 265 extern long double lgammal_r(long double, int *); 266 extern long double scalbl(long double, long double); 267 extern long double significandl(long double); 268 extern long double y0l(long double); 269 extern long double y1l(long double); 270 extern long double ynl(int, long double); 271 272 #if defined(__MATHERR_ERRNO_DONTCARE) 273 #pragma does_not_read_global_data(isnanf, isnanl) 274 #pragma does_not_write_global_data(isnanf, isnanl) 275 #pragma no_side_effect(isnanf, isnanl) 276 #pragma does_not_read_global_data(gammaf_r, j0f, j1f, jnf, lgammaf_r, scalbf) 277 #pragma does_not_read_global_data(significandf, y0f, y1f, ynf) 278 #pragma does_not_write_global_data(j0f, j1f, jnf, scalbf) 279 #pragma does_not_write_global_data(significandf, y0f, y1f, ynf) 280 #pragma no_side_effect(j0f, j1f, jnf, scalbf) 281 #pragma no_side_effect(significandf, y0f, y1f, ynf) 282 #pragma does_not_read_global_data(gammal_r, j0l, j1l, jnl, lgammal_r, scalbl) 283 #pragma does_not_read_global_data(significandl, y0l, y1l, ynl) 284 #pragma does_not_write_global_data(j0l, j1l, jnl, scalbl) 285 #pragma does_not_write_global_data(significandl, y0l, y1l, ynl) 286 #pragma no_side_effect(j0l, j1l, jnl, scalbl) 287 #pragma no_side_effect(significandl, y0l, y1l, ynl) 288 #endif 289 290 /* 291 * for sin+cos->sincos transformation 292 */ 293 extern void sincos(double, double *, double *); 294 extern void sincosf(float, float *, float *); 295 extern void sincosl(long double, long double *, long double *); 296 297 #if defined(__MATHERR_ERRNO_DONTCARE) 298 #pragma does_not_read_global_data(sincos, sincosf, sincosl) 299 #endif 300 301 /* BEGIN adopted by C99 */ 302 /* 303 * Functions callable from C, intended to support IEEE arithmetic. 304 */ 305 extern double copysign(double, double); 306 extern double scalbn(double, int); 307 308 #if defined(__MATHERR_ERRNO_DONTCARE) 309 #pragma does_not_read_global_data(copysign, scalbn) 310 #pragma does_not_write_global_data(copysign, scalbn) 311 #pragma no_side_effect(copysign, scalbn) 312 #endif 313 /* END adopted by C99 */ 314 315 /* 316 * Reentrant version of gamma & lgamma; passes signgam back by reference 317 * as the second argument; user must allocate space for signgam. 318 */ 319 extern double gamma_r(double, int *); /* deprecated; use lgamma_r */ 320 extern double lgamma_r(double, int *); 321 322 #if defined(__MATHERR_ERRNO_DONTCARE) 323 #pragma does_not_read_global_data(gamma_r, lgamma_r) 324 #endif 325 326 /* BEGIN adopted by C99 */ 327 extern float modff(float, float *); 328 329 #if defined(__MATHERR_ERRNO_DONTCARE) 330 #pragma does_not_read_global_data(modff) 331 #endif 332 /* END adopted by C99 */ 333 334 #if defined(__EXTENSIONS__) || !defined(__cplusplus) 335 #include <floatingpoint.h> 336 #endif 337 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */ 338 #endif /* defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || ... */ 339 340 #if defined(__cplusplus) && defined(__GNUC__) 341 #undef exception 342 #endif 343 344 #ifdef __cplusplus 345 } 346 #endif 347 348 #endif /* _MATH_H */ 349