Double -> CDouble, realToFrac doesn't work

Hal Daume III hdaume at ISI.EDU
Tue Aug 3 20:53:56 EDT 2004

I need to convert a Double to a CDouble to pass to a C function.

In the past, when I've asked how to do this, I'm told: realToFrac. This
works in most cases, but recently gave me a problem that took me *forever* 
to track down:

Prelude Foreign.C> (0 :: CDouble) / 0
Prelude Foreign.C> (0 :: Double) / 0
Prelude Foreign.C> realToFrac ((0 :: Double) / 0) :: CDouble

yikes!  the NaN got turned into a -Infinity!!!

aside from manually checking for 'strange' Double/CDouble values and 
wrapping realToFrac, is there a better way?  also, does this count as a 

 Hal Daume III                                   | hdaume at
 "Arrest this man, he talks in maths."           |

More information about the Glasgow-haskell-users mailing list