/*
        math.h
        Definitions for the math floating point package.
*/

#ifndef  __MATH_H
#define  __MATH_H

#include <_ansi.h>

#define HUGE_VAL        1.7976931348623157E+308 /* largest mag represent as double */

#ifdef __cplusplus
extern "C" {
#endif

enum version {libm_ieee = -1, c_issue_4, ansi_1, strict_ansi};

#ifdef __STDC__
extern const enum version _lib_version;
#else
extern enum version _lib_version;
#endif

double  _EXFUN(acos  ,(double x));
double  _EXFUN(asin  ,(double x));
double  _EXFUN(atan  ,(double x));
double  _EXFUN(atan2 ,(double y, double x));
double  _EXFUN(cos   ,(double x));
double  _EXFUN(sin   ,(double x));
double  _EXFUN(tan   ,(double x));
double  _EXFUN(cosh  ,(double x));
double  _EXFUN(sinh  ,(double x));
double  _EXFUN(tanh  ,(double x));
double  _EXFUN(exp   ,(double x));
double  _EXFUN(log1p ,(double x));
double  _EXFUN(frexp ,(double x, int *exp));
double  _EXFUN(ldexp ,(double x, int exp));
double  _EXFUN(log   ,(double x));
double  _EXFUN(log10 ,(double x));
double  _EXFUN(log2  ,(double x));
double  _EXFUN(modf  ,(double x, double *ipart));
double  _EXFUN(pow   ,(double x, double y));
double  _EXFUN(sqrt  ,(double x));
double  _EXFUN(cbrt  ,(double x));
double  _EXFUN(ceil  ,(double x));
double  _EXFUN(floor ,(double x));

#if __STDC_VERSION__ >= 199901L
double  _EXFUN(nearbyint ,(double x));
double  _EXFUN(rint  ,(double x));
long    _EXFUN(lrint ,(double x));
double  _EXFUN(round ,(double x));
double  _EXFUN(trunc ,(double x));
#endif

double  _EXFUN(expm1 ,(double x));
double  _EXFUN(fabs  ,(double x));
double  _EXFUN(fmod  ,(double x, double y));
double  _EXFUN(atanh, (double x));
double  _EXFUN(acosh, (double x));
double  _EXFUN(asinh, (double x));

extern int signgam;
double _EXFUN(gamma, (double x));
double _EXFUN(lgamma, (double x));

double _EXFUN(erf,(double x));
double _EXFUN(erfc,(double x));
double _EXFUN(hypot,(double,double));
double _EXFUN(infinity,(void));

struct exception
{
  int type;
  char *name;
  double arg1;
  double arg2;
  double retval;
};

int _EXFUN(matherr,(struct exception *e));

double  _EXFUN(exp10  ,(double x));
double  _EXFUN(exp2  ,(double x));
double  _EXFUN(annuity  ,(double, double));
double  _EXFUN(compound  ,(double, double));
double  _EXFUN(drem  ,(double, double));
double  _EXFUN(copysign  ,(double, double));

int     _EXFUN(finite  ,(double x));
int     _EXFUN(isnan  ,(double x));
int     _EXFUN(isinf  ,(double x));
int     _EXFUN(signbit  ,(double x));

/* Poor man's C99 fpclass test macros */
#define isfinite(x)     finite(x)
#define isnan(x)        isnan(x)
#define isinf(x)        isinf(x)
int     _EXFUN(isnormal  ,(double x));
int     _EXFUN(issubnormal  ,(double x));
int     _EXFUN(iszero  ,(double x));
int     _EXFUN(ilogb  ,(double x));
double  _EXFUN(nextafter  ,(double, double));
double  _EXFUN(scalbn  ,(double, int));
double  _EXFUN(logb  ,(double x));
double  _EXFUN(scalb  ,(double, double));
double  _EXFUN(significand  ,(double x));
double  _EXFUN(min_subnormal,(_VOID));
double  _EXFUN(max_subnormal,(_VOID));
double  _EXFUN(min_normal,(_VOID));
double  _EXFUN(max_normal,(_VOID));
double  _EXFUN(quiet_nan,(_VOID));
double  _EXFUN(signaling_nan,(_VOID));
double  _EXFUN(remainder  ,(double, double));
_VOID   _EXFUN(sincos  ,(double, double*, double*));

/* math functions of float type */

_FLOAT_RET _EXFUN(acosf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(asinf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(atanf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(atan2f ,(_FLOAT_ARG, _FLOAT_ARG));
_FLOAT_RET _EXFUN(cosf   ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(sinf   ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(tanf   ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(coshf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(sinhf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(tanhf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(expf   ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(log1pf ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(frexpf ,(_FLOAT_ARG, int *exp));
_FLOAT_RET _EXFUN(ldexpf ,(_FLOAT_ARG, int exp));
_FLOAT_RET _EXFUN(logf   ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(log10f ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(log2f  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(modff  ,(_FLOAT_ARG, _FLOAT_ARG *ipart));
_FLOAT_RET _EXFUN(powf   ,(_FLOAT_ARG, _FLOAT_ARG));
_FLOAT_RET _EXFUN(sqrtf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(cbrtf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(ceilf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(floorf ,(_FLOAT_ARG));

#if __STDC_VERSION__ >= 199901L
_FLOAT_RET _EXFUN(nearbyintf ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(rintf  ,(_FLOAT_ARG));
long       _EXFUN(lrintf ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(roundf ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(truncf ,(_FLOAT_ARG));
#endif

_FLOAT_RET _EXFUN(expm1f ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(fabsf  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(fmodf  ,(_FLOAT_ARG, _FLOAT_ARG));
_FLOAT_RET _EXFUN(atanhf, (_FLOAT_ARG));
_FLOAT_RET _EXFUN(acoshf, (_FLOAT_ARG));
_FLOAT_RET _EXFUN(asinhf, (_FLOAT_ARG));

_FLOAT_RET _EXFUN(gammaf, (_FLOAT_ARG));
_FLOAT_RET _EXFUN(lgammaf, (_FLOAT_ARG));

_FLOAT_RET _EXFUN(erff,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(erfcf,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(hypotf,(_FLOAT_ARG,_FLOAT_ARG));

_FLOAT_RET _EXFUN(exp10f  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(exp2f  ,(_FLOAT_ARG));
_FLOAT_RET _EXFUN(annuityf  ,(_FLOAT_ARG, _FLOAT_ARG));
_FLOAT_RET _EXFUN(compoundf  ,(_FLOAT_ARG, _FLOAT_ARG));
_FLOAT_RET _EXFUN(dremf  ,(_FLOAT_ARG, _FLOAT_ARG));
_FLOAT_RET _EXFUN(copysignf, (_FLOAT_ARG, _FLOAT_ARG));

int        _EXFUN(finitef, (_FLOAT_ARG));
int        _EXFUN(isnanf, (_FLOAT_ARG));
int        _EXFUN(isinff, (_FLOAT_ARG));
int        _EXFUN(signbitf, (_FLOAT_ARG));

int        _EXFUN(isnormalf, (_FLOAT_ARG));
int        _EXFUN(issubnormalf, (_FLOAT_ARG));
int        _EXFUN(iszerof, (_FLOAT_ARG));
int        _EXFUN(ilogbf, (_FLOAT_ARG));
_FLOAT_RET _EXFUN(nextafterf, (_FLOAT_ARG, _FLOAT_ARG));
_FLOAT_RET _EXFUN(scalbnf, (_FLOAT_ARG, int));
_FLOAT_RET _EXFUN(logbf, (_FLOAT_ARG));
_FLOAT_RET _EXFUN(scalbf, (_FLOAT_ARG, _FLOAT_ARG));
_FLOAT_RET _EXFUN(significandf, (_FLOAT_ARG));
_FLOAT_RET _EXFUN(remainderf  ,(_FLOAT_ARG, _FLOAT_ARG));
_VOID      _EXFUN(sincosf  ,(_FLOAT_ARG, _FLOAT_ARG*, _FLOAT_ARG*));

/* math functions of long double type */
long double _EXFUN(fabsl  ,(long double x));
long double _EXFUN(sqrtl  ,(long double x));

#define DOMAIN 1
#define SING 2
#define OVERFLOW 3
#define UNDERFLOW 4
#define TLOSS 5
#define PLOSS 6

#define M_E             2.7182818284590452354
#define M_LOG2E         1.4426950408889634074
#define M_LOG10E        0.43429448190325182765
#define M_LN2           0.69314718055994530942
#define M_LN10          2.30258509299404568402
#define M_PI            3.14159265358979323846
#define M_TWOPI         (M_PI * 2.0)
#define M_PI_2          1.57079632679489661923
#define M_PI_4          0.78539816339744830962
#define M_3PI_4         2.3561944901923448370E0
#define M_SQRTPI        1.77245385090551602792981
#define M_1_PI          0.31830988618379067154
#define M_2_PI          0.63661977236758134308
#define M_2_SQRTPI      1.12837916709551257390
#define M_SQRT2         1.41421356237309504880
#define M_SQRT1_2       0.70710678118654752440
#define M_LN2LO         1.9082149292705877000E-10
#define M_LN2HI         6.9314718036912381649E-1
#define M_SQRT3         1.73205080756887719000
#define M_IVLN10        0.43429448190325182765  /* 1 / log(10) */
#define M_LOG2_E        0.693147180559945309417
#define M_INVLN2        1.4426950408889633870E0 /* 1 / log(2) */

#ifdef __cplusplus
}
#endif

#endif /* __MATH_H */
