Fergus Henderson <[EMAIL PROTECTED]> writes:
> Yes, but for any given Haskell program execution, the sum of any two
> floating-point values should be the same every time you compute it.
> In general it need not be the same as the sum of the equivalent real
> numbers, because floating point numbers are subject to rounding,
> overflow, etc., and of course it might vary from platform to platform,
> or from compiler to compiler, or perhaps even from run to run;
> but nevertheless, Haskell or any other language which aims to be
> referentially transparent, for any given program execution the sum
> should be the same each time in that program execution.
I haven't verified it, but I expect that on x86, the following code if
compiled by gcc can print "Oops! divided by zero". I agree with
Fergus that this behavior is undesirable and should be avoided for
Haskell, unless a flag like "-funsafe-fast-math" is provided.
double inverse(double val) {
if (val == 0) {
printf("Oops! divided by zero\n");
abort();
} else {
return 1/val;
}
}
...
double a, b;
...
if (a-b == 0) {
inv = 1;
} else {
inv = inverse(a-b);
}
...
Carl Witty