[Haskell-cafe] floating point operations and representation

John Meacham john at repetae.net
Mon Mar 17 14:15:21 EDT 2008

On Mon, Mar 17, 2008 at 12:59:09PM -0400, David Roundy wrote:
> foreign import ccall unsafe "math.h log10" log10 :: Double -> Double
> since in ghc CDouble and Double are identical.
> It's a bit sloppier, but shouldn't cause any trouble.  And I've no
> idea how realToFrac is implemented, but would worry about it behaving
> oddly... for instance when given NaNs.

Yes. 'realToFrac' is inherently pretty broken and should be avoided
whenever possible. It is not all all obvious to me what the correct
primitive should be.. but we really should do something better for
haskell'. relying on RULES firing as ghc currently does doesn't seem

hmm.. maybe a 'FloatMax' type and have 'fromFloatMax' and 'toFloatMax'
in 'Fractional' and 'Real' respectively? hmm.. hc has 'fromDouble' and
'toDouble' there, but jhc also supports a 'Float128' type (when the
underlying hardware does). so this still isn't quite right.


John Meacham - ⑆repetae.net⑆john⑈

More information about the Haskell-Cafe mailing list