David Hopwood wrote:
> Maximilian Wilson wrote:
>>On 12/2/05, Maximilian Wilson <[EMAIL PROTECTED]> wrote:
>>
>>>operation. This wouldn't matter so much if Floats didn't have such
>>>very different properties from Ints, unlike say fixed-point numbers...
>>>it makes it very difficult to reason about the semantics of your
>>>calculation. I am more and more coming to appreciate Mozart's strict
>>>aversion to arithmetic type coercion.
>>
>>Come to think of it, it strikes me that C-style type promotion (an int
>>is a float) is a bad idea for the same reason that "a square 'IS A'
>>rectangle" is now widely considered to be a fallacy. A square has the
>>same *data* as a rectangle, but it has extra constraints, so the
>>Liskov substitution principle doesn't hold if squares are mutable.
>
> But ints and floats are not mutable, so the reason is not the same.
>
> I agree that int should not be considered a subtype of float, though.
> Floating point arithmetic gives numerically different results than integer
> arithmetic (since it may lose precision), and this is sufficient reason by
> itself not to consider int a subtype of float.
Concrete example in C99 (on an x86 platform, which has approximately
IEEE 754-compliant doubles):
#include <stdio.h>
int main(int argc, char **argv) {
printf("%f\n", 9000000000000001.0);
printf("%f\n", 9000000000000001.0 + 9000000000000001.0 +
9000000000000001.0);
printf("%lld\n", 9000000000000001LL);
printf("%lld\n", 9000000000000001LL + 9000000000000001LL +
9000000000000001LL);
}
9000000000000001.000000
27000000000000004.000000
9000000000000001
27000000000000003
--
David Hopwood <[EMAIL PROTECTED]>
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users