1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-23 07:50:09 -08:00

Change the constructor for NumberNode

This commit is contained in:
Danila Fedorin 2017-07-28 14:47:34 -07:00
parent 9e3b550a15
commit eac4ce8600
2 changed files with 6 additions and 13 deletions

View File

@ -22,19 +22,10 @@ public class NumberNode extends TreeNode {
/** /**
* Creates a new number node with the given double value. * Creates a new number node with the given double value.
* @param value the value to use. * @param newNumber the number for which to create a number node.
*/ */
public NumberNode(double value){ public NumberNode(NumberInterface newNumber){
number = new NaiveNumber(value); this.number = newNumber;
}
/**
* Creates a new number node with the given string value, converted
* to a double.
* @param value the value.
*/
public NumberNode(String value){
this(Double.parseDouble(value));
} }
/** /**

View File

@ -5,6 +5,8 @@ import org.nwapw.abacus.function.OperatorType;
import org.nwapw.abacus.lexing.Lexer; import org.nwapw.abacus.lexing.Lexer;
import org.nwapw.abacus.lexing.pattern.Match; import org.nwapw.abacus.lexing.pattern.Match;
import org.nwapw.abacus.lexing.pattern.Pattern; import org.nwapw.abacus.lexing.pattern.Pattern;
import org.nwapw.abacus.number.NaiveNumber;
import org.nwapw.abacus.number.PreciseNumber;
import java.util.*; import java.util.*;
@ -170,7 +172,7 @@ public class TreeBuilder {
else return new UnaryPrefixNode(operator, applyTo); else return new UnaryPrefixNode(operator, applyTo);
} }
} else if(matchType == TokenType.NUM){ } else if(matchType == TokenType.NUM){
return new NumberNode(Double.parseDouble(source.substring(match.getFrom(), match.getTo()))); return new NumberNode(new NaiveNumber(Double.parseDouble(source.substring(match.getFrom(), match.getTo()))));
} else if(matchType == TokenType.FUNCTION){ } else if(matchType == TokenType.FUNCTION){
String functionName = source.substring(match.getFrom(), match.getTo()); String functionName = source.substring(match.getFrom(), match.getTo());
FunctionNode node = new FunctionNode(functionName); FunctionNode node = new FunctionNode(functionName);