From 682ad4a72cc5c117f22924d41a296761f94f288c Mon Sep 17 00:00:00 2001 From: Alexander Herzog Date: Sat, 18 Jul 2020 21:15:11 +0200 Subject: [PATCH] Small improvements to the formula parser --- .../main/java/parser/symbols/CalcSymbolPreOperatorCos.java | 6 ++++-- .../main/java/parser/symbols/CalcSymbolPreOperatorSin.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/SimSystem/src/main/java/parser/symbols/CalcSymbolPreOperatorCos.java b/SimSystem/src/main/java/parser/symbols/CalcSymbolPreOperatorCos.java index a3cc2a2..cba3f79 100644 --- a/SimSystem/src/main/java/parser/symbols/CalcSymbolPreOperatorCos.java +++ b/SimSystem/src/main/java/parser/symbols/CalcSymbolPreOperatorCos.java @@ -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 diff --git a/SimSystem/src/main/java/parser/symbols/CalcSymbolPreOperatorSin.java b/SimSystem/src/main/java/parser/symbols/CalcSymbolPreOperatorSin.java index e68441d..7255487 100644 --- a/SimSystem/src/main/java/parser/symbols/CalcSymbolPreOperatorSin.java +++ b/SimSystem/src/main/java/parser/symbols/CalcSymbolPreOperatorSin.java @@ -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