diff options
-rw-r--r-- | big.c | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -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 |