Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Format function's F directive's k parameter fails when preceded only by a tilde and 2 commas #53

Closed
ninejaguar opened this issue Feb 17, 2019 · 2 comments

Comments

@ninejaguar
Copy link

ninejaguar commented Feb 17, 2019

Environment:
Corman Common Lisp 3.1 (Patch level 2) under Windows 10 64bit

Issue:
The Format function's F directive's k parameter fails to move the decimal point of the floating point argument to the right when preceded by a tilde and 2 consecutive commas. This fails in Corman CL, but works in SBCL 1.4.14 64bit and in Clisp 2.49 when tested.

Corman CL Example1: Note the issue is that 0.1 is returned rather than 10.0

(format t "10 Percent ~,,2f ~%" .10)
10 Percent 0.1 
NIL

SBCL Example1: SBCL produces the correct result, just as Clisp does.

* (format t "10 Percent ~,,2f ~%" .10)
10 Percent 10.0
NIL

Other Format F directive k parameter scenarios seem to work fine for Corman CL...

Corman CL Example2: Corman CL correctly produces the same result as SBCL if a 0 or 1 is entered for the d parameter (decimal digits) between the two commas before the k parameter.

(format t "10 Percent ~,1,2f ~%" .10)
10 Percent 10.0 
NIL

(format t "10 Percent ~,0,2f ~%" .10)
10 Percent 10. 
NIL

SBCL Example2: The same correct results as Clisp and Corman CL.

* (format t "10 Percent ~,1,2f ~%" .10)
10 Percent 10.0
NIL

* (format t "10 Percent ~,0,2f ~%" .10)
10 Percent 10.
NIL

Reference:

  1. This is the same issue found and fixed in Clozure Common Lisp. This is an oddly obscure bug to coincidentally share with another Common Lisp implementation. Perhaps the solution used to fix Clozure CL can also be used for Corman CL? Do the two Common Lisp implementations already share some code? If yes, can additional Clozure CL code be used to fix other/future Corman CL issues as they're found? See the following closed Clozure CL issue:
    The Format function's F directive's k parameter fails when preceded by a tilde and 2 commas
    The Format function's F directive's k parameter fails when preceded by a tilde and 2 commas Clozure/ccl#51

  2. CLHS: 22.3.3.1 Tilde F: Fixed-Format Floating-Point.
    "The full form is ~w,d,k,overflowchar,padcharF. The parameter w is the width of the field to be printed; d is the number of digits to print after the decimal point; k is a scale factor that defaults to zero."
    http://www.lispworks.com/documentation/HyperSpec/Body/22_cca.htm

@ninejaguar ninejaguar changed the title The Format function's F directive's k parameter fails when preceded by a tilde and 2 commas The Format function's F directive's k parameter fails when preceded only by a tilde and 2 commas Feb 17, 2019
@arbv arbv closed this as completed in 38864f8 Feb 19, 2019
@arbv
Copy link
Member

arbv commented Feb 19, 2019

@ninejaguar

Thank you for reporting the bug as well as referencing the solution!

@ninejaguar
Copy link
Author

The first form shows that the solution works! And, the following forms work as expected without issue. Thank you!

(format t "10 Percent ~,,2f ~%" .10)
10 Percent 10.0 
Nil
(format t "10 Percent ~,1,2f ~%" .10)
10 Percent 10.0 
Nil
(format t "10 Percent ~,0,2f ~%" .10)
10 Percent 10. 
Nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants