File: cdsMath.cc

package info (click to toggle)
toshset 1.73-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 484 kB
  • ctags: 572
  • sloc: sh: 3,589; cpp: 2,938; ansic: 1,057; makefile: 190
file content (36 lines) | stat: -rw-r--r-- 699 bytes parent folder | download | duplicates (4)
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

//#include <sthead.hh>
#include <cdsMath.hh>
#include <cstdlib> // for std::abs

namespace CDS {

//realtype ipow(const realtype &x,
//		      int       i)
///* return the ith integer power of x
//   7/12/93 - now works for negative integers too*/
//{
// realtype temp = 1;
// for (int cnt=0 ; cnt<abs(i) ; cnt++) temp *= x;
//
// if (i<0 && temp != 0.0) temp = 1.0 / temp;
//
// return temp;
//} /*ipow*/


template<class T> T 
ipow(const T&  x,
	   int i)
/* return the ith integer power of x
   - works for negative integers too*/
{
 T temp = 1;
 for (int cnt=0 ; cnt<std::abs(i) ; cnt++) temp *= x;

 if (i<0 && temp != 0.0) temp = 1.0 / temp;

 return temp;
} /* pow */

} /* namespace CDS */