Which function returns a pair after division ? (integer,frac)

Vitaliy Fadeev vital.fadeev at gmail.com
Tue Sep 19 04:06:33 UTC 2023


On Tuesday, 19 September 2023 at 03:53:06 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> There are no operators for this, not that you need one.
>
> ```d
> void func(int numerator, int denominator, out int quotient, out 
> int remainder) {
>     quotient = numerator / denominator;
>     remainder = numerator % denominator;
> }
> ```
>
> This will produce with ldc2 -O3:
>
> ```
> void example.func(int, int, out int, out int):
>         mov     r8, rdx
>         mov     eax, edi
>         cdq
>         idiv    esi
>         mov     dword ptr [r8], eax
>         mov     dword ptr [rcx], edx
>         ret
> ```
>
> Embrace modern backends, they are amazing!

Thanks, Rikki. Optimization is good!
May be exist native D function or D-operator, like ```(a,b) = x 
/% y;``` ?



More information about the Digitalmars-d-learn mailing list