
On 17 Mar 2008, bulat.ziganshin@gmail.com wrote:
Hello David,
Monday, March 17, 2008, 7:59:09 PM, you wrote:
foreign import ccall unsafe "math.h log10" c_log10 :: CDouble -> CDouble
log10 :: Double -> Double log10 x = realToFrac (c_log10 (realToFrac x))
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.
it should be nop (no operation) in such cases
A related issue: http://hackage.haskell.org/trac/ghc/ticket/2110 Presumably everyone is aware of decodeFloat :: (RealFloat a) => a -> (Integer, Int) which really is a canonical representation of a floating point number. As for realToFrac, this really isn't okay: *GHCi> 0/0 NaN *GHCi> realToFrac (0/0) -Infinity Also, this one might surprise a few people. *GHCi> realToFrac (realToFrac 0.2 :: Ratio Int) -Infinity *GHCi> realToFrac 0.2 :: Ratio Int (-858993459)%0 Jed