-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.c
43 lines (34 loc) · 1.45 KB
/
common.c
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
/*
freesteam - IAPWS-IF97 steam tables library
Copyright (C) 2004-2005 John Pye
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define FREESTEAM_BUILDING_LIB
#include "common.h"
/* ipow: public domain by Mark Stephen with suggestions by Keiichi Nakasato */
MyDouble ipow(MyDouble x, int n){
MyDouble t = 1.0;
if(!n)return 1.0; /* At the top. x^0 = 1 */
if (n < 0){
n = -n;
x = 1.0/x; /* error if x == 0. Good */
} /* ZTC/SC returns inf, which is even better */
if (x == 0.0)return 0.0;
do{
if(n & 1)t *= x;
n /= 2; /* KN prefers if (n/=2) x*=x; This avoids an */
x *= x; /* unnecessary but benign multiplication on */
}while(n); /* the last pass, but the comparison is always
true _except_ on the last pass. */
return t;
}