Converting from Int to Double

Hello! I have a list of integer numbers (grayscale values from 0 to 255) and want to convert them to a list of double numbers, so that each number is 0 <= x <= 1, where 0 is completely black and 1 is completely white. Before I convert the numbers, I need to convert them to a list of double values (then I can use map to re-scale each element from 0..255 to 0..1). How can I convert an Int into a Double? TIA Dmitri Pissarenko -- Dmitri Pissarenko Software Engineer http://dapissarenko.com

Zitat von Henning Thielemann
On Wed, 26 Jan 2005, Dmitri Pissarenko wrote:
How can I convert an Int into a Double?
fromIntegral
Thanks! -- Dmitri Pissarenko Software Engineer http://dapissarenko.com

How can I convert an Int into a Double?
You don't convert to, you convert from :-) The function 'fromIntegral' is probably what you want.
And what function can I use to convert from Double to Int (the inverse of fromIntegral) ? TIA Dmitri Pissarenko -- Dmitri Pissarenko Software Engineer http://dapissarenko.com

Dmitri,
And what function can I use to convert from Double to Int (the inverse of fromIntegral) ?
You should really have a look at the Prelude and the Standard Libraries. Well, it depends on *how* you want to convert. truncate :: (RealFrac a, Integral b) => a -> b round :: (RealFrac a, Integral b) => a -> b floor :: (RealFrac a, Integral b) => a -> b ceiling :: (RealFrac a, Integral b) => a -> b HTH, Stefan

How can I convert an Int into a Double?
You don't convert to, you convert from :-) The function 'fromIntegral' is probably what you want.
And what function can I use to convert from Double to Int (the inverse of fromIntegral) ?
Use the functions in the RealFrac class. http://www.haskell.org/onlinereport/standard-prelude.html#$tRealFrac class (Real a, Fractional a) => RealFrac a where properFraction :: (Integral b) => a -> (b,a) truncate, round :: (Integral b) => a -> b ceiling, floor :: (Integral b) => a -> b J.A.

Thanks! -- Dmitri Pissarenko Software Engineer http://dapissarenko.com
participants (5)
-
Dmitri Pissarenko
-
Henning Thielemann
-
Jorge Adriano Aires
-
Ketil Malde
-
Stefan Holdermans