Skip to content

Commit

Permalink
Small improvements to the formula parser
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Herzog committed Jul 18, 2020
1 parent 804a66d commit 682ad4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ public final class CalcSymbolPreOperatorCos extends CalcSymbolPreOperator {
@Override
protected double calc(double[] parameters) throws MathCalcError {
if (parameters.length!=1) throw error();
return Math.cos(parameters[0]);
final double d=Math.cos(parameters[0]);
return (Math.abs(d)<2E-16)?0.0:d;
}

@Override
protected double calcOrDefault(final double[] parameters, final double fallbackValue) {
if (parameters.length!=1) return fallbackValue;
return Math.cos(parameters[0]);
final double d=Math.cos(parameters[0]);
return (Math.abs(d)<2E-16)?0.0:d;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ public final class CalcSymbolPreOperatorSin extends CalcSymbolPreOperator {
@Override
protected double calc(double[] parameters) throws MathCalcError {
if (parameters.length!=1) throw error();
return Math.sin(parameters[0]);
final double d=Math.sin(parameters[0]);
return (Math.abs(d)<2E-16)?0.0:d;
}

@Override
protected double calcOrDefault(final double[] parameters, final double fallbackValue) {
if (parameters.length!=1) return fallbackValue;
return Math.sin(parameters[0]);
final double d=Math.sin(parameters[0]);
return (Math.abs(d)<2E-16)?0.0:d;
}

@Override
Expand Down

0 comments on commit 682ad4a

Please sign in to comment.