Raymond Toy pushed to branch issue-274-make-float-of-huge-numbers at cmucl / cmucl
Commits: ab7f4ce8 by Raymond Toy at 2024-03-10T12:52:20-07:00 Use builtin constants to get the range of valid exponents.
Instead of hard-wiring the min and max exponents, use `vm:single-float-normal-expenent-min`, and `vm:single-float-normal-exponent-max` to get the exponents. These need to be adjusted by `vm:single-float-bias` and `vm:single-float-digits` as appropriate to go the actual signed exponents ranges. We use analogous values for double-floats.
- - - - -
1 changed file:
- src/code/reader.lisp
Changes:
===================================== src/code/reader.lisp ===================================== @@ -1845,12 +1845,22 @@ the end of the stream." (multiple-value-bind (log2-low log2-high) (ecase float-format ((short-float single-float) - ;; Single-float exponents range is -149 to 127 - (values (* 2 -149) (* 2 127))) + ;; Single-float exponents range is -149 to 127, but we + ;; don't need to be super-accurate since we're + ;; multiplying the values by 2. + (values (* 2 (- vm:single-float-normal-exponent-min + vm:single-float-bias + vm:single-float-digits)) + (* 2 (- vm:single-float-normal-exponent-max + vm:single-float-bias)))) ((double-float long-float #+double-double kernel:double-double-float) - ;; Double-float exponent range is -1074 to -1023 - (values (* 2 -1074) (* 2 1023)))) + (values (* 2 (- vm:double-float-normal-exponent-min + vm:double-float-bias + vm:double-float-digits)) + (* 2 (- vm:double-float-normal-exponent-max + vm:double-float-bias))))) + ;; Double-float exponent range is -1074 to -1023 (unless (< log2-low log2-num log2-high) ;; The number is definitely too large or too small to fit. ;; Signal an error.
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/ab7f4ce8c13a35a79f463d53...