diogoalexandrefranco / cl-strings

A portable, dependency-free set of utilities to manipulate strings in Common Lisp
MIT License
46 stars 7 forks source link

Number Parsing #5

Closed sabracrolleton closed 7 years ago

sabracrolleton commented 7 years ago

First, thank you for the library. It means that I do not need to have both decimals and wu-decimal in the same package.

That said, two specific issues in parsing numbers.

  1. If the string is prepended by a positive sign, it throws an error (e.g. "+23243")
  2. The precision in format-number does not really work past the second decimal:

(cl-strings:format-number 212322.4473 :precision 4 :decimal-separator #. :order-separator #\,) "212,322.4500"

diogoalexandrefranco commented 7 years ago

Hello!

Thank you for contributing by filling up this issue.

  1. You are right, it's weird that I forgot this in the code and in all the tests. I have fixed it in the master branch and added a test for this case. The fix will be on quicklisp only when it updates all the libs (usually, once a month) but you can of course use the code from the master branch directly.
  2. This is awkward indeed, but I think it has to do with the way Common Lisp implementations handle big decimal numbers. Notice that if you simply evaluate 212322.4473 at the REPL, you get 212322.45 (the same is true for write-to-string). if you do cl-strings:format-number with 123.4471, you will get the result you expect. I'll look into this and learn if it is at all possible to do it better.
diogoalexandrefranco commented 7 years ago

Regarding the second point, it seems I can't do much from my side, since you're passing 212322.4473 which is likely a single-float in your CL implementation. It should work if you use 212322.4473d0, which usually represents a double-float.

sabracrolleton commented 7 years ago

Have now validated that the second point is not the fault of cl-strings. Something in my lisp image had changed. I restarted sbcl and it now works (I am usually running double-floats as defaults and did not catch that some other library was trying to change things.)

On Sat, Oct 8, 2016 at 1:40 PM, Diogo Franco notifications@github.com wrote:

Regarding the second point, it seems I can't do much from my side, since you're passing 212322.4473 which is likely a single-float in your implementation. It might work if use 212322.4473d0, which usually represents a double-float.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/diogoalexandrefranco/cl-strings/issues/5#issuecomment-252447180, or mute the thread https://github.com/notifications/unsubscribe-auth/AE1dLW5cktRmJDsxOSBwLUYYaFI__r-Wks5qx_-0gaJpZM4KRyOY .

diogoalexandrefranco commented 7 years ago

Awesome. I'll close this issue, thanks for the report!