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

issue with reading JSON floats. #14

Open
jsulmont opened this issue May 7, 2023 · 5 comments
Open

issue with reading JSON floats. #14

jsulmont opened this issue May 7, 2023 · 5 comments

Comments

@jsulmont
Copy link

jsulmont commented May 7, 2023

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

@hxzrx
Copy link

hxzrx commented Apr 15, 2024

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

@yitzchak
Copy link
Owner

yitzchak commented Jul 2, 2024

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.

@hxzrx
Copy link

hxzrx commented Jul 9, 2024

That works, thanks!

@sabracrolleton
Copy link

@yitzchak Do you have any suggested reading beyond the classic What Every Computer Scientist Should Know About Floating-Point Arithmetic?

@yitzchak
Copy link
Owner

yitzchak commented Jul 10, 2024

@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.

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

4 participants