summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-28 15:00:34 -0400
committerJakob Kaivo <jkk@ung.org>2022-03-28 15:00:34 -0400
commit9fc3c369e0de14c7a8df081ec35f9283088e6891 (patch)
treebd885c0f4e043d9566958b0448640e800fca5e1e
parentf9a8d0b1205d3772d27c0e8e8a8dccda2f3c66ca (diff)
modernize bigtodbl()
-rw-r--r--big.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/big.c b/big.c
index 8fba599..1c7aac3 100644
--- a/big.c
+++ b/big.c
@@ -620,34 +620,24 @@ word bigpow(word x, word y)
return r;
}
-double bigtodbl(x)
-word x;
+double bigtodbl(word x)
{
word s = big_is_negative(x);
- double b = 1.0, r = (double)digit0(x);
+ double b = 1.0;
+ double r = (double)digit0(x);
x = rest(x);
- while (x)
- b = b * IBASE, r = r + b * digit(x), x = rest(x);
- if (s)
- return (-r);
- return (r);
+ while (x) {
+ b = b * IBASE;
+ r = r + b * digit(x);
+ x = rest(x);
+ }
+
+ return s ? -r : r;
} /* small end first */
/* note: can return oo, -oo
but is used without surrounding sto_/set)dbl() only in compare() */
-/* not currently used
-long double bigtoldbl(x)
-word x;
-{ int s=big_is_negative(x);
- long double b=1.0L, r=digit0(x);
- x = rest(x);
- while(x)b=b*IBASE,r=r+b*digit(x),x=rest(x);
-/*printf("bigtoldbl returns %Le\n",s?-r:r); /* DEBUG
- if(s)return(-r);
- return(r);
-} /* not compatible with std=c90, lib fns eg sqrtl broken */
-
word dbltobig(x) /* entier */
double x;
{