mostly on computers and mathematics
ceilDiv x y = let { (d,m) = divMod x y } in if m>0 then (d+1) else d
This approximates the function composition (ceil . (/)) without going through floating point (assuming non-negative).
(ceil . (/))
floorDiv is not necessary; plain div will do.
div
Alternatively, ceilDiv x y = (x + y - 1) `div` y
Or even nicer: ceilDiv x y = negate (negate x `div` y)
Post a Comment
2 comments :
Alternatively, ceilDiv x y = (x + y - 1) `div` y
Or even nicer: ceilDiv x y = negate (negate x `div` y)
Post a Comment