mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 15:30:09 -08:00
Format code.
This commit is contained in:
parent
e172108476
commit
6a65e66935
|
@ -1,9 +1,7 @@
|
||||||
package org.nwapw.abacus;
|
package org.nwapw.abacus;
|
||||||
|
|
||||||
import org.nwapw.abacus.config.Configuration;
|
import org.nwapw.abacus.config.Configuration;
|
||||||
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.PromotionManager;
|
import org.nwapw.abacus.number.PromotionManager;
|
||||||
import org.nwapw.abacus.parsing.LexerTokenizer;
|
import org.nwapw.abacus.parsing.LexerTokenizer;
|
||||||
import org.nwapw.abacus.parsing.ShuntingYardParser;
|
import org.nwapw.abacus.parsing.ShuntingYardParser;
|
||||||
|
@ -14,8 +12,6 @@ import org.nwapw.abacus.plugin.StandardPlugin;
|
||||||
import org.nwapw.abacus.tree.NumberReducer;
|
import org.nwapw.abacus.tree.NumberReducer;
|
||||||
import org.nwapw.abacus.tree.TreeNode;
|
import org.nwapw.abacus.tree.TreeNode;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main calculator class. This is responsible
|
* The main calculator class. This is responsible
|
||||||
* for piecing together all of the components, allowing
|
* for piecing together all of the components, allowing
|
||||||
|
@ -72,6 +68,7 @@ public class Abacus {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the promotion manager.
|
* Gets the promotion manager.
|
||||||
|
*
|
||||||
* @return the promotion manager.
|
* @return the promotion manager.
|
||||||
*/
|
*/
|
||||||
public PromotionManager getPromotionManager() {
|
public PromotionManager getPromotionManager() {
|
||||||
|
@ -139,6 +136,7 @@ public class Abacus {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number implementation.
|
* Gets the number implementation.
|
||||||
|
*
|
||||||
* @return the number implementation to use for creating numbers.
|
* @return the number implementation to use for creating numbers.
|
||||||
*/
|
*/
|
||||||
public NumberImplementation getNumberImplementation() {
|
public NumberImplementation getNumberImplementation() {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.nwapw.abacus.number.PreciseNumber;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plugin providing standard functions such as addition and subtraction to
|
* The plugin providing standard functions such as addition and subtraction to
|
||||||
|
@ -90,21 +89,6 @@ public class StandardPlugin extends Plugin {
|
||||||
return new NaiveNumber(Math.PI);
|
return new NaiveNumber(Math.PI);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
|
||||||
* The square root function.
|
|
||||||
*/
|
|
||||||
public static final NumberFunction FUNCTION_SQRT = new NumberFunction() {
|
|
||||||
@Override
|
|
||||||
public boolean matchesParams(NumberImplementation implementation, NumberInterface[] params) {
|
|
||||||
return params.length == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NumberInterface applyInternal(NumberImplementation implementation, NumberInterface[] params) {
|
|
||||||
return OP_CARET.apply(implementation, params[0], implementation.instanceForString(".5"));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* The implementation for the infinite-precision BigDecimal.
|
* The implementation for the infinite-precision BigDecimal.
|
||||||
*/
|
*/
|
||||||
|
@ -347,6 +331,52 @@ public class StandardPlugin extends Plugin {
|
||||||
return implementation.instanceForString(Long.toString(Math.round(Math.random() * params[0].floor().intValue())));
|
return implementation.instanceForString(Long.toString(Math.round(Math.random() * params[0].floor().intValue())));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* The caret / pow operator, ^
|
||||||
|
*/
|
||||||
|
public static final NumberOperator OP_CARET = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 2) {
|
||||||
|
@Override
|
||||||
|
public boolean matchesParams(NumberImplementation implementation, NumberInterface[] params) {
|
||||||
|
NumberInterface zero = implementation.instanceForString("0");
|
||||||
|
return params.length == 2
|
||||||
|
&& !(params[0].compareTo(zero) == 0
|
||||||
|
&& params[1].compareTo(zero) == 0)
|
||||||
|
&& !(params[0].signum() == -1 && params[1].fractionalPart().compareTo(zero) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NumberInterface applyInternal(NumberImplementation implementation, NumberInterface[] params) {
|
||||||
|
NumberInterface zero = implementation.instanceForString("0");
|
||||||
|
if (params[0].compareTo(zero) == 0)
|
||||||
|
return zero;
|
||||||
|
else if (params[1].compareTo(zero) == 0)
|
||||||
|
return implementation.instanceForString("1");
|
||||||
|
//Detect integer bases:
|
||||||
|
if (params[0].fractionalPart().compareTo(implementation.instanceForString("0")) == 0
|
||||||
|
&& FUNCTION_ABS.apply(implementation, params[1]).compareTo(implementation.instanceForString(Integer.toString(Integer.MAX_VALUE))) < 0
|
||||||
|
&& FUNCTION_ABS.apply(implementation, params[1]).compareTo(implementation.instanceForString("1")) >= 0) {
|
||||||
|
NumberInterface[] newParams = {params[0], params[1].fractionalPart()};
|
||||||
|
return params[0].intPow(params[1].floor().intValue()).multiply(applyInternal(implementation, newParams));
|
||||||
|
}
|
||||||
|
return FUNCTION_EXP.apply(implementation, FUNCTION_LN.apply(implementation, FUNCTION_ABS.apply(implementation, params[0])).multiply(params[1]));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* The square root function.
|
||||||
|
*/
|
||||||
|
public static final NumberFunction FUNCTION_SQRT = new NumberFunction() {
|
||||||
|
@Override
|
||||||
|
public boolean matchesParams(NumberImplementation implementation, NumberInterface[] params) {
|
||||||
|
return params.length == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NumberInterface applyInternal(NumberImplementation implementation, NumberInterface[] params) {
|
||||||
|
return OP_CARET.apply(implementation, params[0], implementation.instanceForString(".5"));
|
||||||
|
}
|
||||||
|
};
|
||||||
private static final HashMap<NumberImplementation, ArrayList<NumberInterface>> FACTORIAL_LISTS = new HashMap<>();
|
private static final HashMap<NumberImplementation, ArrayList<NumberInterface>> FACTORIAL_LISTS = new HashMap<>();
|
||||||
/**
|
/**
|
||||||
* The exponential function, exp(1) = e^1 = 2.71...
|
* The exponential function, exp(1) = e^1 = 2.71...
|
||||||
|
@ -386,37 +416,6 @@ public class StandardPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
|
||||||
* The caret / pow operator, ^
|
|
||||||
*/
|
|
||||||
public static final NumberOperator OP_CARET = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 2) {
|
|
||||||
@Override
|
|
||||||
public boolean matchesParams(NumberImplementation implementation, NumberInterface[] params) {
|
|
||||||
NumberInterface zero = implementation.instanceForString("0");
|
|
||||||
return params.length == 2
|
|
||||||
&& !(params[0].compareTo(zero) == 0
|
|
||||||
&& params[1].compareTo(zero) == 0)
|
|
||||||
&& !(params[0].signum() == -1 && params[1].fractionalPart().compareTo(zero) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NumberInterface applyInternal(NumberImplementation implementation, NumberInterface[] params) {
|
|
||||||
NumberInterface zero = implementation.instanceForString("0");
|
|
||||||
if (params[0].compareTo(zero) == 0)
|
|
||||||
return zero;
|
|
||||||
else if (params[1].compareTo(zero) == 0)
|
|
||||||
return implementation.instanceForString("1");
|
|
||||||
//Detect integer bases:
|
|
||||||
if (params[0].fractionalPart().compareTo(implementation.instanceForString("0")) == 0
|
|
||||||
&& FUNCTION_ABS.apply(implementation, params[1]).compareTo(implementation.instanceForString(Integer.toString(Integer.MAX_VALUE))) < 0
|
|
||||||
&& FUNCTION_ABS.apply(implementation, params[1]).compareTo(implementation.instanceForString("1")) >= 0) {
|
|
||||||
NumberInterface[] newParams = {params[0], params[1].fractionalPart()};
|
|
||||||
return params[0].intPow(params[1].floor().intValue()).multiply(applyInternal(implementation, newParams));
|
|
||||||
}
|
|
||||||
return FUNCTION_EXP.apply(implementation, FUNCTION_LN.apply(implementation, FUNCTION_ABS.apply(implementation, params[0])).multiply(params[1]));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* The sine function (the argument is interpreted in radians).
|
* The sine function (the argument is interpreted in radians).
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package org.nwapw.abacus.tree;
|
package org.nwapw.abacus.tree;
|
||||||
|
|
||||||
import org.nwapw.abacus.Abacus;
|
import org.nwapw.abacus.Abacus;
|
||||||
import org.nwapw.abacus.function.*;
|
import org.nwapw.abacus.function.NumberFunction;
|
||||||
|
import org.nwapw.abacus.function.NumberOperator;
|
||||||
|
import org.nwapw.abacus.function.TreeValueFunction;
|
||||||
|
import org.nwapw.abacus.function.TreeValueOperator;
|
||||||
import org.nwapw.abacus.number.NumberInterface;
|
import org.nwapw.abacus.number.NumberInterface;
|
||||||
import org.nwapw.abacus.number.PromotionManager;
|
import org.nwapw.abacus.number.PromotionManager;
|
||||||
import org.nwapw.abacus.number.PromotionResult;
|
import org.nwapw.abacus.number.PromotionResult;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user