yitzchak/shasht

issue with reading JSON floats.

Opened this issue · 5 comments

Thanks for that neat lib!!

read-json-number seems to behave incorrectly:

(let ((cl:*read-default-float-format* 'double-float))
  (shasht:read-json "-3.14159"))

returns:

-3.1415900000000003d0

when

(let ((cl:*read-default-float-format* 'long-float))
  (read-from-string "-3.14159"))

returns:

-3.14159d0, 8

Am I missing anything here?

Thanks

Also:
(shasht:write-json 14.0d0 nil)
returns:
"1.3999999999999999e1"

Reading and printing floats correctly, let alone quickly, is highly non-trivial. Currently, shasht delegates printing to CL:FORMAT with an attempt to cleanup the output a bit. For parsing it uses the CL implementation's coerce. To avoid some of the issues with both aspects we are working on a new Lisp system, Quaviver, which handles the difficult part of reading and printing, i.e base 10 conversion with some more modern algorithms then Burger-Dybvig, etc.

I've added a preliminary testing branch "quaviver" that uses these algorithms and it appears to pass the test cases given so far in this issue.

That works, thanks!

@sabracrolleton I don't have any suggested reading for generic floating point operations/concerns yet. We do have some references for some of the stuff we are working on for Quaviver https://github.com/s-expressionists/Quaviver/wiki/References

Its not organized at all yet. If you have anything you think is worth adding please feel free to.