From 19942e931bd3d8132a5b85273a0bec525a789240 Mon Sep 17 00:00:00 2001 From: lehtonen Date: Tue, 22 Dec 2015 10:59:19 +0000 Subject: [PATCH] Added @mod(x,y)@ function to internal solver and changed the current @IEEEremainder@ function to @rem(x,y)@ according to Modelica 3.3 specification. refs #6217 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@32145 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../semantum/sysdyn/solver/Environment.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java index 1a367696..baf91ac6 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java @@ -219,7 +219,21 @@ final public class Environment implements IEnvironment, ISystem { } }); - model.functions.put("IEEEremainder", new Fn1(2) { + model.functions.put("mod", new Fn1(2) { + + @Override + public Object evaluate(IEnvironment environment, int argc) { + Double x = (Double)environment.getValue(0); + Double y = (Double)environment.getValue(1); + return mod(x, y); + } + + double mod(double x, double y) { + return x - Math.floor(x/y)*y; + } + + }); + model.functions.put("rem", new Fn1(2) { @Override public Object evaluate(IEnvironment environment, int argc) { @@ -227,7 +241,7 @@ final public class Environment implements IEnvironment, ISystem { Double y = (Double)environment.getValue(1); return Math.IEEEremainder(x, y); } - + }); model.functions.put("ceil", new Fn1(1) { @@ -1125,5 +1139,5 @@ final public class Environment implements IEnvironment, ISystem { } private Set assigned = new HashSet(); - + } -- 2.47.1