With GCL we do not get overflow errors when converting bigfloat numbers into float numbers which are obviously too big to fit in a float number:
This is a correct example:
(%i11) float(gamma(150b0));
(%o11) 3.8089226376305632E+260
The following bigfloat numbers are too big. The result is unpredicable and wrong:
(%i12) float(gamma(250b0));
(%o12) 4.0014303970800103E-127
(%i13) float(gamma(2500b0));
(%o13) 5.0208574388889818E+9
I have observed this for GCL 2.6.8. CLISP 2.44 gives an overflow error.
The problem is the Lisp function scale-float which is called by fp2flo in the file float.lisp.
Dieter Kaiser
Raymond Toy
2008-11-26
Here is a replacement. It explicitly checks for overflow and signals it. An overflow happens if the exponent is larger than 1024, the largest double-float exponent.
(defmfun fp2flo (l)
(let ((precision (caddar l))
(mantissa (cadr l))
(exponent (caddr l))
(fpprec machine-mantissa-precision)
(*m 0))
(setq mantissa (quotient (fpround mantissa) (expt 2.0 machine-mantissa-precision)))
(let ((e (+ exponent (- precision) *m machine-mantissa-precision)))
(if (>= (abs e) 1025)
(merror "Floating point overflow in converting ~:M to flonum" l)
(scale-float mantissa e)))))
Raymond Toy
2008-12-01
Fixed as suggested in float.lisp, rev 1.45. Tests added to rtest16.mac, rev 1.58.
Raymond Toy
2008-12-01