summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-28 15:02:07 -0400
committerJakob Kaivo <jkk@ung.org>2022-03-28 15:02:07 -0400
commit4a9e7da4421619ed7a0ab9a02d808b77df93e867 (patch)
treed339d146424db097b65781899420b0265c0600e7
parent9fc3c369e0de14c7a8df081ec35f9283088e6891 (diff)
modernize dbltobig()
-rw-r--r--big.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/big.c b/big.c
index 1c7aac3..1e4eb33 100644
--- a/big.c
+++ b/big.c
@@ -638,26 +638,31 @@ double bigtodbl(word x)
/* note: can return oo, -oo
but is used without surrounding sto_/set)dbl() only in compare() */
-word dbltobig(x) /* entier */
-double x;
+/* entier */
+word dbltobig(double x)
{
word s = (x < 0);
word r = make(INT, 0, 0);
word *p = &r;
double y = floor(x);
-/*if(fabs(y-x+1.0)<1e-9)y += 1.0; /* trick due to Peter Bartke, see note */
+
for (y = fabs(y);;) {
double n = fmod(y, (double)IBASE);
digit(*p) = (word) n;
y = (y - n) / (double)IBASE;
- if (y > 0.0)
- rest(*p) = make(INT, 0, 0), p = &rest(*p);
- else
+ if (y > 0.0) {
+ rest(*p) = make(INT, 0, 0);
+ p = &rest(*p);
+ } else {
break;
+ }
}
- if (s)
+
+ if (s) {
digit(r) = SIGNBIT | digit(r);
- return (r);
+ }
+
+ return r;
}
/* produces junk in low order digits if x exceeds range in which integer