Am Sonntag, 14. Mai 2006 09:30 schrieb SevenThunders:
> I am new to Haskell and found myself in a bind concerning the use of
> the C types, CDouble in particular.  I extract a CDouble via it's pointer
> from a StorableArray.  Since the array must interface with C the elements
> of the array must be CDouble.  Now I'd like to use Text.Printf to format
> print statements of elements of the array, but Text.Printf requires Doubles
> as inputs and so far I have not found an obvious way to coerce CDoubles
> into Doubles. [...]

You can use the Prelude function realToFrac to convert between the various 
floating-point types:

----------------------------------------------------------------
[EMAIL PROTECTED]:~> ghci -v0
Prelude> :t realToFrac
realToFrac :: (Fractional t1, Real t) => t -> t1
Prelude> (realToFrac :: Foreign.C.Types.CDouble -> Double) 1234.5
1234.5
----------------------------------------------------------------

As you can see from its type, realToFrac is not exactly about floating-point 
conversions, but for almost all practical use cases it is. :-)

Cheers,
   S.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to