Numbers in Kawa
Helmut Eller
eller.helmut@gmail.com
Sun Apr 29 07:40:00 GMT 2012
* Jamison Hope [2012-04-27 21:05] writes:
>> I'd expect a compile time warning and an error at runtime. Automagic
>> coercion from float to int surprises me. E.g. (string-ref "abc" 0.6)
>> should be an error instead of returning #\a or #\b.
>
> That does seem erroneous. I feel like (string-ref "abc" 1.0) should
> work, though [with a warning], so perhaps it should be an error iff
> the float isn't already integer-valued?
Floats are tricky, so I think the programmer should state conversions
from floats to int explicitly. Coercing int to floats seems less
problematic and could probably done automatically.
> Perhaps if DFloNum (or a superclass?) had a method like:
>
>> public boolean isInexactInteger()
>> {
>> return (0.0 == Math.IEEEremainder(doubleValue(), 1.0));
>> }
I don't know much about floating-point stuff, but looking at the
exponent with (Math.getExponent(somefloat) == 0) might be better.
Helmut
More information about the Kawa
mailing list