Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell minimum/maximum Double Constant

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

like image 659
Claudiu Avatar asked Nov 23 '09 00:11

Claudiu


1 Answers

maxNonInfiniteFloat :: RealFloat a => a -> a
maxNonInfiniteFloat a = encodeFloat m n 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
like image 110
ephemient Avatar answered Sep 23 '22 05:09

ephemient