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(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && !defined(__C99FEATURES__) 151 extern int isnan(double); 152 #endif 153 /* END adopted by C99 */ 154 155 #if defined(__EXTENSIONS__) || _XOPEN_SOURCE - 0 < 600 156 extern double gamma(double); /* deprecated; use lgamma */ 157 #endif 158 extern double j0(double); 159 extern double j1(double); 160 extern double jn(int, double); 161 extern double y0(double); 162 extern double y1(double); 163 extern double yn(int, double); 164 165 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || \ 166 _XOPEN_SOURCE - 0 >= 500 || \ 167 defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1 168 /* 169 * SVID & XPG 4.2/5 - removed from XPG7. 170 */ 171 #if !defined(_STRICT_SYMBOLS) || !defined(_XPG7) 172 extern double scalb(double, double); 173 #endif 174 175 /* BEGIN adopted by C99 */ 176 extern double acosh(double); 177 extern double asinh(double); 178 extern double atanh(double); 179 extern double cbrt(double); 180 extern double logb(double); 181 extern double nextafter(double, double); 182 extern double remainder(double, double); 183 184 /* 185 * XPG 4.2/5 186 */ 187 extern double expm1(double); 188 extern int ilogb(double); 189 extern double log1p(double); 190 extern double rint(double); 191 192 /* END adopted by C99 */ 193 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || ... */ 194 195 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) 196 /* 197 * SVID 198 */ 199 extern int matherr(struct exception *); 200 201 /* 202 * IEEE Test Vector 203 */ 204 extern double significand(double); 205 206 extern int signgamf; /* deprecated; use signgam */ 207 extern int signgaml; /* deprecated; use signgam */ 208 209 extern int isnanf(float); 210 extern int isnanl(long double); 211 extern float gammaf(float); /* deprecated; use lgammaf */ 212 extern float gammaf_r(float, int *); /* deprecated; use lgammaf_r */ 213 extern float j0f(float); 214 extern float j1f(float); 215 extern float jnf(int, float); 216 extern float lgammaf_r(float, int *); 217 extern float scalbf(float, float); 218 extern float significandf(float); 219 extern float y0f(float); 220 extern float y1f(float); 221 extern float ynf(int, float); 222 extern long double gammal(long double); /* deprecated; use lgammal */ 223 extern long double gammal_r(long double, int *); /* deprecated */ 224 extern long double j0l(long double); 225 extern long double j1l(long double); 226 extern long double jnl(int, long double); 227 extern long double lgammal_r(long double, int *); 228 extern long double scalbl(long double, long double); 229 extern long double significandl(long double); 230 extern long double y0l(long double); 231 extern long double y1l(long double); 232 extern long double ynl(int, long double); 233 234 /* 235 * for sin+cos->sincos transformation 236 */ 237 extern void sincos(double, double *, double *); 238 extern void sincosf(float, float *, float *); 239 extern void sincosl(long double, long double *, long double *); 240 241 /* BEGIN adopted by C99 */ 242 /* 243 * Functions callable from C, intended to support IEEE arithmetic. 244 */ 245 extern double copysign(double, double); 246 extern double scalbn(double, int); 247 /* END adopted by C99 */ 248 249 /* 250 * Reentrant version of gamma & lgamma; passes signgam back by reference 251 * as the second argument; user must allocate space for signgam. 252 */ 253 extern double gamma_r(double, int *); /* deprecated; use lgamma_r */ 254 extern double lgamma_r(double, int *); 255 256 /* BEGIN adopted by C99 */ 257 extern float modff(float, float *); 258 /* END adopted by C99 */ 259 260 #if defined(__EXTENSIONS__) || !defined(__cplusplus) 261 #include <floatingpoint.h> 262 #endif 263 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */ 264 #endif /* defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || ... */ 265 266 #if defined(__cplusplus) && defined(__GNUC__) 267 #undef exception 268 #endif 269 270 #ifdef __cplusplus 271 } 272 #endif 273 274 #endif /* _MATH_H */ 275