Skip to content

Floats converted into ints during reading #104

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

Open
orodley opened this issue May 18, 2013 · 5 comments
Open

Floats converted into ints during reading #104

orodley opened this issue May 18, 2013 · 5 comments

Comments

@orodley
Copy link
Contributor

orodley commented May 18, 2013

Floats ending in .0 get read in as ints:

CL-USER> (read-from-string "1.0")
1
@davazp
Copy link
Member

davazp commented May 18, 2013

I suppose it is not converted to integer. Is `ls-read-from-string' working in the host? The issue is that in Javascript every number is a float. So we do not difference between 1.0 and 1. An integer is just a float point with no fractional part.

Any idea about how to solve this? We have to implement bignums yet. Perhaps this library https://github.com/jtobey/javascript-bignum would solve both problems?

@orodley
Copy link
Contributor Author

orodley commented May 18, 2013

Ah, okay. I wasn't aware of that detail of javascript. That library does look like a good solution. I'll try to integrate it on my fork and see how it goes. At the very least it will help us out with rationals and bignums, even if it doesn't deal with this problem.

Do you think there would be performance implications in using this for all numbers? Should we keep using the primitive type for fixnums (maybe with some kind of boxing to distinguish them from floats?) and transparently convert when they would overflow to avoid the overhead when it is unnecessary?

@orodley
Copy link
Contributor Author

orodley commented May 18, 2013

Nevermind that last question, I see that the library does that itself anyway. Even better!

@davazp
Copy link
Member

davazp commented May 19, 2013

Sure. However the problem still remains. How to force the disjointness of rational and float (and so integer and float)?
As the library uses primitive numbers for exact integers in a small range, I suppose it does not distinguish them either.

@orodley
Copy link
Contributor Author

orodley commented May 19, 2013

I haven't delved too deep into the library yet, but it looks like it has functions like isInteger, isFloat, isRational, etc. Is this what you mean?

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

No branches or pull requests

2 participants