SINFONI Pipeline Reference Manual
2.5.2
sinfoni
sinfo_ipow.c
1
/*
2
* This file is part of the ESO SINFONI Pipeline
3
* Copyright (C) 2004,2005 European Southern Observatory
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18
*/
19
#ifdef HAVE_CONFIG_H
20
# include <config.h>
21
#endif
22
/*
23
* This function is so generic and used everywhere, it diserves its
24
* own source file...
25
*/
26
/*
27
$Id: sinfo_ipow.c,v 1.4 2012-03-02 08:42:20 amodigli Exp $
28
$Author: amodigli $
29
$Date: 2012-03-02 08:42:20 $
30
$Revision: 1.4 $
31
*/
53
#include "sinfo_ipow.h"
54
double
sinfo_ipow(
double
x,
int
p)
55
{
56
double
r, recip ;
57
58
/* Get rid of trivial cases */
59
switch
(p) {
60
case
0:
61
return
1.00 ;
62
63
case
1:
64
return
x ;
65
66
case
2:
67
return
x*x ;
68
69
case
3:
70
return
x*x*x ;
71
72
case
-1:
73
return
1.00 / x ;
74
75
case
-2:
76
return
(1.00 / x) * (1.00 / x) ;
77
}
78
if
(p>0) {
79
r = x ;
80
while
(--p) r *= x ;
81
}
else
{
82
r = recip = 1.00 / x ;
83
while
(++p) r *= recip ;
84
}
85
return
r;
86
}
87
88
Generated by
1.8.1.1