
daveroundy:
On Wed, Mar 12, 2008 at 9:27 PM, Don Stewart
wrote: You could consider binding directly to the C functions, if needed,
{-# OPTIONS -fffi -#include "math.h" #-}
import Foreign.C.Types
foreign import ccall unsafe "math.h log10" c_log10 :: CDouble -> CDouble
log10 :: Double -> Double log10 x = realToFrac (c_log10 (realToFrac x))
Actually, you could almost certainly just use
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.
It's a no-op (from the core I was looking at), and then you're not worrying about coercing newtypes. -- Don