Re: Converting float to double.

2000-05-09 Thread Marcin 'Qrczak' Kowalczyk

Mon, 8 May 2000 20:42:10 -0700 (PDT), Ronald J. Legere <[EMAIL PROTECTED]> pisze:

>  I have a very simple question. What is the best way to 
> convert a float to a double?
>  I use fromRational.toRational, and the notes in the prelude
> seem to imply that this is optimized into something sensible..

The Prelude contains:

realToFrac:: (Real a, Fractional b) => a -> b
realToFrac = fromRational . toRational

Unfortunately GHC currently does not optimize this into anything
smarter than going through Rational. Fortunately it contains enough
machinery so you can let it optimize it yourself :-)  Just add:

import NumExts (floatToDouble, doubleToFloat)

{-# RULES
"realToFrac/Float->Double" realToFrac = floatToDouble
"realToFrac/Double->Float" realToFrac = doubleToFloat #-}

and compile with  -syslib lang -O  and use realToFrac.

To GHC developers: please add it to the GHC's library.

-- 
 __("$ P+++ L++>$ E-
  ^^  W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK  5? X- R tv-- b+>++ DI D- G+ e> h! r--%>++ y-





Converting float to double.

2000-05-08 Thread Ronald J. Legere


 I have a very simple question. What is the best way to 
convert a float to a double?
 I use fromRational.toRational, and the notes in the prelude
seem to imply that this is optimized into something sensible..
is this the way?

Cheers! + Ron Legere --
http://www.its.caltech.edu/~legere Caltech Quantum Optics MC 12-33
Pasadena CA 91125 626-395-8343 FAX: 626-793-9506
+