On 12/25/2011 10:57 PM, Don wrote:
On 24.12.2011 22:12, bearophile wrote:
Caligo:

I'm hoping to see something like the above mod function in Phobos someday.

I'd like that, for both int/long/BigInts. And I'd like some functions for
BigInts:
- divmod: returns both % and div and %, but it's more efficient if you need
both values;
- gcd

These should both exist for int and long as well.

Consider the following program:

  int div(int a, int b)
  {
    auto x = a / b;
    auto y = a % b;
    return x + y;
  }

Compile with:

  dmd -c test -O

Disassemble with obj2asm:

  _D4test3divFiiZi        comdat
                push    EAX
                mov     EAX,8[ESP]
                cdq
                idiv    [ESP]
                add     EAX,EDX
                pop     ECX
                ret     4

Reply via email to