Min / Max Haskell Double Constant

Is there a way in Haskell to get a constant that is the largest and smallest possible positive rational number greater than zero that can be represented by doubles?

+7
floating-point haskell constants
source share
2 answers
maxNonInfiniteFloat :: RealFloat a => a -> a maxNonInfiniteFloat a = encodeFloat mn where b = floatRadix a e = floatDigits a (_, e') = floatRange a m = b ^ e - 1 n = e' - e minPositiveFloat :: RealFloat a => a -> a minPositiveFloat a = encodeFloat 1 $ fst (floatRange a) - floatDigits a 
+7
source share

GHC.Float has the function [floatRange][2] :

floatRange :: a β†’ (Int, Int) Source

constant function that returns the smallest and highest values ​​that an exponent can take

which should be what you want.

+2
source share

All Articles