File: real.C

package info (click to toggle)
xjig 2.4-5.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 408 kB
  • ctags: 1,155
  • sloc: cpp: 4,534; makefile: 735; sh: 14; perl: 5
file content (52 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#ifndef _global_h
#	include "global.h"
#endif
#ifndef _real_h
#	include "real.h"
#endif

#ifndef RealZero
const Real RealZero = 0.0;
#endif


FunTab::FunTab( double (*fkt) (double), double from_in, double to_in, int step_in ) {

	from		= from_in;
	to   		= to_in;
	step		= step_in;
	interval = (to-from)/Real((double)step);

	val = new Real [step+1];

	for (int i=0;i<=step;i++) {
		val[i] = fkt( from+interval*(double)i );
	}
}


FunTab::~FunTab() {
	if (val)		delete [] val;
}

const Real &FunTab::GetVal( const Real &in ) const  {
	double	m = fmod( in, 2.0*M_PI );
	while( m<0 )	m+= M_PI*2.0;
	int ind = (int)((m-from)/interval+0.5);
	return val[ind];
}

Real FunTab::GetRezVal( const Real &in ) const {
int	hi = step;
int	lo = 0;

int	mid = (hi+lo)/2;

	while( mid!=lo ) {
		if (val[mid]>in)	hi=mid;
		else					lo=mid;
		mid = (hi+lo)/2;
	}
	return (double)mid*interval+from;
}