source: Sophya/trunk/SophyaLib/NTools/tabmath.h@ 4030

Last change on this file since 4030 was 1371, checked in by ansari, 25 years ago

MAJ documentation, Makefile, ... - Reza 5/1/2001

File size: 1.3 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// Tabulated math functions
3// E. Aubourg, C. Magneville 1996-2000
4// DAPNIA/SPP (Saclay) / CEA LAL - IN2P3/CNRS (Orsay)
5
6#ifndef TABMATH_H_SEEN
7#define TABMATH_H_SEEN
8
9#include <math.h>
10#include "peida.h"
11#include "nbconst.h"
12
13namespace SOPHYA {
14
15///////////////////////////////
16// Exponentielles tabulees //
17///////////////////////////////
18
19class TabFExp {
20public:
21 TabFExp();
22 ~TabFExp();
23 inline double operator()(double x)
24 { if (x > 0) return exp(x);
25 if (x <= -10) return 0;
26 return tab[int(-x*1000)];
27 }
28private:
29 double* tab;
30};
31
32extern TabFExp* ptabFExp;
33#define tabFExp(_x_) ((*ptabFExp)(_x_))
34
35
36////////////////////////////////////
37// Sinus tabules (et Cosinus) //
38////////////////////////////////////
39
40class TabFSin {
41public:
42 TabFSin(int ntab = 0);
43 ~TabFSin();
44 inline double operator()(double x)
45 {
46 double s = 1.;
47 if(x<0.) {x *=-1.; s = -1.;}
48 x -= DeuxPi * int(x/DeuxPi);
49 if(x>Pi) {x -= Pi; s *= -1.;}
50 if(x>Pi/2.) x = Pi-x;
51 return s * tab[int(x/delta)];
52 }
53private:
54 int ntab;
55 double delta;
56 double* tab;
57};
58
59extern TabFSin* ptabFSin;
60#define tabFSin(_x_) ((*ptabFSin)(_x_))
61#define tabFCos(_x_) ((*ptabFSin)(_x_+Pis2))
62
63} // namespace SOPHYA
64
65#endif
Note: See TracBrowser for help on using the repository browser.