What is the function to get the quotient and remainder (DIVMOD) for rust?

Viewed 3423

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);
1 Answers

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

Related