[Haskell] instance Bounded Double

Stefan Karrmann sk at mathematik.uni-ulm.de
Mon Mar 14 15:51:09 EST 2005


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


More information about the Haskell mailing list