From 7dfcc480ba1e19bd3232349fc733caef94034292 Mon Sep 17 00:00:00 2001 From: stainer_t Date: Mon, 8 Sep 2025 13:48:49 +0200 Subject: Initial commit from Polytechnique Montreal --- Utilib/src/common.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Utilib/src/common.c (limited to 'Utilib/src/common.c') diff --git a/Utilib/src/common.c b/Utilib/src/common.c new file mode 100644 index 0000000..80ae291 --- /dev/null +++ b/Utilib/src/common.c @@ -0,0 +1,25 @@ +#define FREESTEAM_BUILDING_LIB +#include "common.h" + +/* ipow: public domain by Mark Stephen with suggestions by Keiichi Nakasato */ +double ipow(double x, int n){ + double 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; +} -- cgit v1.2.3