jscl
jscl copied to clipboard
Floats converted into ints during reading
Floats ending in .0
get read in as ints:
CL-USER> (read-from-string "1.0")
1
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?
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?
Nevermind that last question, I see that the library does that itself anyway. Even better!
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.
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?