org.snapscript.tree.math.DoubleCalculator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.math;
import org.snapscript.core.variable.Value;
import org.snapscript.core.variable.ValueCache;
public class DoubleCalculator extends LongCalculator {
@Override
public Value add(Number left, Number right) {
double first = left.doubleValue();
double second = right.doubleValue();
return ValueCache.getDouble(first + second);
}
@Override
public Value subtract(Number left, Number right) {
double first = left.doubleValue();
double second = right.doubleValue();
return ValueCache.getDouble(first - second);
}
@Override
public Value divide(Number left, Number right) {
double first = left.doubleValue();
double second = right.doubleValue();
return ValueCache.getDouble(first / second);
}
@Override
public Value multiply(Number left, Number right) {
double first = left.doubleValue();
double second = right.doubleValue();
return ValueCache.getDouble(first * second);
}
@Override
public Value modulus(Number left, Number right) {
double first = left.doubleValue();
double second = right.doubleValue();
return ValueCache.getDouble(first % second);
}
}