jscl icon indicating copy to clipboard operation
jscl copied to clipboard

Floats converted into ints during reading

Open orodley opened this issue 11 years ago • 5 comments

Floats ending in .0 get read in as ints:

CL-USER> (read-from-string "1.0")
1

orodley avatar May 18 '13 22:05 orodley

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?

davazp avatar May 18 '13 23:05 davazp

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 avatar May 18 '13 23:05 orodley

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

orodley avatar May 18 '13 23:05 orodley

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.

davazp avatar May 19 '13 00:05 davazp

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?

orodley avatar May 19 '13 00:05 orodley