Alex Rivera | Logout

Divide Int to Int and return Int

Asked 2010-12-05T13:30:17.010
80

I need a function which gets two Ints (a and b) and returns A/B as Int. I am sure that A/B will always be an integer.

Here is my solution:

myDiv :: Int -> Int -> Int
myDiv a b = 
      let x = fromIntegral a
          y = fromIntegral b
      in truncate (x / y)

But want to find more simpler solution. Something like this:

myDiv :: Int -> Int -> Int
myDiv a b = a / b

How can I divide Int to Int and get Int ?

Edit
Report

1 Answer

145

Why not just use quot?

quot a b

is the integer quotient of integers a and b truncated towards zero.

answered 2010-12-05T13:36:13.843

Your Answer