Convert Double to Data.Fixed

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Convert Double to Data.Fixed

Eugene Kirpichov
Hi cafe,

How do I most efficiently convert a Double to a Data.Fixed?

I'm asking because I want to convert fractional seconds to the seconds field of Data.Time.TimeOfDay, which is Pico = Data.Fixed.Fixed E12.

For now the fastest thing I came up with was fromIntegral (round (sec*1000000)) / fromIntegral 1000000, but this frankly sucks and is rather slow, there must be a better way.

--
Eugene Kirpichov
Principal Engineer, Mirantis Inc. http://www.mirantis.com/
Editor, http://fprog.ru/

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Convert Double to Data.Fixed

Albert Y. C. Lai
On 11-12-26 10:55 AM, Eugene Kirpichov wrote:
> How do I most efficiently convert a Double to a Data.Fixed?

Double is an instance of Real, Fixed E12 is an instance of Fractional,
they are eligible for realToFrac.

Similarly for many time types.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe