Class Real
java.lang.Object
calculator.atoms.Real
- All Implemented Interfaces:
Atom, Expression
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept method to implement the visitor design pattern to traverse arithmetic expressions.voidaccept method to implement the visitor design pattern to traverse arithmetic expressions.apply(BinaryFunction f, Atom a) Applies an Binary between two atoms of the same concrete type The function supposes that both atoms are of the same concrete typeApplies an operation on the atomapplies an operation between two RealsbooleanTwo Real expressions are equal if the values they contain are equalgetValue()getter method to obtain the value contained in the objectinthashCode()The method hashCode needs to be overridden it the equals method is overridden; otherwise there may be problems when you use your object in hashed collections such as HashMap, HashSet, LinkedHashSet.booleanReturns if the Real is representing -infinitybooleanisNan()Returns if the Real is representing NaNbooleanReturns if the Real is representing +infinitystatic RealminusInf()Returns a Real representing -infinitystatic Realnan()Returns a NaN Realstatic RealplusInf()Returns a Real representing +infinitytoString()
-
Field Details
-
scale
public static int scale -
context
-
-
Constructor Details
-
Real
Constructor method for a string- Parameters:
s- The string to be represented in the Real
-
Real
Constructor method for a BigDecimal- Parameters:
d- the BigDecimal to be represented in the Real
-
Real
public Real(double d) Constructor method for a double- Parameters:
d- The double to be represented in the Real
-
Real
public Real(int i) Constructor method- Parameters:
i- The int value to be contained in the object
-
-
Method Details
-
getValue
getter method to obtain the value contained in the object- Returns:
- The integer number contained in the object
-
nan
-
plusInf
Returns a Real representing +infinity- Returns:
- A new Real number representing +infinity
-
minusInf
Returns a Real representing -infinity- Returns:
- A new Real number representing -infinity
-
isMinusInf
public boolean isMinusInf()Returns if the Real is representing -infinity- Returns:
- if the Real is representing -infinity
-
isPlusInf
public boolean isPlusInf()Returns if the Real is representing +infinity- Returns:
- if the Real is representing +infinity
-
isNan
public boolean isNan()Returns if the Real is representing NaN- Returns:
- if the Real is representing NaN
-
accept
accept method to implement the visitor design pattern to traverse arithmetic expressions. Each real number will pass itself to the Atomvisitor object to get processed by the Atomvisitor. -
accept
accept method to implement the visitor design pattern to traverse arithmetic expressions. Each real number will pass itself to the visitor object to get processed by the visitor.- Specified by:
acceptin interfaceExpression- Parameters:
v- The visitor object
-
equals
-
hashCode
-
apply
-
apply
Description copied from interface:AtomApplies an Binary between two atoms of the same concrete type The function supposes that both atoms are of the same concrete type -
apply
Description copied from interface:AtomApplies an operation on the atom -
toString
-