Shouldn't Double, Float, etc. be instances of Bounded? I've declared e.g. instance Bounded Double where minBound = -(1/0) maxBound = 1/0 in a module where I needed it and there doesn't seem to be any issue with the definition... Frederik -- http://ofb.net/~frederik/
Haskell does not guarantee that 1/0 is well defined, nor that -(1/0) is different from 1/0. While the former is true for IEEE floating point numbers, the latter is only true when using affine infinities. -- Lennart Frederik Eaton wrote:
Shouldn't Double, Float, etc. be instances of Bounded?
I've declared e.g.
instance Bounded Double where minBound = -(1/0) maxBound = 1/0
in a module where I needed it and there doesn't seem to be any issue with the definition...
Frederik
Interesting. In that case, I would agree that portability seems like another reason to define a Bounded instance for Double. That way users could call 'maxBound' and 'minBound' rather than 1/0 and -(1/0)... Frederik On Fri, Mar 11, 2005 at 11:10:33AM +0100, Lennart Augustsson wrote:
Haskell does not guarantee that 1/0 is well defined, nor that -(1/0) is different from 1/0. While the former is true for IEEE floating point numbers, the latter is only true when using affine infinities.
-- Lennart
Frederik Eaton wrote:
Shouldn't Double, Float, etc. be instances of Bounded?
I've declared e.g.
instance Bounded Double where minBound = -(1/0) maxBound = 1/0
in a module where I needed it and there doesn't seem to be any issue with the definition...
Frederik
And what would you have minBound and maxBound be? I guess you could use +/- the maximum value representable. Going for infinity is rather dodgy, and assumes an FP representation that has infinity. -- Lennart Frederik Eaton wrote:
Interesting. In that case, I would agree that portability seems like another reason to define a Bounded instance for Double. That way users could call 'maxBound' and 'minBound' rather than 1/0 and -(1/0)...
Frederik
On Fri, Mar 11, 2005 at 11:10:33AM +0100, Lennart Augustsson wrote:
Haskell does not guarantee that 1/0 is well defined, nor that -(1/0) is different from 1/0. While the former is true for IEEE floating point numbers, the latter is only true when using affine infinities.
-- Lennart
Frederik Eaton wrote:
Shouldn't Double, Float, etc. be instances of Bounded?
I've declared e.g.
instance Bounded Double where minBound = -(1/0) maxBound = 1/0
in a module where I needed it and there doesn't seem to be any issue with the definition...
Frederik
I may be barking up the wrong tree here, but I think the key to this discussion is that real numbers are not bounded, while doubles are bounded. One cannot say what the smallest or largest real number are, but one can say what the smallest or largest double are (and it is unfortunately implementation specific, and probably pretty messy to set up). We could define maxBound as (2^(mantisa_space))^(2^(exponent_space)) and min bound pretty similarly... But I'm sure that everyone will agree that this is a horrible hack. One may even question whether Doubles should be bounded, in that they are an attempt to represent real numbers, and as such should come as close as is possible to being real numbers (meaning not having bounds). Sorry for a possibly irrelevant ramble. Bob On Mar 13, 2005, at 11:02 PM, Lennart Augustsson wrote:
And what would you have minBound and maxBound be? I guess you could use +/- the maximum value representable. Going for infinity is rather dodgy, and assumes an FP representation that has infinity.
-- Lennart
Frederik Eaton wrote:
Interesting. In that case, I would agree that portability seems like another reason to define a Bounded instance for Double. That way users could call 'maxBound' and 'minBound' rather than 1/0 and -(1/0)... Frederik On Fri, Mar 11, 2005 at 11:10:33AM +0100, Lennart Augustsson wrote:
Haskell does not guarantee that 1/0 is well defined, nor that -(1/0) is different from 1/0. While the former is true for IEEE floating point numbers, the latter is only true when using affine infinities.
-- Lennart
Frederik Eaton wrote:
Shouldn't Double, Float, etc. be instances of Bounded?
I've declared e.g.
instance Bounded Double where minBound = -(1/0) maxBound = 1/0
in a module where I needed it and there doesn't seem to be any issue with the definition...
Frederik
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
I agree with all of that. :) -- Lennart Thomas Davie wrote:
I may be barking up the wrong tree here, but I think the key to this discussion is that real numbers are not bounded, while doubles are bounded. One cannot say what the smallest or largest real number are, but one can say what the smallest or largest double are (and it is unfortunately implementation specific, and probably pretty messy to set up). We could define maxBound as (2^(mantisa_space))^(2^(exponent_space)) and min bound pretty similarly... But I'm sure that everyone will agree that this is a horrible hack.
One may even question whether Doubles should be bounded, in that they are an attempt to represent real numbers, and as such should come as close as is possible to being real numbers (meaning not having bounds).
Sorry for a possibly irrelevant ramble.
Bob
On Mar 13, 2005, at 11:02 PM, Lennart Augustsson wrote:
And what would you have minBound and maxBound be? I guess you could use +/- the maximum value representable. Going for infinity is rather dodgy, and assumes an FP representation that has infinity.
-- Lennart
Frederik Eaton wrote:
Interesting. In that case, I would agree that portability seems like another reason to define a Bounded instance for Double. That way users could call 'maxBound' and 'minBound' rather than 1/0 and -(1/0)... Frederik On Fri, Mar 11, 2005 at 11:10:33AM +0100, Lennart Augustsson wrote:
Haskell does not guarantee that 1/0 is well defined, nor that -(1/0) is different from 1/0. While the former is true for IEEE floating point numbers, the latter is only true when using affine infinities.
-- Lennart
Frederik Eaton wrote:
Shouldn't Double, Float, etc. be instances of Bounded?
I've declared e.g.
instance Bounded Double where minBound = -(1/0) maxBound = 1/0
in a module where I needed it and there doesn't seem to be any issue with the definition...
Frederik
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Perhaps some motivation is in order. In an interval arithmetic library, I have 'Bounded a' as a constraint on the instance 'Fractional (Interval a)' because an interval of maximum bound can result when dividing by an interval containing zero. In a function solver library I wrote, parameters need to be specified with constraints on their values - so that the natural default can be (minBound, maxBound) I require them to be Bounded. Having these bounds be plus and minus infinity is elegant, but not necessary for either of these applications, so I think that even if some platforms don't have affine infinities there should still be a suitably defined maxBound and minBound for Double - just maximum and minimum representable values should be fine. (Besides, exactly how many floating point implementations use projective infinities?) Frederik On Sun, Mar 13, 2005 at 11:08:26PM +0000, Thomas Davie wrote:
I may be barking up the wrong tree here, but I think the key to this discussion is that real numbers are not bounded, while doubles are bounded. One cannot say what the smallest or largest real number are, but one can say what the smallest or largest double are (and it is unfortunately implementation specific, and probably pretty messy to set up). We could define maxBound as (2^(mantisa_space))^(2^(exponent_space)) and min bound pretty similarly... But I'm sure that everyone will agree that this is a horrible hack.
One may even question whether Doubles should be bounded, in that they are an attempt to represent real numbers, and as such should come as close as is possible to being real numbers (meaning not having bounds).
Sorry for a possibly irrelevant ramble.
Bob
On Mar 13, 2005, at 11:02 PM, Lennart Augustsson wrote:
And what would you have minBound and maxBound be? I guess you could use +/- the maximum value representable. Going for infinity is rather dodgy, and assumes an FP representation that has infinity.
-- Lennart
Frederik Eaton wrote:
Interesting. In that case, I would agree that portability seems like another reason to define a Bounded instance for Double. That way users could call 'maxBound' and 'minBound' rather than 1/0 and -(1/0)... Frederik On Fri, Mar 11, 2005 at 11:10:33AM +0100, Lennart Augustsson wrote:
Haskell does not guarantee that 1/0 is well defined, nor that -(1/0) is different from 1/0. While the former is true for IEEE floating point numbers, the latter is only true when using affine infinities.
-- Lennart
Frederik Eaton wrote:
Shouldn't Double, Float, etc. be instances of Bounded?
I've declared e.g.
instance Bounded Double where minBound = -(1/0) maxBound = 1/0
in a module where I needed it and there doesn't seem to be any issue with the definition...
Frederik
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
On Sun, Mar 13, 2005 at 11:08:26PM +0000, Thomas Davie wrote:
I may be barking up the wrong tree here, but I think the key to this discussion is that real numbers are not bounded, while doubles are bounded. One cannot say what the smallest or largest real number are, but one can say what the smallest or largest double are (and it is unfortunately implementation specific, and probably pretty messy to set up). We could define maxBound as (2^(mantisa_space))^(2^(exponent_space)) and min bound pretty similarly... But I'm sure that everyone will agree that this is a horrible hack.
I don't see how this is any more hacky than defining the minBound for int as - 2^(number of bits - 1 ) and the maxBound as 2^(number of bits - 1) - 1 which seems to be generally accepted. In any case, I am in favor of including the instance, perhaps in its own module, due to the fact that if two useful libraries end up having to declare their own, said libraries cannot be used together. However, if they both rely on the same external module, no problems will arise. That and since the maxBound is machine dependent, it seems like it Should be made available somewhere in the libraries since portable programs would have no other way to figure this sort of thing out. John -- John Meacham - ⑆repetae.net⑆john⑈
John Meacham (Sun, Mar 13, 2005 at 08:08:56PM -0800):
On Sun, Mar 13, 2005 at 11:08:26PM +0000, Thomas Davie wrote:
[...] We could define maxBound as (2^(mantisa_space))^(2^(exponent_space)) and min bound pretty similarly... But I'm sure that everyone will agree that this is a horrible hack.
2 cent: module Float_bounds ( max_float , min_float , min_pos_float , max_neg_float ) where d = 1 :: Double f = 1 :: Float max_float x = encodeFloat (radix ^ mant - 1) (expo - mant) where radix = floatRadix x mant = floatDigits x expo = snd $ floatRange x min_pos_float x = encodeFloat (1) (expo - mant) where radix = floatRadix x mant = floatDigits x expo = fst $ floatRange x min_float x = - max_float x max_neg_float x = - min_pos_float x Regards -- Stefan Karrmann
participants (5)
-
Frederik Eaton -
John Meacham -
Lennart Augustsson -
Stefan Karrmann -
Thomas Davie