x86 and likely other architectures provide a method to get the quotient and remainder in a single operation (DIV
). Because of this many languages have a DIVMOD combined operation, (like DIVREM
in C#, DIVMOD
in Python, or with div
and div_t
in C. How can I do this in Rust?
Is there an optimized method to perform both
let res = (a / b, a % b);
As rodrigo commented already, the compiler is able to optimize this away. For the sake of completeness, there is a num_integer::div_rem method if you need it for generic integer types, but I'd vote against using this library if you don't need to be generic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With