From 7aedbd5e20d3f4c484b5f3abbda4b40c2bc9985d Mon Sep 17 00:00:00 2001 From: Arthur Drobot Date: Tue, 25 Jul 2017 14:36:46 -0700 Subject: [PATCH] Add support for non-positive ints in intPow for NaiveNumber. --- src/org/nwapw/abacus/number/NaiveNumber.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/org/nwapw/abacus/number/NaiveNumber.java b/src/org/nwapw/abacus/number/NaiveNumber.java index 6ad43f1..2465007 100755 --- a/src/org/nwapw/abacus/number/NaiveNumber.java +++ b/src/org/nwapw/abacus/number/NaiveNumber.java @@ -43,10 +43,18 @@ public class NaiveNumber implements NumberInterface { @Override public NumberInterface intPow(int exponent) { + if(exponent == 0){ + return NaiveNumber.ONE; + } + boolean takeReciprocal = exponent < 0; + exponent = Math.abs(exponent); NumberInterface power = this; for(int currentExponent = 1; currentExponent < exponent; currentExponent++){ power = power.multiply(this); } + if(takeReciprocal){ + power = NaiveNumber.ONE.divide(power); + } return power; }