mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-24 00:10:09 -08:00
Add handling of edge cases to pow.
This commit is contained in:
parent
8215f3e98c
commit
9bf1aee92d
|
@ -8,6 +8,7 @@ import org.nwapw.abacus.number.NaiveNumber;
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
import org.nwapw.abacus.number.PreciseNumber;
|
import org.nwapw.abacus.number.PreciseNumber;
|
||||||
|
|
||||||
|
import javax.print.attribute.standard.MediaSize;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
@ -133,12 +134,20 @@ public class StandardPlugin extends Plugin {
|
||||||
public static final Operator OP_CARET = new Operator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 2, new Function() {
|
public static final Operator OP_CARET = new Operator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 2, new Function() {
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
protected boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 2;
|
return params.length == 2
|
||||||
|
&& !(params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0
|
||||||
|
&& params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NumberInterface applyInternal(NumberInterface[] params) {
|
protected NumberInterface applyInternal(NumberInterface[] params) {
|
||||||
return FUNCTION_EXP.apply(FUNCTION_LN.apply(params[0]).multiply(params[1]));
|
if(params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0){
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
return FUNCTION_EXP.apply(FUNCTION_LN.apply(FUNCTION_ABS.apply(params[0])).multiply(params[1]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user