diff --git a/src/main/java/org/nwapw/abacus/number/NumberInterface.java b/src/main/java/org/nwapw/abacus/number/NumberInterface.java index c77f531..83007c2 100755 --- a/src/main/java/org/nwapw/abacus/number/NumberInterface.java +++ b/src/main/java/org/nwapw/abacus/number/NumberInterface.java @@ -182,7 +182,7 @@ public abstract class NumberInterface { * Also, checks if the thread has been interrupted, and if so, throws * an exception. * - * @return the least integer bigger or equal to the number, if int can hold the value. + * @return the least integer bigger or equal to the number. */ public final NumberInterface ceiling(){ checkInterrupted(); @@ -192,7 +192,7 @@ public abstract class NumberInterface { /** * Return the greatest integer less than or equal to the number. * - * @return the greatest integer smaller or equal the number, if int can hold the value. + * @return the greatest integer smaller or equal the number. */ protected abstract NumberInterface floorInternal(); @@ -201,7 +201,7 @@ public abstract class NumberInterface { * Also, checks if the thread has been interrupted, and if so, throws * an exception. * - * @return the greatest int smaller or equal to the number, if int can hold the value. + * @return the greatest int smaller than or equal to the number. */ public final NumberInterface floor(){ checkInterrupted(); @@ -216,7 +216,7 @@ public abstract class NumberInterface { protected abstract NumberInterface fractionalPartInternal(); /** - * Returns the fractional part of the number. + * Returns the fractional part of the number, specifically x - floor(x). * Also, checks if the thread has been interrupted, * and if so, throws an exception. * @return the fractional part of the number. diff --git a/src/main/java/org/nwapw/abacus/number/PreciseNumber.java b/src/main/java/org/nwapw/abacus/number/PreciseNumber.java index abc657f..7d288b7 100755 --- a/src/main/java/org/nwapw/abacus/number/PreciseNumber.java +++ b/src/main/java/org/nwapw/abacus/number/PreciseNumber.java @@ -113,19 +113,18 @@ public class PreciseNumber extends NumberInterface { String str = value.toPlainString(); int decimalIndex = str.indexOf('.'); if (decimalIndex != -1) { - return new PreciseNumber(str.substring(0, decimalIndex)); + NumberInterface floor = new PreciseNumber(str.substring(0, decimalIndex)); + if(signum() == -1){ + floor = floor.subtract(ONE); + } + return floor; } return this; } @Override public NumberInterface fractionalPartInternal() { - String str = value.toPlainString(); - int decimalIndex = str.indexOf('.'); - if (decimalIndex != -1) { - return new PreciseNumber(str.substring(decimalIndex + 1)); - } - return ZERO; + return this.subtractInternal(floorInternal()); } @Override diff --git a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index 363af7e..4d8aea2 100755 --- a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java +++ b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java @@ -340,7 +340,8 @@ public class StandardPlugin extends Plugin { protected boolean matchesParams(NumberInterface[] params) { return params.length == 2 && !(params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0 - && params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) == 0); + && params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) == 0) + && !(params[0].signum() == -1 && params[1].fractionalPart().compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) != 0); } @Override @@ -349,6 +350,13 @@ public class StandardPlugin extends Plugin { return NaiveNumber.ZERO.promoteTo(params[0].getClass()); else if (params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0) return NaiveNumber.ONE.promoteTo(params[1].getClass()); + //Detect integer bases: + if(params[0].fractionalPart().compareTo(fromInt(params[0].getClass(), 0)) == 0 + && FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), Integer.MAX_VALUE)) < 0 + && FUNCTION_ABS.apply(params[1]).compareTo(fromInt(params[1].getClass(), 1)) >= 0){ + NumberInterface[] newParams = {params[0], params[1].fractionalPart()}; + return params[0].intPow(params[1].floor().intValue()).multiply(applyInternal(newParams)); + } return FUNCTION_EXP.apply(FUNCTION_LN.apply(FUNCTION_ABS.apply(params[0])).multiply(params[1])); } });