From d916772ddbda4f1553be404dc81b7287c96c3f1a Mon Sep 17 00:00:00 2001 From: Arthur Drobot Date: Mon, 7 Aug 2017 13:43:12 -0700 Subject: [PATCH] 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])); } });