convert to fixed length Int

Hi. In Haskell, how would I go about converting from a Double (or Float) type to a Data.Int.Int8, Data.Int.Int16, and so forth? (Of course, expecting rounding and damage to out of range values.) I was playing around with signal generation using trig functions (hence the floating types) but the actual output has to be Int16. -- frigidcode.com indicium.us

On 08/17/12 01:42, Christopher Howard wrote:
Hi. In Haskell, how would I go about converting from a Double (or Float) type to a Data.Int.Int8, Data.Int.Int16, and so forth? (Of course, expecting rounding and damage to out of range values.)
I was playing around with signal generation using trig functions (hence the floating types) but the actual output has to be Int16.
Don't know if there's a better or correct way, but this seems to work: ghci> let c = (round 256.6) :: Int16 ghci> :type c c :: Int16 It rolls over at overflow: ghci> let c = (round 65537) :: Int16 ghci> c 1
participants (2)
-
Carlos J. G. Duarte
-
Christopher Howard