Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Divides {@code n} by 2.
- *
- * @param n
- * {@code NaturalNumber} to be divided
- * @updates n
- * @ensures 2 * n <= #n < 2 * (n + 1)
- */
- private static void divideBy2(NaturalNumber n) {
- int lastDigit = 0;
- if (!n.isZero()) {
- lastDigit = n.divideBy10();
- if (!n.isZero()) {
- int remainder2 = n.divideBy10();
- if (remainder2 % 2 != 0) {
- lastDigit = lastDigit / 2 + 5;
- } else {
- lastDigit = lastDigit / 2;
- }
- divideBy2(n);
- n.multiplyBy10(lastDigit);
- } else {
- lastDigit = lastDigit / 2;
- }
- }
- n.multiplyBy10(lastDigit);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement