From 553349133d8cd98b5f9d56779894015f15c8df1d Mon Sep 17 00:00:00 2001 From: Arthur Drobot Date: Mon, 7 Aug 2017 10:54:27 -0700 Subject: [PATCH 1/4] Improve some comments of NumberInterface functions. --- .../java/org/nwapw/abacus/number/NumberInterface.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/number/NumberInterface.java b/src/main/java/org/nwapw/abacus/number/NumberInterface.java index 7af5901..e997c7a 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 >= the number, if int can hold the value. + * @return the greatest int greater 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. From c636289d3c44bc91e879f2ce689ffadb6ba45355 Mon Sep 17 00:00:00 2001 From: Arthur Drobot Date: Mon, 7 Aug 2017 13:41:45 -0700 Subject: [PATCH 2/4] Modify some functions in PreciseNumber for consistency. --- .../java/org/nwapw/abacus/number/PreciseNumber.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 From d916772ddbda4f1553be404dc81b7287c96c3f1a Mon Sep 17 00:00:00 2001 From: Arthur Drobot Date: Mon, 7 Aug 2017 13:43:12 -0700 Subject: [PATCH 3/4] Optimize pow for integer bases. --- src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index 8dcfedb..62a732f 100755 --- a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java +++ b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java @@ -349,6 +349,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])); } }); From 584918e5d1ff42e5b2d2274d8ca075d164aa1de7 Mon Sep 17 00:00:00 2001 From: Arthur Drobot Date: Mon, 7 Aug 2017 14:05:15 -0700 Subject: [PATCH 4/4] Add checking of negative bases raised to non-integer powers in matchesParams in OP_CARET. --- src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java b/src/main/java/org/nwapw/abacus/plugin/StandardPlugin.java index 62a732f..e085e07 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