From 9fc3c369e0de14c7a8df081ec35f9283088e6891 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 28 Mar 2022 15:00:34 -0400 Subject: modernize bigtodbl() --- big.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'big.c') 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; { -- cgit v1.2.1