Re: [Haskell-cafe] Re: Double -> CDouble, realToFrac doesn't work

I would be very careful of adding non-rationals to the Rational type.
Why is there no Irrational class. This would make more sense for Floats and Doubles than the fraction based Rational class. We could also add an implementation of infinite precision irrationals using a pair of Integers for exponent and mantissa. Keean.

My guess is because irrationals can't be represented on a discrete computer (unless you consider a computaion, the limit of which is the irrational number in question). A single irrational might not just be arbitrarily long, but it may have an _infinite_ length representation! What you have described is arbitrary (not infinite) precision floating point. What IEEE has done is shoehorned in some values that aren't really numbers into their representation (NaN certainly; one could make a convincing argument that +Inf and -Inf aren't numbers). Perhaps it would make more sense to add constructors to the Rational type to represent these additional "values", ie, make Rational look like (edited from section 12.1 of the Report) data (Integral a) => Ratio a = a! :% a! | Nan | PosInf | NegInf deriving(Eq) type Rational = Ratio Integer This has the effect that pattern matching :% when the value is NaN etc. gives an error instead of doing bizarre things (by succeeding against non numeric values). This is an advantage or a disadvantage depending on your viewpoint. Unfortunately, that isn't how its defined in the Report, so it may not be an option. MR K P SCHUPKE wrote:
I would be very careful of adding non-rationals to the Rational type.
Why is there no Irrational class. This would make more sense for Floats and Doubles than the fraction based Rational class. We could also add an implementation of infinite precision irrationals using a pair of Integers for exponent and mantissa.
Keean. _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On Fri, 5 Nov 2004, Robert Dockins wrote:
What IEEE has done is shoehorned in some values that aren't really numbers into their representation (NaN certainly; one could make a convincing argument that +Inf and -Inf aren't numbers).
I wonder why Infinity has a sign in IEEE floating processing, as well as 0. To support this behaviour uniformly one would need a +0 or -0 offset for each number, which would lead straightforward to non-standard analysis ... Prelude> 1/0.0 Infinity Prelude> -1/0.0 -Infinity Prelude> -0.0 -0.0 Prelude> 1.0-1.0 0.0 Prelude> -(1.0-1.0) -0.0 Thus (a-b) is not the same as -(b-a) for IEEE floats!

Henning Thielemann wrote:
I wonder why Infinity has a sign in IEEE floating processing, as well as 0. To support this behaviour uniformly one would need a +0 or -0 offset for each number, which would lead straightforward to non-standard analysis ...
See "Branch Cuts for Complex Elementary Functions, or Much Ado About Nothing's Sign Bit" by William Kahan, in The State of the Art in Numerical Analysis, (eds. Iserles and Powell), Clarendon Press, Oxford, 1987. (Note that I have not read this paper. However, Kahan was the primary architect of the IEEE floating point standard, so you can be pretty sure the reasons given in the paper are also the reasons IEEE floating point has signed zero.) A good online presentation which mentions all kinds of interesting floating point pathologies, including those discussed in the above paper, is "How Java’s Floating-Point Hurts Everyone Everywhere" (http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf).
[...] Thus (a-b) is not the same as -(b-a) for IEEE floats!
Nor is x*0 equal to 0 for every x; nor does x == y imply f(x) == f(y) for every x, y, f; nor is addition or multiplication associative. There aren't many identities that do hold of floating point numbers. -- Ben

[...] Thus (a-b) is not the same as -(b-a) for IEEE floats!
Nor is x*0 equal to 0 for every x; nor does x == y imply f(x) == f(y) for every x, y, f; nor is addition or multiplication associative. There aren't many identities that do hold of floating point numbers.
Yes, but they DO hold for Rational (I believe). The argument against NaN = 0 :% 0, Inf = 1 :% 0, etc. is that the otherwise valid identies for _Rational_ are disturbed.

On Fri, 2004-11-05 at 13:57, Henning Thielemann wrote:
On Fri, 5 Nov 2004, Robert Dockins wrote:
What IEEE has done is shoehorned in some values that aren't really numbers into their representation (NaN certainly; one could make a convincing argument that +Inf and -Inf aren't numbers).
I wonder why Infinity has a sign in IEEE floating processing, as well as 0. To support this behaviour uniformly one would need a +0 or -0 offset for each number, which would lead straightforward to non-standard analysis
It is related to the decision to have signed infinity. One rationale is thus: The identity 1/(1/x) = x is only true for all IEEE floats x if we have signed 0. In particular if x is -infinity then 1/(-infinity) would be 0 and 1/0 = +infinity in the IEEE floating point system. So if we preserve the sign for overflow (+-infinity), we also need to preserve the sign for underflow (+-0) or other identities fail. Note that -0 == +0 See: What Every Computer Scientist Should Know About Floating Point Arithmetic http://citeseer.ist.psu.edu/goldberg91what.html page 183. Duncan

Henning Thielemann wrote:
On Fri, 5 Nov 2004, Robert Dockins wrote:
What IEEE has done is shoehorned in some values that aren't really numbers into their representation (NaN certainly; one could make a convincing argument that +Inf and -Inf aren't numbers).
I wonder why Infinity has a sign in IEEE floating processing, as well as 0. To support this behaviour uniformly one would need a +0 or -0 offset for each number, which would lead straightforward to non-standard analysis ...
IEEE floats support both affine (signed) and projective (unsigned) infinity. Projective is more natural in some circumstances (since you can do a Möbius transformation from a circle to an infinite line). Haskell, on the othet hand, does not let you specify the mode. -- Lennart

MR K P SCHUPKE wrote:
Why is there no Irrational class. This would make more sense for Floats and Doubles than the fraction based Rational class. We could also add an implementation of infinite precision irrationals using a pair of Integers for exponent and mantissa.
That would just be a subset of the rationals, namely the dyadic rationals (mantissa / 2^^exponent). -- Ben
participants (6)
-
Ben Rudiak-Gould
-
Duncan Coutts
-
Henning Thielemann
-
Lennart Augustsson
-
MR K P SCHUPKE
-
Robert Dockins