diff --git a/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt b/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt index 3279af6..9b14ae9 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt @@ -221,6 +221,13 @@ abstract class NumberInterface: Comparable { return fractionalPartInternal() } + /** + * Checks whether the given number is an integer or not. + * + * @return whether the number is an integer or not. + */ + fun isInteger() = fractionalPart().signum() == 0 + /** * Returns a NumberRangeBuilder object, which is used to create a range. * The reason that this returns a builder and not an actual range is that diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorCaret.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorCaret.kt index c587ec9..75022a0 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorCaret.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorCaret.kt @@ -17,7 +17,7 @@ class OperatorCaret: NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BI override fun matchesParams(context: MutableEvaluationContext, params: Array) = params.size == 2 && !(params[0].signum() == 0 && params[1].signum() == 0) - && !(params[0].signum() == -1 && params[1].fractionalPart().signum() != 0) + && !(params[0].signum() == -1 && !params[1].isInteger()) override fun applyInternal(context: MutableEvaluationContext, params: Array): NumberInterface { val implementation = context.inheritedNumberImplementation @@ -26,7 +26,7 @@ class OperatorCaret: NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BI else if (params[1].signum() == 0) return implementation.instanceForString("1") //Detect integer bases: - if (params[0].fractionalPart().signum() == 0 + if (params[0].isInteger() && FUNCTION_ABS.apply(context, params[1]) < implementation.instanceForString(Integer.toString(Integer.MAX_VALUE)) && FUNCTION_ABS.apply(context, params[1]) >= implementation.instanceForString("1")) { val newParams = arrayOf(params[0], params[1].fractionalPart()) diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorFactorial.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorFactorial.kt index e520ecc..cc8e1fd 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorFactorial.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorFactorial.kt @@ -15,7 +15,7 @@ class OperatorFactorial: NumberOperator(OperatorAssociativity.LEFT, OperatorType override fun matchesParams(context: MutableEvaluationContext, params: Array) = params.size == 1 - && params[0].fractionalPart().signum() == 0 + && params[0].isInteger() && params[0].signum() >= 0 override fun applyInternal(context: MutableEvaluationContext, params: Array): NumberInterface { diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNcr.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNcr.kt index 22fea5a..67330ab 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNcr.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNcr.kt @@ -17,8 +17,8 @@ import org.nwapw.abacus.plugin.standard.StandardPlugin.OP_NPR class OperatorNcr: NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 0) { override fun matchesParams(context: MutableEvaluationContext, params: Array) = - params.size == 2 && params[0].fractionalPart().signum() == 0 - && params[1].fractionalPart().signum() == 0 + params.size == 2 && params[0].isInteger() + && params[1].isInteger() override fun applyInternal(context: MutableEvaluationContext, params: Array) = OP_NPR.apply(context, *params) / OP_FACTORIAL.apply(context, params[1]) diff --git a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNpr.kt b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNpr.kt index dfc9fd2..dd2aa94 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNpr.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/plugin/standard/operator/OperatorNpr.kt @@ -15,8 +15,8 @@ import org.nwapw.abacus.number.NumberInterface class OperatorNpr: NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 0) { override fun matchesParams(context: MutableEvaluationContext, params: Array) = - params.size == 2 && params[0].fractionalPart().signum() == 0 - && params[1].fractionalPart().signum() == 0 + params.size == 2 && params[0].isInteger() + && params[1].isInteger() override fun applyInternal(context: MutableEvaluationContext, params: Array): NumberInterface { val implementation = context.inheritedNumberImplementation