[erlang-questions] Flooring integer division in Erlang?
Sun Apr 27 04:06:28 CEST 2008
Thanks for the suggestion, but it does not work as needed with large
numbers. I tried similar things just like floor(A/B) (floor/1 was
found somewhere on TrapExit).
Say we want to print a factorial of 40. Each digit is obtained by
taking a quot and rem from division by 10. What I compute is
equivalent to (show . fac) in Haskell
With your function instead of div, in Haskell compiled to Erlang:
Same in ghci:
Prelude> let fac 1 = 1; fac n = n * fac (n - 1)
Prelude> (show . fac) 40
And when I use the standard div, in Haskell compiled to Erlang:
On Sat, Apr 26, 2008 at 7:59 PM, Igor Ribeiro Sucupira <> wrote:
> You could use, for example, the BIF trunc/1.
> Something like this:
> floorDiv(A, B) ->
> Quotient = A / B,
> Truncated = trunc(Quotient),
> case Truncated > Quotient of
> true -> Truncated - 1;
> false -> Truncated
Anywhere on the Web
More information about the erlang-questions