1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-25 16:15:19 +00:00

Compare commits

..

11 Commits

7 changed files with 305 additions and 192 deletions

View File

@@ -1,12 +1,12 @@
package org.nwapw.abacus;
import org.nwapw.abacus.config.ConfigurationObject;
import org.nwapw.abacus.number.NaiveNumber;
import org.nwapw.abacus.number.NumberInterface;
import org.nwapw.abacus.parsing.LexerTokenizer;
import org.nwapw.abacus.parsing.ShuntingYardParser;
import org.nwapw.abacus.parsing.TreeBuilder;
import org.nwapw.abacus.plugin.ClassFinder;
import org.nwapw.abacus.plugin.NumberImplementation;
import org.nwapw.abacus.plugin.PluginManager;
import org.nwapw.abacus.plugin.StandardPlugin;
import org.nwapw.abacus.tree.NumberReducer;
@@ -16,7 +16,6 @@ import org.nwapw.abacus.window.Window;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
/**
* The main calculator class. This is responsible
@@ -25,10 +24,7 @@ import java.lang.reflect.InvocationTargetException;
*/
public class Abacus {
/**
* The default implementation to use for the number representation.
*/
public static final Class<? extends NumberInterface> DEFAULT_NUMBER = NaiveNumber.class;
public static final NumberImplementation DEFAULT_IMPLEMENTATION = StandardPlugin.IMPLEMENTATION_NAIVE;
/**
* The file used for saving and loading configuration.
*/
@@ -154,15 +150,10 @@ public class Abacus {
* @return the resulting number.
*/
public NumberInterface numberFromString(String numberString) {
Class<? extends NumberInterface> toInstantiate =
pluginManager.numberFor(configuration.getNumberImplementation());
if (toInstantiate == null) toInstantiate = DEFAULT_NUMBER;
NumberImplementation toInstantiate =
pluginManager.numberImplementationFor(configuration.getNumberImplementation());
if (toInstantiate == null) toInstantiate = DEFAULT_IMPLEMENTATION;
try {
return toInstantiate.getConstructor(String.class).newInstance(numberString);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
return toInstantiate.instanceForString(numberString);
}
}

View File

@@ -1,10 +1,6 @@
package org.nwapw.abacus.function;
import org.nwapw.abacus.number.NaiveNumber;
import org.nwapw.abacus.number.NumberInterface;
import org.nwapw.abacus.number.PreciseNumber;
import java.util.HashMap;
/**
* A function that operates on one or more
@@ -12,15 +8,6 @@ import java.util.HashMap;
*/
public abstract class Function {
/**
* A map to correctly promote different number implementations to each other.
*/
private static final HashMap<Class<? extends NumberInterface>, Integer> priorityMap =
new HashMap<Class<? extends NumberInterface>, Integer>() {{
put(NaiveNumber.class, 0);
put(PreciseNumber.class, 1);
}};
/**
* Checks whether the given params will work for the given function.
*

View File

@@ -1,7 +1,6 @@
package org.nwapw.abacus.number;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class PreciseNumber implements NumberInterface {
@@ -9,15 +8,15 @@ public class PreciseNumber implements NumberInterface {
/**
* The number one.
*/
static final PreciseNumber ONE = new PreciseNumber(BigDecimal.ONE);
public static final PreciseNumber ONE = new PreciseNumber(BigDecimal.ONE);
/**
* The number zero.
*/
static final PreciseNumber ZERO = new PreciseNumber(BigDecimal.ZERO);
public static final PreciseNumber ZERO = new PreciseNumber(BigDecimal.ZERO);
/**
* The number ten.
*/
static final PreciseNumber TEN = new PreciseNumber(BigDecimal.TEN);
public static final PreciseNumber TEN = new PreciseNumber(BigDecimal.TEN);
/**
* The value of the PreciseNumber.

View File

@@ -0,0 +1,75 @@
package org.nwapw.abacus.plugin;
import org.nwapw.abacus.number.NumberInterface;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
/**
* A class that holds data about a number implementation.
*/
public abstract class NumberImplementation {
/**
* The list of paths through which this implementation can be promoted.
*/
protected Map<Class<? extends NumberInterface>, Function<NumberInterface, NumberInterface>> promotionPaths;
/**
* The implementation class for this implementation.
*/
private Class<? extends NumberInterface> implementation;
/**
* The priority of converting into this number implementation.
*/
private int priority;
/**
* Creates a new number implementation with the given data.
* @param implementation the implementation class.
* @param priority the priority, higher -> more likely to be converted into.
*/
public NumberImplementation(Class<? extends NumberInterface> implementation, int priority){
this.implementation = implementation;
this.priority = priority;
promotionPaths = new HashMap<>();
}
/**
* Gets the list of all promotion paths this implementation can take.
* @return the map of documentation paths.
*/
public final Map<Class<? extends NumberInterface>, Function<NumberInterface, NumberInterface>> getPromotionPaths(){
return promotionPaths;
}
/**
* Gets the implementation class used by this implementation.
* @return the implementation class.
*/
public final Class<? extends NumberInterface> getImplementation(){
return implementation;
}
/**
* Gets the priority of this number implementation.
* @return the priority.
*/
public final int getPriority(){
return priority;
}
/**
* Abstract function to create a new instance from a string.
* @param string the string to create a number from.
* @return the resulting number.
*/
public abstract NumberInterface instanceForString(String string);
/**
* Get the instance of pi with the given implementation.
* @return pi
*/
public abstract NumberInterface instanceForPi();
}

View File

@@ -26,13 +26,9 @@ public abstract class Plugin {
*/
private Map<String, Operator> operators;
/**
* A hash map of operators mapped to their string names.
* The map of the number implementations this plugin provides.
*/
private Map<String, Class<? extends NumberInterface>> numbers;
/**
* A hash map of constant providers for each number type.
*/
private Map<Class<?>, java.util.function.Function<String, NumberInterface>> constantProviders;
private Map<String, NumberImplementation> numberImplementations;
/**
* The plugin manager in which to search for functions
* not inside this package,
@@ -55,8 +51,7 @@ public abstract class Plugin {
this.manager = manager;
functions = new HashMap<>();
operators = new HashMap<>();
numbers = new HashMap<>();
constantProviders = new HashMap<>();
numberImplementations = new HashMap<>();
enabled = false;
}
@@ -79,20 +74,12 @@ public abstract class Plugin {
}
/**
* Gets the list of all numbers provided by this plugin.
* Gets the list of number implementations provided by this plugin.
*
* @return the list of registered numbers.
* @return the list of registered number implementations.
*/
public final Set<String> providedNumbers() {
return numbers.keySet();
}
/**
* Gets the list of all constant providers provided by this plugin.
* @return the list of constant providers.
*/
public final Set<Class<?>> providedConstantProviders() {
return constantProviders.keySet();
public final Set<String> providedNumberImplementations(){
return numberImplementations.keySet();
}
/**
@@ -116,23 +103,13 @@ public abstract class Plugin {
}
/**
* Gets the class under the given name.
* Gets the number implementation under the given name.
*
* @param numberName the name of the class.
* @return the class, or null if the plugin doesn't provide it.
* @param name the name of the number implementation to look up.
* @return the number implementation associated with that name, or null if the plugin doesn't provide it.
*/
public final Class<? extends NumberInterface> getNumber(String numberName) {
return numbers.get(numberName);
}
/**
* Gets the constant provider for the given class.
*
* @param pluginClass the class for which to provide constants.
* @return the provider, or null, if the plugin doesn't provide it.
*/
public final java.util.function.Function<String, NumberInterface> getConstantProvider(Class<?> pluginClass){
return constantProviders.get(pluginClass);
public final NumberImplementation getNumberImplementation(String name){
return numberImplementations.get(name);
}
/**
@@ -154,8 +131,6 @@ public abstract class Plugin {
onDisable();
functions.clear();
operators.clear();
numbers.clear();
constantProviders.clear();
enabled = false;
}
@@ -183,29 +158,13 @@ public abstract class Plugin {
}
/**
* To be used in load(). Registers a number class
* with the plugin internally, which makes it possible
* for the user to select it as an "implementation" for the
* number that they would like to use.
*
* @param name the name to register it under.
* @param toRegister the class to register.
* To be used in load(). Registers a new number implementation with the plugin.
* This makes it accessible to the plugin manager.
* @param name the name of the implementation.
* @param implementation the actual implementation class to register.
*/
protected final void registerNumber(String name, Class<? extends NumberInterface> toRegister) {
numbers.put(name, toRegister);
}
/**
* To be used in load(). Registers a constant provider
* with the plugin internally, which makes it possible
* for the calculations to look up constants for each different
* number type.
* @param providerFor the class the provider works with.
* @param constantProvider the provider to register.
*/
protected final void registerConstantProvider(Class<?> providerFor,
java.util.function.Function<String, NumberInterface> constantProvider) {
constantProviders.put(providerFor, constantProvider);
protected final void registerNumberImplementation(String name, NumberImplementation implementation){
numberImplementations.put(name, implementation);
}
/**
@@ -233,27 +192,27 @@ public abstract class Plugin {
}
/**
* Searches the PluginManager for the given number implementation.
* This can be used by the plugins internally in order to
* find classes by name that they do not provide.
* Searches the PluginManager for the given number implementation
* name. This can be used by the plugins internally in order to find
* implementations that they do not provide.
*
* @param name the name for which to search
* @return the resulting number class.
* @param name the name for which to search.
* @return the resulting number implementation, or null if none was found.
*/
protected final Class<? extends NumberInterface> numberFor(String name) {
return manager.numberFor(name);
protected final NumberImplementation numberImplementationFor(String name){
return manager.numberImplementationFor(name);
}
/**
* Searches the PluginManager for the given constant provider.
* This can be used by the plugins internally in order
* to find constant providers for number provider they do not provide.
*
* @param forClass the class for which to get a generator for.
* @return the resulting generator
* Searches the plugin manager for a Pi value for the given number implementation.
* This is done so that number implementations with various degrees of precision
* can provide their own pi values, without losing said precision by
* promoting NaiveNumbers.
* @param forClass the class to which to find the pi instance.
* @return the pi value for the given class.
*/
protected final java.util.function.Function<String, NumberInterface> constantProviderFor(Class<?> forClass){
return manager.constantProviderFor(forClass);
protected final NumberInterface getPi(Class<? extends NumberInterface> forClass){
return manager.piFor(forClass);
}
/**

View File

@@ -32,15 +32,19 @@ public class PluginManager {
*/
private Map<String, Operator> cachedOperators;
/**
* List of registered number implementations that have
* The list of number implementations that have
* been cached, that is, found in a plugin and returned.
*/
private Map<String, Class<? extends NumberInterface>> cachedNumbers;
private Map<String, NumberImplementation> cachedNumberImplementations;
/**
* List of registered constant providers for every
* number class.
* The list of number implementations that have been
* found by their implementation class.
*/
private Map<Class<?>, java.util.function.Function<String, NumberInterface>> cachedConstantProviders;
private Map<Class<? extends NumberInterface>, NumberImplementation> cachedInterfaceImplementations;
/**
* The pi values for each implementation class that have already been computer.
*/
private Map<Class<? extends NumberInterface>, NumberInterface> cachedPi;
/**
* List of all functions loaded by the plugins.
*/
@@ -50,13 +54,9 @@ public class PluginManager {
*/
private Set<String> allOperators;
/**
* List of all numbers loaded by the plugins.
* List of all the number implementations loaded by the plugins.
*/
private Set<String> allNumbers;
/**
* List of all the constant providers loaded by the plugins.
*/
private Set<Class<?>> allConstantProviders;
private Set<String> allNumberImplementations;
/**
* The list of plugin listeners attached to this instance.
*/
@@ -70,12 +70,12 @@ public class PluginManager {
plugins = new HashSet<>();
cachedFunctions = new HashMap<>();
cachedOperators = new HashMap<>();
cachedNumbers = new HashMap<>();
cachedConstantProviders = new HashMap<>();
cachedNumberImplementations = new HashMap<>();
cachedInterfaceImplementations = new HashMap<>();
cachedPi = new HashMap<>();
allFunctions = new HashSet<>();
allOperators = new HashSet<>();
allNumbers = new HashSet<>();
allConstantProviders = new HashSet<>();
allNumberImplementations = new HashSet<>();
listeners = new HashSet<>();
}
@@ -133,22 +133,51 @@ public class PluginManager {
}
/**
* Gets a numer implementation under the given name.
*
* Gets the number implementation under the given name.
* @param name the name of the implementation.
* @return the implementation class
* @return the implementation.
*/
public Class<? extends NumberInterface> numberFor(String name) {
return searchCached(plugins, cachedNumbers, Plugin::providedNumbers, Plugin::getNumber, name);
public NumberImplementation numberImplementationFor(String name){
return searchCached(plugins, cachedNumberImplementations, Plugin::providedNumberImplementations,
Plugin::getNumberImplementation, name);
}
/**
* Gets the constant provider for the given class.
* @param forClass the class to get the provider for.
* @return the provider.
* Gets the number implementation for the given implementation class.
* @param name the class for which to find the implementation.
* @return the implementation.
*/
public java.util.function.Function<String, NumberInterface> constantProviderFor(Class<?> forClass){
return searchCached(plugins, cachedConstantProviders, Plugin::providedConstantProviders, Plugin::getConstantProvider, forClass);
public NumberImplementation interfaceImplementationFor(Class<? extends NumberInterface> name){
if(cachedInterfaceImplementations.containsKey(name)) return cachedInterfaceImplementations.get(name);
NumberImplementation toReturn = null;
outside:
for(Plugin plugin : plugins){
for(String implementationName : plugin.providedNumberImplementations()){
NumberImplementation implementation = plugin.getNumberImplementation(implementationName);
if(implementation.getImplementation().equals(name)) {
toReturn = implementation;
break outside;
}
}
}
cachedInterfaceImplementations.put(name, toReturn);
return toReturn;
}
/**
* Gets the mathematical constant pi for the given implementation class.
* @param forClass the class for which to find pi.
* @return pi
*/
public NumberInterface piFor(Class<? extends NumberInterface> forClass){
if(cachedPi.containsKey(forClass)) return cachedPi.get(forClass);
NumberImplementation implementation = interfaceImplementationFor(forClass);
NumberInterface generatedPi = null;
if(implementation != null){
generatedPi = implementation.instanceForPi();
}
cachedPi.put(forClass, generatedPi);
return generatedPi;
}
/**
@@ -185,8 +214,7 @@ public class PluginManager {
for (Plugin plugin : plugins) {
allFunctions.addAll(plugin.providedFunctions());
allOperators.addAll(plugin.providedOperators());
allNumbers.addAll(plugin.providedNumbers());
allConstantProviders.addAll(plugin.providedConstantProviders());
allNumberImplementations.addAll(plugin.providedNumberImplementations());
}
listeners.forEach(e -> e.onLoad(this));
}
@@ -198,8 +226,7 @@ public class PluginManager {
for (Plugin plugin : plugins) plugin.disable();
allFunctions.clear();
allOperators.clear();
allNumbers.clear();
allConstantProviders.clear();
allNumberImplementations.clear();
listeners.forEach(e -> e.onUnload(this));
}
@@ -230,20 +257,12 @@ public class PluginManager {
}
/**
* Gets all the number implementations loaded by the Plugin Manager
* Gets all the number implementations loaded by the Plugin Manager.
*
* @return the set of all implementations that were loaded
* @return the set of all implementations that were loaded.
*/
public Set<String> getAllNumbers() {
return allNumbers;
}
/**
* Gets all the constant providers loaded by the Plugin Manager.
* @return the set of all constant providers that were loaded.
*/
public Set<Class<?>> getAllConstantProviders() {
return allConstantProviders;
public Set<String> getAllNumberImplementations(){
return allNumberImplementations;
}
/**

View File

@@ -8,7 +8,6 @@ import org.nwapw.abacus.number.NaiveNumber;
import org.nwapw.abacus.number.NumberInterface;
import org.nwapw.abacus.number.PreciseNumber;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.function.BiFunction;
@@ -20,7 +19,6 @@ import java.util.function.BiFunction;
public class StandardPlugin extends Plugin {
private static HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>> factorialLists = new HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>>();
static HashMap<Class<? extends NumberInterface>, NumberInterface> piValues = new HashMap<Class<? extends NumberInterface>, NumberInterface>();
/**
* The addition operator, +
@@ -97,7 +95,9 @@ public class StandardPlugin extends Plugin {
//private HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>> storedList = new HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>>();
@Override
protected boolean matchesParams(NumberInterface[] params) {
return params.length == 1;
return params.length == 1
&& params[0].fractionalPart().compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0
&& params[0].signum() >= 0;
}
@Override
@@ -285,7 +285,7 @@ public class StandardPlugin extends Plugin {
/**
* The sine function (the argument is interpreted in radians).
*/
public static final Function FUNCTION_SIN = new Function() {
public final Function functionSin = new Function() {
@Override
protected boolean matchesParams(NumberInterface[] params) {
return params.length == 1;
@@ -295,7 +295,7 @@ public class StandardPlugin extends Plugin {
protected NumberInterface applyInternal(NumberInterface[] params) {
NumberInterface pi = getPi(params[0].getClass());
NumberInterface twoPi = pi.multiply(new NaiveNumber(2).promoteTo(pi.getClass()));
NumberInterface theta = getSmallAngle(params[0]);
NumberInterface theta = getSmallAngle(params[0], pi);
//System.out.println(theta);
if(theta.compareTo(pi.multiply(new NaiveNumber(1.5).promoteTo(twoPi.getClass()))) >= 0){
theta = theta.subtract(twoPi);
@@ -308,6 +308,119 @@ public class StandardPlugin extends Plugin {
}
};
public final Function functionCos = new Function() {
@Override
protected boolean matchesParams(NumberInterface[] params) {
return params.length == 1;
}
@Override
protected NumberInterface applyInternal(NumberInterface[] params) {
return functionSin.apply(getPi(params[0].getClass()).divide(new NaiveNumber(2).promoteTo(params[0].getClass()))
.subtract(params[0]));
}
};
public final Function functionTan = new Function() {
@Override
protected boolean matchesParams(NumberInterface[] params) {
return params.length == 1;
}
@Override
protected NumberInterface applyInternal(NumberInterface[] params) {
return functionSin.apply(params[0]).divide(functionCos.apply(params[0]));
}
};
public final Function functionSec = new Function() {
@Override
protected boolean matchesParams(NumberInterface[] params) {
return params.length == 1;
}
@Override
protected NumberInterface applyInternal(NumberInterface[] params) {
return NaiveNumber.ONE.promoteTo(params[0].getClass()).divide(functionCos.apply(params[0]));
}
};
public final Function functionCsc = new Function() {
@Override
protected boolean matchesParams(NumberInterface[] params) {
return params.length == 1;
}
@Override
protected NumberInterface applyInternal(NumberInterface[] params) {
return NaiveNumber.ONE.promoteTo(params[0].getClass()).divide(functionSin.apply(params[0]));
}
};
public final Function functionCot = new Function() {
@Override
protected boolean matchesParams(NumberInterface[] params) {
return params.length == 1;
}
@Override
protected NumberInterface applyInternal(NumberInterface[] params) {
return functionCos.apply(params[0]).divide(functionCos.apply(params[0]));
}
};
/**
* The implementation for double-based naive numbers.
*/
public static final NumberImplementation IMPLEMENTATION_NAIVE = new NumberImplementation(NaiveNumber.class, 0) {
@Override
public NumberInterface instanceForString(String string) {
return new NaiveNumber(string);
}
@Override
public NumberInterface instanceForPi() {
return new NaiveNumber(Math.PI);
}
};
/**
* The implementation for the infinite-precision BigDecimal.
*/
public static final NumberImplementation IMPLEMENTATION_PRECISE = new NumberImplementation(PreciseNumber.class, 0) {
@Override
public NumberInterface instanceForString(String string) {
return new PreciseNumber(string);
}
@Override
public NumberInterface instanceForPi() {
NumberInterface C = FUNCTION_SQRT.apply(new PreciseNumber("10005")).multiply(new PreciseNumber("426880"));
NumberInterface M = PreciseNumber.ONE;
NumberInterface L = new PreciseNumber("13591409");
NumberInterface X = M;
NumberInterface sum = L;
int termsNeeded = C.getMaxPrecision()/13 + 1;
NumberInterface lSummand = new PreciseNumber("545140134");
NumberInterface xMultiplier = new PreciseNumber("262537412")
.multiply(new PreciseNumber("1000000000"))
.add(new PreciseNumber("640768000"))
.negate();
for(int i = 0; i < termsNeeded; i++){
M = M
.multiply(new NaiveNumber(12*i+2).promoteTo(PreciseNumber.class))
.multiply(new NaiveNumber(12*i+6).promoteTo(PreciseNumber.class))
.multiply(new NaiveNumber(12*i+10).promoteTo(PreciseNumber.class))
.divide(new NaiveNumber(Math.pow(i+1,3)).promoteTo(PreciseNumber.class));
L = L.add(lSummand);
X = X.multiply(xMultiplier);
sum = sum.add(M.multiply(L).divide(X));
}
return C.divide(sum);
}
};
public StandardPlugin(PluginManager manager) {
super(manager);
}
@@ -340,8 +453,8 @@ public class StandardPlugin extends Plugin {
@Override
public void onEnable() {
registerNumber("naive", NaiveNumber.class);
registerNumber("precise", PreciseNumber.class);
registerNumberImplementation("naive", IMPLEMENTATION_NAIVE);
registerNumberImplementation("precise", IMPLEMENTATION_PRECISE);
registerOperator("+", OP_ADD);
registerOperator("-", OP_SUBTRACT);
@@ -354,7 +467,12 @@ public class StandardPlugin extends Plugin {
registerFunction("exp", FUNCTION_EXP);
registerFunction("ln", FUNCTION_LN);
registerFunction("sqrt", FUNCTION_SQRT);
registerFunction("sin", FUNCTION_SIN);
registerFunction("sin", functionSin);
registerFunction("cos", functionCos);
registerFunction("tan", functionTan);
registerFunction("sec", functionSec);
registerFunction("csc", functionCsc);
registerFunction("cot", functionCot);
}
@Override
@@ -402,48 +520,13 @@ public class StandardPlugin extends Plugin {
return sum;
}
/**
* Returns an approximation of Pi, with appropriate accuracy for given number class.
* @param numClass type of number.
* @return A number of class numClass, with value approximately Pi = 3.1415...
*/
public static NumberInterface getPi(Class<? extends NumberInterface> numClass){
if(!piValues.containsKey(numClass)){
//https://en.wikipedia.org/wiki/Chudnovsky_algorithm
NumberInterface C = FUNCTION_SQRT.apply(new NaiveNumber(10005).promoteTo(numClass)).multiply(new NaiveNumber(426880).promoteTo(numClass));
NumberInterface M = NaiveNumber.ONE.promoteTo(numClass);
NumberInterface L = new NaiveNumber(13591409).promoteTo(numClass);
NumberInterface X = M;
NumberInterface sum = L;
int termsNeeded = C.getMaxPrecision()/13 + 1;
NumberInterface lSummand = new NaiveNumber(545140134).promoteTo(L.getClass());
NumberInterface xMultiplier = new NaiveNumber(262537412).promoteTo(X.getClass())
.multiply(new NaiveNumber(1000000000).promoteTo(X.getClass()))
.add(new NaiveNumber(640768000).promoteTo(X.getClass()))
.negate();
for(int i = 0; i < termsNeeded; i++){
M = M
.multiply(new NaiveNumber(12*i+2).promoteTo(M.getClass()))
.multiply(new NaiveNumber(12*i+6).promoteTo(M.getClass()))
.multiply(new NaiveNumber(12*i+10).promoteTo(M.getClass()))
.divide(new NaiveNumber(Math.pow(i+1,3)).promoteTo(M.getClass()));
L = L.add(lSummand);
X = X.multiply(xMultiplier);
sum = sum.add(M.multiply(L).divide(X));
}
piValues.put(numClass, C.divide(sum));
}
return piValues.get(numClass);
}
/**
* Returns an equivalent angle in the interval [0, 2pi)
* @param phi an angle (in radians).
* @return theta in [0, 2pi) that differs from phi by a multiple of 2pi.
*/
private static NumberInterface getSmallAngle(NumberInterface phi){
NumberInterface twoPi = getPi(phi.getClass()).multiply(new NaiveNumber("2").promoteTo(phi.getClass()));
private static NumberInterface getSmallAngle(NumberInterface phi, NumberInterface pi){
NumberInterface twoPi = pi.multiply(new NaiveNumber("2").promoteTo(phi.getClass()));
NumberInterface theta = FUNCTION_ABS.apply(phi).subtract(twoPi
.multiply(FUNCTION_ABS.apply(phi).divide(twoPi).floor())); //Now theta is in [0, 2pi).
if(phi.signum() < 0){