Skip to content

Commit

Permalink
Changed operations order in make-float/frac
Browse files Browse the repository at this point in the history
Now it won't result in an overflow for numbers with big exponent.
  • Loading branch information
filipjsowa authored and sionescu committed Feb 28, 2024
1 parent 936444a commit 7ce13ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions parse-number.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@
(let* ((base (base-for-exponent-marker exp-marker))
(exp (expt base (number-value exp-place))))
(+ (* exp (number-value whole-place))
(/ (* exp (number-value frac-place))
(* exp (/ (number-value frac-place)
(expt (float radix base)
(places frac-place))))))
(places frac-place)))))))

(defun make-float/whole (exp-marker whole-place exp-place)
"Create a float where EXP-MARKER is the exponent-marker and the
Expand Down
5 changes: 3 additions & 2 deletions tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
(in-package #:org.mapcar.parse-number-tests)

(defparameter *test-values*
'("1" "-1" "1034" "3." "-3." "-364" "80/335" "1.3214" "3.5333" "2.4E4" "6.8d3" "#xFF"
`("1" "-1" "1034" "3." "-3." "-364" "80/335" "1.3214" "3.5333" "2.4E4" "6.8d3" "#xFF"
"#b-1000" "#o-101/75" "13.09s3" "35.66l5" "21.4f2" "#C(1 2)"
"#c ( #xF #o-1 ) " "#c(1d1 2s1)" "#16rFF" "#9r10" "#C(#9r44/61 4f4)"
"2.56 " "+1" "+1." "+1.4" "+.14" "+0.14" " -4.312")
"2.56 " "+1" "+1." "+1.4" "+.14" "+0.14" " -4.312"
,(write-to-string least-positive-single-float) ,(write-to-string most-positive-single-float))
"These are the values that are going to be tested.")

(defparameter *expected-failures* ()
Expand Down

0 comments on commit 7ce13ba

Please sign in to comment.