/*
 * math.h for libRILc.

    This file is part of libRILc, a standard C library for GCC on Amiga OS.
    Copyright © 1998  Rask Ingemann Lambertsen

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    As a special exception, if you link this library with files compiled
    with a GNU compiler to produce an executable, this does not cause the
    resulting executable to be covered by the GNU General Public License.
    This exception does not however invalidate any other reasons why the
    executable file might be covered by the GNU General Public License.
*/

#ifndef _MATH_H
#define _MATH_H

#ifdef __cplusplus
extern "C" {
#endif

#ifndef HUGE_VAL
#define HUGE_VAL 1e500 /* IEEE: positive infinity */
#endif

/*
 *      Useful mathmatical constants:
 *
 * M_E          -- e
 * M_LOG2E      -- log2(e)
 * M_LOG10E     -- log10(e)
 * M_LN2        -- ln(2)
 * M_2PI        -- 2*pi
 * M_PI         -- pi
 * M_PI_2       -- pi/2
 * M_PI_4       -- pi/4
 * M_1_PI       -- 1/pi
 * M_2_PI       -- 2/pi
 * M_2_SQRTPI   -- 2/(sqrt(pi))
 * M_SQRT2      -- sqrt(2)
 * M_SQRT1_2    -- 1/sqrt(2)
 * HUGE         -- +infinity (single precision)
 *
 * These constants are provided to more significant digits
 * than is necessary for a 64-bit double precision number; they 
 * may be used for other purposes where the extra precision
 * is necessary or useful.
 */

#define M_E         2.71828182845904523536028747135266250
#define M_LOG2E     1.44269504088896340735992468100189214
#define M_LOG10E    0.434294481903251827651128918916605082
#define M_LN2       0.693147180559945309417232121458176568
#define M_LN10      2.30258509299404568401799145468436421
#define M_2PI       6.2831853071795862320E0                  /* Hex  2^ 2 * 1.921FB54442D18 */
#define M_PI        3.14159265358979323846264338327950288
#define M_PI_2      1.57079632679489661923132169163975144
#define M_PI_4      0.785398163397448309615660845819875721
#define M_1_PI      0.318309886183790671537767526745028724
#define M_2_PI      0.636619772367581343075535053490057448
#define M_2_SQRTPI  1.12837916709551257389615890312154517
#define M_SQRT2     1.41421356237309504880168872420969808
#define M_SQRT1_2   0.707106781186547524400844362104849039
#define	HUGE	    ((float)3.40282346638528860e+38)

/* #define DINFINITY _DBLINF */
#define DINFINITY HUGE_VAL

/* This is the nearest number to the cube root of MAXDOUBLE that   */
/*      doesn't cause the cube of it to overflow.                  */
/* In double precision hex this constant is: 554428a2 f98d728a     */
#define CUBRTHUGE      5.6438030941223618e102
#define INV_CUBRTHUGE  1.7718548704178434e-103

struct dbl_hypot
{
  double x, y;
};

/* Functions in the math library. */

extern  double    acos(double);
extern  double    asin(double);
extern  double    atan(double);
extern  double    atan2(double,double);
extern  double    ceil(double);
extern  double    cos(double);
extern  double    cosh(double);
extern  double    exp(double);
extern  double    fabs(double);
extern  double    floor(double);
extern  double    fmod(double, double);
extern  double    frexp(double, int *);
extern  double    ldexp(double, int);
extern  double    log(double);
extern  double    log10(double);
extern  double    modf(double, double *);
extern  double    pow(double, double);
extern  double    sin(double);
extern  double    sinh(double);
extern  double    sqrt(double);
extern  double    tan(double);
extern  double    tanh(double);
extern  double    erf(double);
extern  double    erfc(double);
extern  int       isnan(double);
extern  int       isinf(double);
extern  double    hypot(double,double);
extern  double    j0(double);
extern  double    j1(double);
extern  double    jn(int, double);
extern  double    gamma(double);
extern  double    lgamma(double);
extern  double    y0(double);
extern  double    y1(double);
extern  double    yn(int, double);
extern  double    acosh(double);
extern  double    asinh(double);
extern  double    atanh(double);
extern  double    cabs(struct dbl_hypot);
extern  double    cbrt(double);
extern  double    copysign (double, double);
extern  double    drem(double, double);
extern  double    exp__E(double, double);
extern  double    expm1(double);
extern  double    log1p(double);
extern  double    log__L(double);
extern  double    nearest(double);
extern  double    remainder(double, double);
extern  double    rint(double);
extern  double    rsqrt(double);
extern  double    scalb(double, double);
extern  double    trunc(double);
extern  int       itrunc(double);
extern  int       unordered(double, double);
extern  unsigned  uitrunc(double);
extern  double    logb(double);
extern  int       ilogb(double);
extern  double    nextafter(double, double);
#ifndef __cplusplus
extern  int       class(double);
#endif
extern  int       finite(double);

/* Structure passed to math exception handler. */

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

/* Types for exception.type. */

#define 	DOMAIN		01
#define		SING		02
#define		OVERFLOW	03
#define		UNDERFLOW	04
#define		TLOSS		05
#define		PLOSS		06

#ifdef __cplusplus
}
#endif

#endif /* _MATH_H */
