So... Where is the point? 1.0 < 2 but 1.0 == 1 is false... Weird...
Every operator is defined to be as convenient as possible.
It's convenient that == can compare any two values, regardless of type, in a uniform way. In some cases it would be more convenient if it compared ints and floats according to their numerical values, but overall it'd be less convenient.
Similarly, it's convenient that < can order ints and floats according to their numerical values. In some cases it would be more convenient if it could order any two values, regardless of type, in a uniform way. It could do that by specifying an order between types, say int, float, string, array, mapping, multiset, object, function, program. Then 2 < 1.0 would be true. But overall that would be less convenient.
These convenience rules certainly aren't symmetric between the operators, and that can be considered weird. (I'm aware of several thoroughly weird convenience rules in different operators, say when strings are divided by floats, or when arrays containing nonstrings are multiplied with a string.)
There should perhaps be more operators, something like Generic.== (which is the current ==), Generic.<, Numeric.== and Numeric.< (which would be fairly similar to the current <).
/ Martin Stjernholm, Roxen IS
Previous text:
2003-09-15 22:38: Subject: Re: float type weirdness
On Mon, Sep 15, 2003 at 04:05:05PM -0400, Martin Stjernholm, Roxen IS @ Pike developers forum wrote:
Because it isn't in the domain of the float type, of course.
IMHO, any numerical (integer) value is in domain of the float type.
The difference is in fractional part (and precision, somehow), which isn't present in integers.
If I see construct like:
if (x < 2) ...;
I assume that this condition should check if x is _numerically_ less than 2, so it doesn't matter is x float, integer, mpi etc. Anyway:
1.0 < 2;
(5) Result: 1
1.0 > 2;
(6) Result: 0
So... Where is the point? 1.0 < 2 but 1.0 == 1 is false... Weird...
Regards, /Al
/ Brevbäraren