Apparently, x86 (and probably a lot of other instruction sets) put both the quotient and the remainder of a divide operation in separate registers.
Now, we can probably trust compilers to optimize a code such as this to use only one call to divide:
( x / 6 )
( x % 6 )
And they probably do. Still, do any languages (or libraries, but mainly looking for languages) support giving both the divide and modulo results at the same time? If so, what are they, and What does the syntax look like?
Common Lisp does: http://www.lispworks.com/documentation/HyperSpec/Body/f_floorc.htm
This return the result an de remainder
The .NET framework has
Math.DivRem
:Although,
DivRem
is just a wrapper around something like this:(I have no idea whether or not the jitter can/does optimise that sort of thing into a single instruction.)
In Java the class
BigDecimal
has the operationdivideAndRemainder
returning an array of 2 elements with the result and de remainder of the division.Javadoc: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#divideAndRemainder(java.math.BigDecimal)
In C#/.NET you've got
Math.DivRem
: http://msdn.microsoft.com/en-us/library/system.math.divrem.aspxBut according to this thread this isn't that much an optimization.