hpmath.h

Go to the documentation of this file.
00001 //& ****************************************************************************
00002 //&
00003 //& Written by Ingo Blank, August 2004
00004 //& Donated to the HP-GCC Development Team
00005 //& Copyright (C) 2004 The HP-GCC Development Team
00006 //&
00007 //& ****************************************************************************
00008 //&
00009 //&
00010 //& This file is part of HP-GCC.
00011 //&
00012 //& HP-GCC is free software; you can redistribute it and/or modify
00013 //& it under the terms of the GNU General Public License as published by
00014 //& the Free Software Foundation; either version 2, or (at your option)
00015 //& any later version.
00016 //& 
00017 //& HP-GCC is distributed in the hope that it will be useful,
00018 //& but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //& GNU General Public License for more details.
00021 //& 
00022 //& You should have received a copy of the GNU General Public License
00023 //& along with HP-GCC; see the file COPYING. 
00024 //&
00025 //& As a special exception, you may use this file as part of a free software
00026 //& library without restriction.  Specifically, if other files instantiate
00027 //& templates or use macros or inline functions from this file, or you compile
00028 //& this file and link it with other files to produce an executable, this
00029 //& file does not by itself cause the resulting executable to be covered by
00030 //& the GNU General Public License.  This exception does not however
00031 //& invalidate any other reasons why the executable file might be covered by
00032 //& the GNU General Public License.
00033 //&
00034 //& ****************************************************************************
00035 
00036 
00037 #ifndef _HPMATH_H
00038 #define _HPMATH_H
00039 
00040 
00041 // LONG TYPE DEFINITION, ADDED BY CLAUDIO 01/14/05
00042 #ifndef _LONGLONG_DEF
00043 typedef unsigned long long ULONGLONG;
00044 typedef long long LONGLONG;
00045 #define _LONGLONG_DEF
00046 #endif
00047 
00048 
00059 #ifndef min
00060 #define min(a,b) ((a) < (b) ? (a) : (b))
00061 #endif
00062 
00063 #ifndef max
00064 #define max(a,b) ((a) > (b) ? (a) : (b))
00065 #endif
00066 
00067 #ifndef abs
00068 #define abs(a) ((a) < 0 ? (-a) : (a))
00069 #endif
00070 
00071 
00072 
00073 double ipow(double x,  int n);
00074 // NEW 10^X ALGORITHM BY CLAUDIO
00075 double i10powx(int n);
00076 // INTERNAL FUNCTIONS
00077 // CREATE A DOUBLE FROM A 64-BIT MANTISSA AND AN EXPONENT
00078 double assemble_double(unsigned int sign,unsigned long long mantissa,int exponent);
00079 // CALCULATE 10^X WITH 64-BIT PRECISION
00080 // RETURN A BASE-2 EXPONENT + A 64-BIT MANTISSA
00081 // MORE ACCURATE THAN STANDARD POW AND IPOW
00082 int _i10pow64(int exp10,unsigned long long *mant);
00083 
00084 
00085 
00086 double square(double x);
00087 double round(double a);
00088 
00089 
00090 
00091 // libm
00092 
00093 double modf(double x, double *iptr);
00094 double frexp(double x, int *exp);
00095 double scalbn (double x, int n);
00096 double copysign(double x, double y);
00097 
00098 double __ieee754_log(double x);
00099 double __ieee754_log10(double x);
00100 double __ieee754_exp(double x);
00101 double __ieee754_pow(double x, double y);
00102 double __ieee754_sqrt(double x);
00103 
00104 double __ieee754_asin(double x); //EDIT BY AL, 29th Oct
00105 double __ieee754_acos(double x);
00106 double __ieee754_atan2(double y, double x);
00107 
00108 double sin(double x);
00109 double cos(double x);
00110 double tan(double x);
00111 
00112 double atan(double x); //EDIT BY AL, 29th Oct
00113 
00114 double floor(double x);
00115 double ceil(double x);
00116 
00117 
00118 #define log     __ieee754_log
00119 #define log10     __ieee754_log10
00120 #define exp     __ieee754_exp
00121 #define pow     __ieee754_pow
00122 #define sqrt    __ieee754_sqrt
00123 
00124 #define asin     __ieee754_asin //EDIT BY AL, 29th Oct
00125 #define acos    __ieee754_acos
00126 #define atan2    __ieee754_atan2
00127 
00128 #define log2(x) (log(x) / M_LOG2_E)
00129 #define _fabs(x) ( (x) < 0.0 ? (-x) : (x) )
00130 
00131 double fabs(double x);
00132 
00133 #define M_E        2.7182818284590452354
00134 #define M_LOG2E        1.4426950408889634074
00135 #define M_LOG10E    0.43429448190325182765
00136 #define M_LN2        0.69314718055994530942
00137 #define M_LN10        2.30258509299404568402
00138 #define M_PI        3.14159265358979323846
00139 #define M_TWOPI        (M_PI * 2.0)
00140 #define M_PI_2        1.57079632679489661923
00141 #define M_PI_4        0.78539816339744830962
00142 #define M_3PI_4        2.3561944901923448370E0
00143 #define M_SQRTPI    1.77245385090551602792981
00144 #define M_1_PI        0.31830988618379067154
00145 #define M_2_PI        0.63661977236758134308
00146 #define M_2_SQRTPI    1.12837916709551257390
00147 #define M_SQRT2        1.41421356237309504880
00148 #define M_SQRT1_2    0.70710678118654752440
00149 #define M_LN2LO        1.9082149292705877000E-10
00150 #define M_LN2HI        6.9314718036912381649E-1
00151 #define M_SQRT3        1.73205080756887719000
00152 #define M_IVLN10    0.43429448190325182765 /* 1 / log(10) */
00153 #define M_LOG2_E    0.693147180559945309417
00154 #define M_INVLN2    1.4426950408889633870E0  /* 1 / log(2) */
00155 
00156 
00157 
00158 
00178 double    random(); // 53 bit pseudo RNG on [0,1)
00179 double     gauss();
00180 double     normal(double mu, double sigma);
00181 
00182 #define prob(p) ((p) >= 1.0 ? 1 : random() < (p))
00183 
00193 int qlog10(double x, double *y);
00194 
00195 
00196 
00202 #define ilog10 qlog10
00203 
00212 double dround(double value, int digits);
00213 
00214 typedef double (*DFUNC1 ) (double);
00215 
00216 // Numerical derivatives & root finding...
00217 
00218 // Computes nth derivative for f(x) :: R->R
00219 double df(int n,DFUNC1 f, double x);
00220 
00221 // Newtonean root iteration for monadic real functions R->R
00222 double newton(DFUNC1 f, double x0,double y);
00223 #define MATH_ERR_NEWTON_INVALID -999.666
00224 
00225 #endif // _MATH_H
00226 
00227 

Generated on Sat Feb 17 00:05:26 2007 for HP-GCCLibrary by  doxygen 1.5.0