I'll ignore the sarcasms and goes straight to the actual topic: If you do the calculation VERY_BIG_VALUE - VERY_SMALL_VALUE - VERY_BIG_VALUE you will end up with 0.0, and not VERY_SMALL_VALUE, which would be the mathematically true answer. Although the result 0.0 is from a bit-for-bit perspective identical to the constant 0.0, the former is just an approximation. And although 2.0 == 2.0, it is not at all certain that 1.0/7.0 == 10.0/70.0 and 2 == 2.0 in the general case, due to the nature of floats.
/ Martin Nilsson (saturator)
Previous text:
2003-09-15 21:39: Subject: Re: float type weirdness
On Mon, Sep 15, 2003 at 03:10:01PM -0400, Martin Nilsson (saturator) @ Pike (-) developers forum wrote:
The issue here is probably how you consider floats. I see 0.0 as a value that is aproximatly zero. I actually consider `== on floats useless and
0.0 is zero - numerically, mathematically. Precisely. Not "near zero" or "aproximatly". It is treated like zero everywhere. Why it is different in Pike - I can't understand.
`== on floats is not (and never will be) useless. 2.0 == 2.0, and 1.0/7.0 == 10.0/70.0. x = 1.0; y = 1.0; and x == y.
that 0==0.0 as a bug. After all 1!=1.0 so why should 0==0.0?
1 != 1.0 only in Pike, I guess. Because 1 == 1.0. Numerically. Like any other number (if precision allows). But 0.0 is zero regardless of precision (and even most binary representation of floats use all zero bits for 0.0).
It is not logical to make a difference between 1.0 and 1 with assignment or comparision operation, unless you want to make everything as strict as possible (but then - Pike is not strict enough in everything else anyway).
After all, if two (numerical) types are different, an implicit conversion must be made (because I can assign: float x = 1.0 + 2), or will you require explicit cast everywhere?
There is a bit more mislead... From equal() docs:
"This function checks if the values a and b are equal." and later: "For all types but arrays, multisets and mappings, this operation is the same as doing a == b"
But from the tutorial (comparision operators):
"The operators == and != can be used on any type. Note that these two operators check if two things are the same, not just if they are equal."
equal(1, 1.0);
(4) Result: 0
This is a bit misleading, at least. How do I check that two things are _equal_? Again (yes, I know, you hate me already for this :) - in most languages comparision is test for _equality_, at least for numerical types.
So? :) Let's keep Pike as different as possible from everything else? :)
Regards, /Al
/ Brevbäraren