Skip to content
Snippets Groups Projects
Commit 1031c478 authored by rtoy's avatar rtoy
Browse files

Some fixes for floating-point printing bugs reported by Bruno Haible,

cmucl-imp, on or around 2005/06/13.

Some useful tests:

(format nil "~9,3,2,0,'%G" 0.0314159)
Expected: "0.314e-01"


(format nil "~9,3,2,-2,'%@e" 3.14159)
Expected: "+.003E+03"


(format nil "~6,2,1,'*F" 3.14159)
Expected: " 31.42"

(format nil "~9,0,6f" 3.14159)
Expected: " 3141590."

(let (x)
 (dotimes (k 13 x)
  (setq x (cons (format nil "~%Scale factor ~2D: |~13,6,2,VE|"
          (- k 5) (- k 5) 3.14159) x))))

("
Scale factor  7: | 3141590.e-06|"
 "
Scale factor  6: | 314159.0e-05|"
 "
Scale factor  5: | 31415.90e-04|"
 "
Scale factor  4: | 3141.590e-03|"
 "
Scale factor  3: | 314.1590e-02|"
 "
Scale factor  2: | 31.41590e-01|"
 "
Scale factor  1: | 3.141590e+00|"
 "
Scale factor  0: | 0.314159e+01|"
 "
Scale factor -1: | 0.031416e+02|"
 "
Scale factor -2: | 0.003142e+03|"
 "
Scale factor -3: | 0.000314e+04|"
 "
Scale factor -4: | 0.000031e+05|"
 "
Scale factor -5: | 0.000003e+06|")


code/format.lisp:
o If the scale factor (k) is negative, the min number of digits to
  print is 1, not (- 1 k) because that prints too many if the field is
  too short.  Setting fmin to fdig is ok if k >= 0.  (See scale factor
  test above.)
o If flonum-to-string returns with a trailing decimal point, we don't
  need to decrement spaceleft because that deletes a white-space
  character.  (See first scale factor 7 test above.)

code/print.lisp:
o We need to adjust the number of digits to be printed to include the
  scale factor.  See tests above.
parent c231fb42
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment