I don't like the idea that int_x==float_y could throw an error. I don't like it the slightest. It would really make Pike a much more difficult language to use. You throw exceptions when exceptional things happen. A float operation that looses precision is nothing exceptional, it is even the intention of floats to loose precision...
/ Martin Nilsson (saturator)
Previous text:
2003-09-16 01:40: Subject: Re: float type weirdness
On Mon, Sep 15, 2003 at 07:00:02PM -0400, Martin Nilsson (saturator) @ Pike (-) developers forum wrote:
I don't really understand what you mean here. Should Pike throw an exception if the integer is larger than 999999 (six digits) in an int/float comparision?
Yes. Or, exactly, if the precision is (will be) lost, exception should be thrown. The rules are simple enough (as we know the precision of floats and ints in bits). And at least on Intel there is special flag in FPU to indicate loss of precision (which may or may not be handled, depends on environment).
Say, when we try to cast int with 31 bits of precision (bits 24 and 0 are set) to 32 bit float (actually we will have 23 bits of precision in float
- exponent and sign take 9 bits) - precision will be lost.
Precision for floats (IEEE 754; sign is not included):
Single precision: 23 bits Double precision: 42 bits Long double: 64 bits
However, it is safe to convert (say) 2 << 64 into single precision float, since it is "floating point" - only one bit is set and exponent will be in effect.
Regards, /Al
/ Brevbäraren