1 /* 2 ** Distributed under the terms of the OpenBeOS License. 3 */ 4 #ifndef _MATH_H_ 5 #define _MATH_H_ 6 7 8 #define M_E 2.7182818284590452354 /* e */ 9 #define M_LOG2E 1.4426950408889634074 /* log 2e */ 10 #define M_LOG10E 0.43429448190325182765 /* log 10e */ 11 #define M_LN2 0.69314718055994530942 /* log e2 */ 12 #define M_LN10 2.30258509299404568402 /* log e10 */ 13 #define M_PI 3.14159265358979323846 /* pi */ 14 #define M_PI_2 1.57079632679489661923 /* pi/2 */ 15 #define M_PI_4 0.78539816339744830962 /* pi/4 */ 16 #define M_1_PI 0.31830988618379067154 /* 1/pi */ 17 #define M_2_PI 0.63661977236758134308 /* 2/pi */ 18 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 19 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 20 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 21 22 #define PI M_PI 23 #define PI2 M_PI_2 24 25 /* platform independent IEEE floating point special values */ 26 #define __HUGE_VAL_v 0x7ff0000000000000LL 27 #define __huge_val_t union { unsigned char __c[8]; long long __ll; double __d; } 28 #define HUGE_VAL (((__huge_val_t) { __ll: __HUGE_VAL_v }).__d) 29 30 #define __HUGE_VALF_v 0x7f800000L 31 #define __huge_valf_t union { unsigned char __c[4]; long __l; float __f; } 32 #define HUGE_VALF (((__huge_valf_t) { __l: __HUGE_VALF_v }).__f) 33 34 // ToDo: define HUGE_VALL for long doubles 35 36 #define __NAN_VALF_v 0x7fc00000L 37 #define NAN (((__huge_valf_t) { __l: __NAN_VALF_v }).__f) 38 39 #define INFINITY HUGE_VALF 40 41 /* floating-point categories */ 42 #define FP_NAN 0 43 #define FP_INFINITE 1 44 #define FP_ZERO 2 45 #define FP_SUBNORMAL 3 46 #define FP_NORMAL 4 47 48 #ifdef __cplusplus 49 struct __exception; 50 extern "C" int matherr(struct __exception *); 51 struct __exception { 52 #else 53 struct exception; 54 extern int matherr(struct exception *); 55 struct exception { 56 #endif 57 int type; 58 char *name; 59 double arg1; 60 double arg2; 61 double retval; 62 }; 63 64 #define DOMAIN 1 65 #define SING 2 66 #define OVERFLOW 3 67 #define UNDERFLOW 4 68 #define TLOSS 5 69 #define PLOSS 6 70 71 extern int signgam; 72 73 74 #ifdef __cplusplus 75 extern "C" { 76 #endif 77 78 extern double acos(double x); 79 extern double asin(double x); 80 extern double atan(double x); 81 extern double atan2(double x, double y); 82 extern double ceil(double x); 83 extern double cos(double x); 84 extern double cosh(double x); 85 extern double exp(double x); 86 extern double fabs(double x); 87 extern double floor(double x); 88 extern double fmod(double x, double y); 89 extern double frexp(double x, int *_exponent); 90 extern double ldexp(double x, int exponent); 91 extern double log(double x); 92 extern double log10(double x); 93 extern double modf(double x, double *y); 94 extern double pow(double x, double y); 95 extern double sin(double x); 96 extern double sinh(double x); 97 extern double sqrt(double x); 98 extern double tan(double x); 99 extern double tanh(double x); 100 101 /* some BSD non-ANSI or POSIX math functions */ 102 extern double acosh(double x); 103 extern double asinh(double x); 104 extern double atanh(double x); 105 extern double cbrt(double x); 106 extern double erf(double x); 107 extern double erfc(double x); 108 extern double expm1(double x); 109 extern double gamma(double x); 110 extern double gamma_r(double x, int *y); 111 extern double hypot(double x, double y); 112 extern int ilogb(double x); 113 extern double j0(double x); 114 extern double j1(double x); 115 extern double jn(int x, double y); 116 extern double lgamma(double x); 117 extern double lgamma_r(double x, int *y); 118 extern double log1p(double x); 119 extern double logb(double x); 120 extern double nextafter(double x, double y); 121 extern double remainder(double x, double y); 122 extern double rint(double x); 123 extern double scalb (double x, double y); 124 extern double y0(double x); 125 extern double y1(double x); 126 extern double yn(int x, double y); 127 128 /* other stuff as defined in BeOS */ 129 extern double significand(double x); 130 extern double copysign(double x, double y); 131 extern double scalbn(double x, int y); 132 extern double drem(double x, double y); 133 extern int isnan(double x); 134 extern int isfinite(double x); 135 extern int finite(double x); 136 extern float modff(float x, float *y); 137 extern float acosf(float x); 138 extern float asinf(float x); 139 extern float atanf(float x); 140 extern float atan2f(float y, float x); 141 extern float cosf(float x); 142 extern float sinf(float x); 143 extern float tanf(float x); 144 extern float coshf(float x); 145 extern float sinhf(float x); 146 extern float tanhf(float x); 147 extern float acoshf(float x); 148 extern float asinhf(float x); 149 extern float atanhf(float x); 150 extern float expf(float x); 151 extern float frexpf(float x, int *_exponent); 152 extern float ldexpf(float x, int exponent); 153 extern float logf(float x); 154 extern float log10f(float x); 155 extern float expm1f(float x); 156 extern float log1pf(float x); 157 extern float logbf(float x); 158 extern float powf(float x, float y); 159 extern float sqrtf(float x); 160 extern float hypotf(float x, float y); 161 extern float cbrtf(float x); 162 extern float ceilf(float x); 163 extern float fabsf(float x); 164 extern float floorf(float x); 165 extern float fmodf(float x, float y); 166 extern int isinff(float value); 167 extern int finitef(float value); 168 extern float infnanf(int error); 169 extern float dremf(float x, float y); 170 extern float significandf(float x); 171 extern float copysignf(float x, float y); 172 extern int isnanf(float value); 173 extern float j0f(float x); 174 extern float j1f(float x); 175 extern float jnf(int x, float y); 176 extern float y0f(float x); 177 extern float y1f(float x); 178 extern float ynf(int x, float y); 179 extern float erff(float x); 180 extern float erfcf(float x); 181 extern float gammaf(float x); 182 extern float lgammaf(float x); 183 extern float gammaf_r(float x, int *y); 184 extern float lgammaf_r(float x, int *y); 185 extern float rintf(float x); 186 extern float nextafterf(float x, float y); 187 extern float remainderf(float x, float y); 188 extern float scalbf(float x, float n); 189 extern float scalbnf(float x, int n); 190 extern int ilogbf(float x); 191 192 /* prototypes for functions used in the macros below */ 193 extern int __fpclassifyf(float value); 194 extern int __signbitf(float value); 195 extern int __finitef(float value); 196 extern int __isnanf(float value); 197 extern int __isinff(float value); 198 199 extern int __fpclassifyl(long double value); 200 extern int __signbitl(long double value); 201 extern int __finitel(long double value); 202 extern int __isnanl(long double value); 203 extern int __isinfl(long double value); 204 205 extern int __fpclassify(double value); 206 extern int __signbit(double value); 207 extern int __finite(double value); 208 extern int __isnan(double value); 209 extern int __isinf(double value); 210 211 /* returns number of classification appropriate for 'value' */ 212 #define fpclassify(value) \ 213 (sizeof(value) == sizeof(float) ? __fpclassifyf(value) \ 214 : sizeof(value) == sizeof(double) ? __fpclassify(value) \ 215 : __fpclassifyl(value)) 216 217 /* returns non-zero if 'value' is negative */ 218 # define signbit(value) \ 219 (sizeof(value) == sizeof(float) ? __signbitf(value) \ 220 : sizeof(value) == sizeof(double) ? __signbit(value) \ 221 : __signbitl(value)) 222 223 /* returns non-zero if 'value' is not Inf or NaN */ 224 # define isfinite(value) \ 225 (sizeof(value) == sizeof(float) ? __finitef(value) \ 226 : sizeof(value) == sizeof(double) ? __finite(value) \ 227 : __finitel(value)) 228 229 /* returns non-zero if 'value' is neither zero, sub-normal, Inf, nor NaN */ 230 # define isnormal(value) \ 231 (fpclassify(value) == FP_NORMAL) 232 233 /* returns non-zero if 'value' is NaN */ 234 # define isnan(value) \ 235 (sizeof(value) == sizeof(float) ? __isnanf(value) \ 236 : sizeof(value) == sizeof(double) ? __isnan(value) \ 237 : __isnanl(value)) 238 239 /* returns non-zero if 'value is Inf */ 240 # define isinf(x) \ 241 (sizeof(value) == sizeof(float) ? __isinff(value) \ 242 : sizeof(value) == sizeof(double) ? __isinf(value) \ 243 : __isinfl(value)) 244 245 #ifdef __cplusplus 246 } 247 #endif 248 249 #endif /* _MATH_H_ */ 250