mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 05:50:08 +00:00
use epsilon for numeric equals
This commit is contained in:
1 parent
7fe7dac57a
commit
76afd54d3c
1 file changed
+7
+7
@@ -3,14 +3,21 @@ package com.dfsek.terra.api.structures.parser.lang.operations.statements;
|
|||||||
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
import com.dfsek.terra.api.structures.parser.lang.Returnable;
|
||||||
import com.dfsek.terra.api.structures.parser.lang.operations.BinaryOperation;
|
import com.dfsek.terra.api.structures.parser.lang.operations.BinaryOperation;
|
||||||
import com.dfsek.terra.api.structures.tokenizer.Position;
|
import com.dfsek.terra.api.structures.tokenizer.Position;
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
public class EqualsStatement extends BinaryOperation<Object, Boolean> {
|
public class EqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||||
|
private static final double EPSILON = 0.000000001D;
|
||||||
|
|
||||||
public EqualsStatement(Returnable<Object> left, Returnable<Object> right, Position position) {
|
public EqualsStatement(Returnable<Object> left, Returnable<Object> right, Position position) {
|
||||||
super(left, right, position);
|
super(left, right, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean apply(Object left, Object right) {
|
public Boolean apply(Object left, Object right) {
|
||||||
|
if(left instanceof Number && right instanceof Number) {
|
||||||
|
return FastMath.abs(((Number) left).doubleValue() - ((Number) right).doubleValue()) <= EPSILON;
|
||||||
|
}
|
||||||
|
|
||||||
return left.equals(right);
|
return left.equals(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user