cl-format prints ratio arguments with bad format for E, F, G directives
Description
Environment
Attachments
- 22 Oct 2013, 03:16 PM
- 03 Sep 2013, 07:57 PM
- 22 Feb 2012, 02:38 AM
Activity
Andy Fingerhut September 3, 2013 at 7:57 PM
Replace patch clj-937-cl-format-coerces-ratios-patch2.txt with another one of the same name. The only change is to eliminate trailing whitespace from some of the lines added by the patch, which eliminates the warnings that occur when git is used to apply the patch.
Andy Fingerhut April 8, 2013 at 6:02 PM
Patch clj-937-cl-format-coerces-ratios-patch2.txt dated Apr 8 2013 supersedes the previous patch cl-format-efg-coerce-ratios-to-doubes-patch1.txt dated Feb 21 2013.
The newer patch works with ratios that cannot be represented as a double, using BigDecimal in those cases. The older patch would print garbage from the string "Infinity" if the ratios were larger than Double/MAX_VALUE, or 0 if the ratio was between 0 and Double/MIN_VALUE.
Tom Faulhaber March 30, 2012 at 2:48 AM
I have reviewed this patch and recommend that it be applied.
(This one has actually been on my to do list for about 4 years. Thanks, Andy!)
Before:
user=> (use 'clojure.pprint) nil user=> (cl-format false "~e" 4/5) "4./5E+2" user=> (cl-format false "~f" 4/5) "4/5.0" user=> (cl-format false "~g" 4/5) "4/5. "
After:
user=> (cl-format false "~10,3f" 4/5) " 0.800" user=> (cl-format false "~e" 4/5) "8.0E-1" user=> (cl-format false "~f" 4/5) "0.8" user=> (cl-format false "~g" 4/5) "0.8 "
Approach: Patch changes
cl-format
so that when E, F, or G directive is used, the corresponding arg is coerced from aclojure.lang.Ratio
to a double before formatting, if it fits in a double, otherwise a BigDecimal if the extra precision is needed.Patch: clj-937-cl-format-coerces-ratios-patch2.diff
Screened by: Alex Miller