Following are some examples using the power, integer divide, and
remainder operators:
/* Again with: Numeric digits 5 */
2**3 -> 8
2**-3 -> 0.125
1.7**8 -> 69.758
2%3 -> 0
2.1//3 -> 2.1
10%3 -> 3
10//3 -> 1
-10//3 -> -1
10.2//1 -> 0.2
10//0.3 -> 0.1
3.6//1.3 -> 1.0
Note: - A particular algorithm for calculating powers is used,
because it is efficient (though not optimal) and considerably reduces
the number of actual multiplications performed. It, therefore, gives
better performance than the simpler definition of repeated multiplication.
Because results may differ from those of repeated multiplication,
the algorithm is defined here.
- The integer divide and remainder operators are defined so that
they can be calculated as a by-product of the standard division operation.
The division process is ended as soon as the integer result is available;
the residue of the dividend is the remainder.