Clojure

cl-format prints ratio arguments with bad format for E, F, G directives

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Completed
  • Affects Version/s: Release 1.3, Release 1.4
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

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 a clojure.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

Activity

Andy Fingerhut made changes -
Field Original Value New Value
Affects Version/s Release 1.2 [ 10037 ]
Affects Version/s Release 1.4 [ 10040 ]
Hide
Tom Faulhaber added a comment -

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!)

Show
Tom Faulhaber added a comment - 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!)
Rich Hickey made changes -
Fix Version/s Release 1.5 [ 10150 ]
Stuart Halloway made changes -
Fix Version/s Release 1.5 [ 10150 ]
Fix Version/s Release 1.6 [ 10157 ]
Hide
Andy Fingerhut added a comment -

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.

Show
Andy Fingerhut added a comment - 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.
Andy Fingerhut made changes -
Attachment clj-937-cl-format-coerces-ratios-patch2.txt [ 11949 ]
Alex Miller made changes -
Approval Vetted [ 10003 ]
Alex Miller made changes -
Description 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. "

Patch changes cl-format so that when E, F, or G directive is used, the corresponding arg is coerced from a clojure.lang.Ratio to a double before formatting.
{{code}}
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. "
{{code}}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.lang.Ratio}} to a double before formatting.

*Patch:* {{clj-937-cl-format-coerces-ratios-patch2.txt}}
Alex Miller made changes -
Description {{code}}
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. "
{{code}}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.lang.Ratio}} to a double before formatting.

*Patch:* {{clj-937-cl-format-coerces-ratios-patch2.txt}}
{code}
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. "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.lang.Ratio}} to a double before formatting.

*Patch:* {{clj-937-cl-format-coerces-ratios-patch2.txt}}
Andy Fingerhut made changes -
Description {code}
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. "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.lang.Ratio}} to a double before formatting.

*Patch:* {{clj-937-cl-format-coerces-ratios-patch2.txt}}
{code}
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. "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.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.txt}}
Alex Miller made changes -
Labels print
Hide
Andy Fingerhut added a comment -

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.

Show
Andy Fingerhut added a comment - 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 made changes -
Andy Fingerhut made changes -
Attachment clj-937-cl-format-coerces-ratios-patch2.txt [ 11949 ]
Alex Miller made changes -
Priority Minor [ 4 ] Trivial [ 5 ]
Alex Miller made changes -
Description {code}
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. "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.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.txt}}
*Before:*

{code}
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. "
{code}

*After:*
{code}
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 "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.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.txt}}
Alex Miller made changes -
Description *Before:*

{code}
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. "
{code}

*After:*
{code}
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 "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.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.txt}}
*Before:*

{code}
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. "
{code}

*After:*
{code}
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 "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.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.txt}}

*Screened by:* Alex Miller
Alex Miller made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Alex Miller made changes -
Description *Before:*

{code}
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. "
{code}

*After:*
{code}
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 "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.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.txt}}

*Screened by:* Alex Miller
*Before:*

{code}
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. "
{code}

*After:*
{code}
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 "
{code}

*Approach:* Patch changes {{cl-format}} so that when E, F, or G directive is used, the corresponding arg is coerced from a {{clojure.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
Attachment clj-937-cl-format-coerces-ratios-patch2.diff [ 12370 ]
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: