/* 
 * Math2.h - misc. math abstract data type include file.
 * 
 * Author:	L. Van Warren
 * Date:	April 1984
 * Copyright (c) 1984-1995 L. Van Warren
 *
 */

/*****************************************************************
 * 
 * The value of PI and other useful constants.
 */

#define PI             3.14159265358979323844
#define MATH2_E        2.7182818284590452354
#define MATH2_LOG2E    1.4426950408889634074
#define MATH2_LOG10E   0.43429448190325182765
#define MATH2_LN2      0.69314718055994530942
#define MATH2_LN10     2.30258509299404568402
#define MATH2_PI       3.14159265358979323846
#define MATH2_PI_2     1.57079632679489661923
#define MATH2_PI_4     0.78539816339744830962
#define MATH2_1_PI     0.31830988618379067154
#define MATH2_2_PI     0.63661977236758134308
#define MATH2_2_SQRTPI 1.12837916709551257390
#define MATH2_SQRT2    1.41421356237309504880
#define MATH2_SQRT1_2  0.70710678118654752440


/*****************************************************************
 * Find the max and min of two numbers.
 */

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

/*****************************************************************
 * Round off a REALing point numbers to ints and shorts.
 */

#define IRND(a) ((Int)((a)+0.5))
#define SRND(a) ((Short)((a)+0.5))

/*****************************************************************
 * Absolute value macros.
 */

#define  ABS(a) ((a)>=0?(a):(-(a)))

/*****************************************************************
 * Miscellaneous self-explanatory macros.
 */
#define SQUARED(a)   ((a)*(a))
#define SQR(a)       ((a)*(a))
#define CUBED(a)     ((a)*(a)*(a))
#define REAL(x)      ((Real)(x))
#define INT(x)       ((Int)(x))
#define EPS          1.17549435e-38			/* For TI C6711 DSK */
#define APX_EQ(x,y)  (ABS((x)-(y))<=EPS)	/* Approximate equality. */

#define DEG_TO_RAD(x) ((x)*0.017453293)
#define RAD_TO_DEG(x) ((x)*57.29577951)

#define HUGE 3.40282347e+38					/* For TI C6711 DSK */
               
#define IN_INTERVAL(a,x,b) ((a<=x)&&(x<=b))

extern Real          xToN(Real x, Int n);
extern Int           iToN(Int i, Int n);
extern Int         signOf(Real a);
extern Real     findParam(Real a, Real b, Real c);
extern Int    BooleanRand(void);
extern Real uniformRandom(void);
extern Real  GaussianRand(void);
extern Int     isPwrOfTwo(Int number);
extern Int   nextPwrOfTwo(Int number);
 
#define TWO_REAL_ROOTS		1
#define DOUBLE_ROOT			2
#define TWO_COMPLEX_ROOTS	3
#define NOT_QUADRATIC_FORM	4

typedef struct
{
	Int    type;
	Complex x[2];
} QuadRoots;

extern QuadRoots  solveQuadratic(Real, Real, Real);
extern void      fprintQuadRoots(FILE*, QuadRoots);
extern QuadRoots  fscanQuadRoots(FILE*);
extern void      fwriteQuadRoots(FILE*, QuadRoots);
extern QuadRoots  freadQuadRoots(FILE*);
