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