Reputation: 219
I want to find, if there is a same divisor between y,x and z,y following:
myFunc [x,y,z] = if y `div` x == z `div` y then True else False
But here I get True even if the divisor is not the same, let´s assume we have
x = 32
y = 64
z = 129
I suppose the problem is with div
, which only makes int division. Is there any int to float divison in haskell that I could use to solve it?
Upvotes: 0
Views: 651
Reputation: 1381
div is floor division. It returns floor of a/b. Change your function to:
myFunc [x,y,z] = (y `foo` x) == (z `foo` y) where foo a b = (fromIntegral a) / (fromIntegral b)
Upvotes: 1