HPGCC3 Documentation 3.0 R003
|
00001 //& *** (c) 2006-2011 The HPGCC3 Team *** 00002 //& Claudio Lapilli 00003 //& Ingo Blank 00004 //& 00005 //& This file is licensed under the terms and conditions of the 00006 //& HPGCC3 license that is included with the source distribution. 00007 //& *** (c) 2006-2011 The HPGCC3 Team *** 00008 00009 // $Id: math.h 523 2007-12-01 19:39:12Z ingo $ 00010 00011 #ifndef _HPMATH_H 00012 #define _HPMATH_H 00013 #ifndef USING_DECFLOAT 00014 00015 // SKIP INCLUSION, IF USING DECIMAL FLOATING POINT CLASS ! 00016 // <ibl ; 2007-12-01> 00017 00018 // LONG TYPE DEFINITION, ADDED BY CLAUDIO 01/14/05 00019 #ifndef _LONGLONG_DEF 00020 typedef unsigned long long ULONGLONG; 00021 typedef long long LONGLONG; 00022 #define _LONGLONG_DEF 00023 #endif 00024 00025 00036 #ifndef min 00037 #define min(a,b) ((a) < (b) ? (a) : (b)) 00038 #endif 00039 00040 #ifndef max 00041 #define max(a,b) ((a) > (b) ? (a) : (b)) 00042 #endif 00043 00044 #ifndef abs 00045 #define abs(a) ((a) < 0 ? -(a) : (a)) 00046 #endif 00047 00048 00049 00050 double ipow(double x, int n); 00051 // NEW 10^X ALGORITHM BY CLAUDIO 00052 double i10powx(int n); 00053 // INTERNAL FUNCTIONS 00054 // CREATE A DOUBLE FROM A 64-BIT MANTISSA AND AN EXPONENT 00055 double assemble_double(unsigned int sign,unsigned long long mantissa,int exponent); 00056 // CALCULATE 10^X WITH 64-BIT PRECISION 00057 // RETURN A BASE-2 EXPONENT + A 64-BIT MANTISSA 00058 // MORE ACCURATE THAN STANDARD POW AND IPOW 00059 int _i10pow64(int exp10,unsigned long long *mant); 00060 00061 00062 00063 double square(double x); 00064 double round(double a); 00065 00066 00067 00068 // libm 00069 00070 double modf(double x, double *iptr); 00071 double frexp(double x, int *exp); 00072 double scalbn (double x, int n); 00073 double copysign(double x, double y); 00074 00075 double __ieee754_log(double x); 00076 double __ieee754_log10(double x); 00077 double __ieee754_exp(double x); 00078 double __ieee754_pow(double x, double y); 00079 double __ieee754_sqrt(double x); 00080 00081 double __ieee754_asin(double x); //EDIT BY AL, 29th Oct 00082 double __ieee754_acos(double x); 00083 double __ieee754_atan2(double y, double x); 00084 00085 double sin(double x); 00086 double cos(double x); 00087 double tan(double x); 00088 00089 double atan(double x); //EDIT BY AL, 29th Oct 00090 00091 double floor(double x); 00092 double ceil(double x); 00093 00094 00095 #define log __ieee754_log 00096 #define log10 __ieee754_log10 00097 #define exp __ieee754_exp 00098 #define pow __ieee754_pow 00099 #define sqrt __ieee754_sqrt 00100 00101 #define asin __ieee754_asin //EDIT BY AL, 29th Oct 00102 #define acos __ieee754_acos 00103 #define atan2 __ieee754_atan2 00104 00105 #define log2(x) (log(x) / M_LOG2_E) 00106 #define _fabs(x) ( (x) < 0.0 ? (-x) : (x) ) 00107 00108 double fabs(double x); 00109 00110 #define M_E 2.7182818284590452354 00111 #define M_LOG2E 1.4426950408889634074 00112 #define M_LOG10E 0.43429448190325182765 00113 #define M_LN2 0.69314718055994530942 00114 #define M_LN10 2.30258509299404568402 00115 #define M_PI 3.14159265358979323846 00116 #define M_TWOPI (M_PI * 2.0) 00117 #define M_PI_2 1.57079632679489661923 00118 #define M_PI_4 0.78539816339744830962 00119 #define M_3PI_4 2.3561944901923448370E0 00120 #define M_SQRTPI 1.77245385090551602792981 00121 #define M_1_PI 0.31830988618379067154 00122 #define M_2_PI 0.63661977236758134308 00123 #define M_2_SQRTPI 1.12837916709551257390 00124 #define M_SQRT2 1.41421356237309504880 00125 #define M_SQRT1_2 0.70710678118654752440 00126 #define M_LN2LO 1.9082149292705877000E-10 00127 #define M_LN2HI 6.9314718036912381649E-1 00128 #define M_SQRT3 1.73205080756887719000 00129 #define M_IVLN10 0.43429448190325182765 /* 1 / log(10) */ 00130 #define M_LOG2_E 0.693147180559945309417 00131 #define M_INVLN2 1.4426950408889633870E0 /* 1 / log(2) */ 00132 00133 00134 00135 00155 double random(); // 53 bit pseudo RNG on [0,1) 00156 double gauss(); 00157 double normal(double mu, double sigma); 00158 00159 #define prob(p) ((p) >= 1.0 ? 1 : random() < (p)) 00160 00170 int qlog10(double x, double *y); 00171 00172 00173 00179 #define ilog10 qlog10 00180 00189 double dround(double value, int digits); 00190 00191 typedef double (*DFUNC1 ) (double); 00192 00193 // Numerical derivatives & root finding... 00194 00195 // Computes nth derivative for f(x) :: R->R 00196 double df(int n,DFUNC1 f, double x); 00197 00198 // Newtonean root iteration for monadic real functions R->R 00199 double newton(DFUNC1 f, double x0,double y); 00200 #define MATH_ERR_NEWTON_INVALID -999.666 00201 00202 #endif // USING_DECFLOAT 00203 #endif // _MATH_H 00204 00205