[erlang-questions] Flooring integer division in Erlang?

Igor Ribeiro Sucupira igorrs@REDACTED
Sun Apr 27 01:59:13 CEST 2008


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
    end.

On Sat, Apr 26, 2008 at 7:58 PM, Dimitry Golubovsky
<golubovsky@REDACTED> wrote:
> Hi,
>
>  I am implementing a program that converts intermediate output from a
>  Haskell compiler (Yhc Core) to Erlang Core. Therefore it is desirable
>  to emulate behavior of Haskell operations as closely as possible. So
>  whatever could be used, would be good, either high level, or low level
>  implementation. Low level could probably be done at the virtual
>  machine level, but this does not seem to be the best way as would
>  result in custom version of the VM.  If there is a high level
>  implementation I'd appreciate if you provide a link.
>
>  Thanks.
>
>
>  On Sat, Apr 26, 2008 at 1:37 PM, Igor Ribeiro Sucupira <igorrs@REDACTED> wrote:
>  > Are you just in need of some (any) high-level implementation? Or
>  >  you're after some really efficient operator?
>
>
> >  >  Is there any Erlang library around that contains an integer division
>  >  >  function that rounds negative quotient down (towards negative
>  >  >  infunity, flooring division)?
>
>  --
>
>
> Dimitry Golubovsky
>
>  Anywhere on the Web
>



More information about the erlang-questions mailing list