This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Numbers in Kawa


* 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]