Home | History | Annotate | Download | only in current
      1 /*
      2  * ====================================================
      3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
      4  *
      5  * Developed at SunPro, a Sun Microsystems, Inc. business.
      6  * Permission to use, copy, modify, and distribute this
      7  * software is freely granted, provided that this notice
      8  * is preserved.
      9  * ====================================================
     10  */
     11 
     12 /*
     13  * from: @(#)fdlibm.h 5.1 93/09/24
     14  * $FreeBSD$
     15  */
     16 
     17 #ifndef _MATH_H_
     18 #define _MATH_H_
     19 
     20 #include <sys/cdefs.h>
     21 #include <limits.h>
     22 
     23 __BEGIN_DECLS
     24 
     25 #define HUGE_VAL	__builtin_huge_val()
     26 
     27 #define FP_ILOGB0	(-INT_MAX)
     28 #define FP_ILOGBNAN	INT_MAX
     29 
     30 #define HUGE_VALF	__builtin_huge_valf()
     31 #define HUGE_VALL	__builtin_huge_vall()
     32 #define INFINITY	__builtin_inff()
     33 #define NAN		__builtin_nanf("")
     34 
     35 #define MATH_ERRNO	1
     36 #define MATH_ERREXCEPT	2
     37 #define math_errhandling	MATH_ERREXCEPT
     38 
     39 #if defined(__FP_FAST_FMA)
     40 #define FP_FAST_FMA 1
     41 #endif
     42 #if defined(__FP_FAST_FMAF)
     43 #define FP_FAST_FMAF 1
     44 #endif
     45 #if defined(__FP_FAST_FMAL)
     46 #define FP_FAST_FMAL 1
     47 #endif
     48 
     49 /* Symbolic constants to classify floating point numbers. */
     50 #define FP_INFINITE	0x01
     51 #define FP_NAN		0x02
     52 #define FP_NORMAL	0x04
     53 #define FP_SUBNORMAL	0x08
     54 #define FP_ZERO		0x10
     55 #define fpclassify(x) \
     56     __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
     57 
     58 #define isfinite(x) __builtin_isfinite(x)
     59 #define isinf(x) __builtin_isinf(x)
     60 #define isnan(x) __builtin_isnan(x)
     61 #define isnormal(x) __builtin_isnormal(x)
     62 
     63 #define isgreater(x, y) __builtin_isgreater((x), (y))
     64 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
     65 #define isless(x, y) __builtin_isless((x), (y))
     66 #define islessequal(x, y) __builtin_islessequal((x), (y))
     67 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
     68 #define isunordered(x, y) __builtin_isunordered((x), (y))
     69 
     70 #define signbit(x) \
     71     ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
     72     : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
     73     : __builtin_signbitl(x))
     74 
     75 typedef double __double_t;
     76 typedef __double_t double_t;
     77 typedef float __float_t;
     78 typedef __float_t float_t;
     79 
     80 #if defined(__USE_BSD)
     81 #define HUGE MAXFLOAT
     82 #endif
     83 
     84 extern int signgam;
     85 
     86 /*
     87  * Most of these functions depend on the rounding mode and have the side
     88  * effect of raising floating-point exceptions, so they are not declared
     89  * as __attribute_const__. In C99, FENV_ACCESS affects the purity of these functions.
     90  */
     91 
     92 int __fpclassifyd(double) __attribute_const__;
     93 int __fpclassifyf(float) __attribute_const__;
     94 int __fpclassifyl(long double) __attribute_const__;
     95 int __isfinitef(float) __attribute_const__;
     96 int __isfinite(double) __attribute_const__;
     97 int __isfinitel(long double) __attribute_const__;
     98 int __isinff(float) __attribute_const__;
     99 int __isinfl(long double) __attribute_const__;
    100 int __isnanf(float) __attribute_const__ __INTRODUCED_IN(21);
    101 int __isnanl(long double) __attribute_const__;
    102 int __isnormalf(float) __attribute_const__;
    103 int __isnormal(double) __attribute_const__;
    104 int __isnormall(long double) __attribute_const__;
    105 int __signbit(double) __attribute_const__;
    106 int __signbitf(float) __attribute_const__;
    107 int __signbitl(long double) __attribute_const__;
    108 
    109 double	acos(double);
    110 double	asin(double);
    111 double	atan(double);
    112 double	atan2(double, double);
    113 double	cos(double);
    114 double	sin(double);
    115 double	tan(double);
    116 
    117 double	cosh(double);
    118 double	sinh(double);
    119 double	tanh(double);
    120 
    121 double	exp(double);
    122 double	frexp(double, int *);	/* fundamentally !__attribute_const__ */
    123 double	ldexp(double, int);
    124 double	log(double);
    125 double	log10(double);
    126 double	modf(double, double *);	/* fundamentally !__attribute_const__ */
    127 
    128 double	pow(double, double);
    129 double	sqrt(double);
    130 
    131 double	ceil(double);
    132 double	fabs(double) __attribute_const__;
    133 double	floor(double);
    134 double	fmod(double, double);
    135 
    136 double	acosh(double);
    137 double	asinh(double);
    138 double	atanh(double);
    139 double	cbrt(double);
    140 double	erf(double);
    141 double	erfc(double);
    142 double	exp2(double);
    143 double	expm1(double);
    144 double	fma(double, double, double);
    145 double	hypot(double, double);
    146 int	ilogb(double) __attribute_const__;
    147 double	lgamma(double);
    148 long long llrint(double);
    149 long long llround(double);
    150 double	log1p(double);
    151 double log2(double) __INTRODUCED_IN(18);
    152 double	logb(double);
    153 long	lrint(double);
    154 long	lround(double);
    155 
    156 double nan(const char*) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
    157     __INTRODUCED_IN_X86(9);
    158 
    159 double	nextafter(double, double);
    160 double	remainder(double, double);
    161 double	remquo(double, double, int*);
    162 double	rint(double);
    163 
    164 double	copysign(double, double) __attribute_const__;
    165 double	fdim(double, double);
    166 double	fmax(double, double) __attribute_const__;
    167 double	fmin(double, double) __attribute_const__;
    168 double	nearbyint(double);
    169 double	round(double);
    170 double scalbln(double, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
    171 double scalbn(double, int);
    172 double	tgamma(double);
    173 double	trunc(double);
    174 
    175 float	acosf(float);
    176 float	asinf(float);
    177 float	atanf(float);
    178 float	atan2f(float, float);
    179 float	cosf(float);
    180 float	sinf(float);
    181 float	tanf(float);
    182 
    183 float	coshf(float);
    184 float	sinhf(float);
    185 float	tanhf(float);
    186 
    187 float	exp2f(float);
    188 float	expf(float);
    189 float	expm1f(float);
    190 float	frexpf(float, int *);	/* fundamentally !__attribute_const__ */
    191 int	ilogbf(float) __attribute_const__;
    192 float	ldexpf(float, int);
    193 float	log10f(float);
    194 float	log1pf(float);
    195 float log2f(float) __INTRODUCED_IN(18);
    196 float	logf(float);
    197 float	modff(float, float *);	/* fundamentally !__attribute_const__ */
    198 
    199 float	powf(float, float);
    200 float	sqrtf(float);
    201 
    202 float	ceilf(float);
    203 float	fabsf(float) __attribute_const__;
    204 float	floorf(float);
    205 float	fmodf(float, float);
    206 float	roundf(float);
    207 
    208 float	erff(float);
    209 float	erfcf(float);
    210 float	hypotf(float, float);
    211 float	lgammaf(float);
    212 float tgammaf(float) __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
    213 
    214 float	acoshf(float);
    215 float	asinhf(float);
    216 float	atanhf(float);
    217 float	cbrtf(float);
    218 float	logbf(float);
    219 float	copysignf(float, float) __attribute_const__;
    220 long long llrintf(float);
    221 long long llroundf(float);
    222 long	lrintf(float);
    223 long	lroundf(float);
    224 float nanf(const char*) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13)
    225     __INTRODUCED_IN_X86(9);
    226 float	nearbyintf(float);
    227 float	nextafterf(float, float);
    228 float	remainderf(float, float);
    229 float	remquof(float, float, int *);
    230 float	rintf(float);
    231 float	scalblnf(float, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
    232 float scalbnf(float, int);
    233 float	truncf(float);
    234 
    235 float	fdimf(float, float);
    236 float	fmaf(float, float, float);
    237 float	fmaxf(float, float) __attribute_const__;
    238 float	fminf(float, float) __attribute_const__;
    239 
    240 long double acoshl(long double) __INTRODUCED_IN(21);
    241 long double acosl(long double) __INTRODUCED_IN(21);
    242 long double asinhl(long double) __INTRODUCED_IN(21);
    243 long double asinl(long double) __INTRODUCED_IN(21);
    244 long double atan2l(long double, long double) __INTRODUCED_IN(21);
    245 long double atanhl(long double) __INTRODUCED_IN(21);
    246 long double atanl(long double) __INTRODUCED_IN(21);
    247 long double cbrtl(long double) __INTRODUCED_IN(21);
    248 long double ceill(long double);
    249 long double copysignl(long double, long double) __attribute_const__;
    250 long double coshl(long double) __INTRODUCED_IN(21);
    251 long double cosl(long double) __INTRODUCED_IN(21);
    252 long double erfcl(long double) __INTRODUCED_IN(21);
    253 long double erfl(long double) __INTRODUCED_IN(21);
    254 long double exp2l(long double) __INTRODUCED_IN(21);
    255 long double expl(long double) __INTRODUCED_IN(21);
    256 long double expm1l(long double) __INTRODUCED_IN(21);
    257 long double fabsl(long double) __attribute_const__;
    258 long double fdiml(long double, long double);
    259 long double floorl(long double);
    260 long double fmal(long double, long double, long double) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
    261 long double fmaxl(long double, long double) __attribute_const__;
    262 long double fminl(long double, long double) __attribute_const__;
    263 long double fmodl(long double, long double) __INTRODUCED_IN(21);
    264 long double frexpl(long double value, int*)
    265     __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; /* fundamentally !__attribute_const__ */
    266 long double hypotl(long double, long double) __INTRODUCED_IN(21);
    267 int ilogbl(long double) __attribute_const__;
    268 long double ldexpl(long double, int);
    269 long double lgammal(long double) __INTRODUCED_IN(21);
    270 long long llrintl(long double) __INTRODUCED_IN(21);
    271 long long llroundl(long double);
    272 long double log10l(long double) __INTRODUCED_IN(21);
    273 long double log1pl(long double) __INTRODUCED_IN(21);
    274 long double log2l(long double) __INTRODUCED_IN(18);
    275 long double logbl(long double) __INTRODUCED_IN(18);
    276 long double logl(long double) __INTRODUCED_IN(21);
    277 long lrintl(long double) __INTRODUCED_IN(21);
    278 long lroundl(long double);
    279 long double modfl(long double, long double*) __INTRODUCED_IN(21); /* fundamentally !__attribute_const__ */
    280 long double nanl(const char*) __attribute_const__ __INTRODUCED_IN(13);
    281 long double nearbyintl(long double) __INTRODUCED_IN(21);
    282 long double nextafterl(long double, long double) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;
    283 double nexttoward(double, long double) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
    284 float nexttowardf(float, long double);
    285 long double nexttowardl(long double, long double) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
    286 long double powl(long double, long double) __INTRODUCED_IN(21);
    287 long double remainderl(long double, long double) __INTRODUCED_IN(21);
    288 long double remquol(long double, long double, int*) __INTRODUCED_IN(21);
    289 long double rintl(long double) __INTRODUCED_IN(21);
    290 long double roundl(long double);
    291 long double scalblnl(long double, long) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
    292 long double scalbnl(long double, int);
    293 long double sinhl(long double) __INTRODUCED_IN(21);
    294 long double sinl(long double) __INTRODUCED_IN(21);
    295 long double sqrtl(long double) __INTRODUCED_IN(21);
    296 long double tanhl(long double) __INTRODUCED_IN(21);
    297 long double tanl(long double) __INTRODUCED_IN(21);
    298 long double tgammal(long double) __INTRODUCED_IN(21);
    299 long double truncl(long double);
    300 
    301 double j0(double);
    302 double j1(double);
    303 double jn(int, double);
    304 double y0(double);
    305 double y1(double);
    306 double yn(int, double);
    307 
    308 #define M_E		2.7182818284590452354	/* e */
    309 #define M_LOG2E		1.4426950408889634074	/* log 2e */
    310 #define M_LOG10E	0.43429448190325182765	/* log 10e */
    311 #define M_LN2		0.69314718055994530942	/* log e2 */
    312 #define M_LN10		2.30258509299404568402	/* log e10 */
    313 #define M_PI		3.14159265358979323846	/* pi */
    314 #define M_PI_2		1.57079632679489661923	/* pi/2 */
    315 #define M_PI_4		0.78539816339744830962	/* pi/4 */
    316 #define M_1_PI		0.31830988618379067154	/* 1/pi */
    317 #define M_2_PI		0.63661977236758134308	/* 2/pi */
    318 #define M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
    319 #define M_SQRT2		1.41421356237309504880	/* sqrt(2) */
    320 #define M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
    321 
    322 #define MAXFLOAT	((float)3.40282346638528860e+38)
    323 
    324 #if defined(__USE_BSD) || defined(__USE_GNU)
    325 double gamma(double);
    326 double scalb(double, double);
    327 double drem(double, double);
    328 int finite(double) __attribute_const__;
    329 int isnanf(float) __attribute_const__;
    330 double gamma_r(double, int*);
    331 double lgamma_r(double, int*);
    332 double significand(double);
    333 long double lgammal_r(long double, int*) __INTRODUCED_IN(23);
    334 long double significandl(long double) __INTRODUCED_IN(21);
    335 float dremf(float, float);
    336 int finitef(float) __attribute_const__;
    337 float gammaf(float);
    338 float j0f(float);
    339 float j1f(float);
    340 float jnf(int, float);
    341 float scalbf(float, float);
    342 float y0f(float);
    343 float y1f(float);
    344 float ynf(int, float);
    345 float gammaf_r(float, int *);
    346 float lgammaf_r(float, int *);
    347 float significandf(float);
    348 #endif
    349 
    350 #if defined(__USE_GNU)
    351 #define M_El            2.718281828459045235360287471352662498L /* e */
    352 #define M_LOG2El        1.442695040888963407359924681001892137L /* log 2e */
    353 #define M_LOG10El       0.434294481903251827651128918916605082L /* log 10e */
    354 #define M_LN2l          0.693147180559945309417232121458176568L /* log e2 */
    355 #define M_LN10l         2.302585092994045684017991454684364208L /* log e10 */
    356 #define M_PIl           3.141592653589793238462643383279502884L /* pi */
    357 #define M_PI_2l         1.570796326794896619231321691639751442L /* pi/2 */
    358 #define M_PI_4l         0.785398163397448309615660845819875721L /* pi/4 */
    359 #define M_1_PIl         0.318309886183790671537767526745028724L /* 1/pi */
    360 #define M_2_PIl         0.636619772367581343075535053490057448L /* 2/pi */
    361 #define M_2_SQRTPIl     1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
    362 #define M_SQRT2l        1.414213562373095048801688724209698079L /* sqrt(2) */
    363 #define M_SQRT1_2l      0.707106781186547524400844362104849039L /* 1/sqrt(2) */
    364 void sincos(double, double*, double*);
    365 void sincosf(float, float*, float*);
    366 void sincosl(long double, long double*, long double*);
    367 #endif
    368 
    369 __END_DECLS
    370 
    371 #endif /* !_MATH_H_ */
    372