SDXorg / test-models

A collection of System Dynamics models implemented in various environments with a canonical output
MIT License
27 stars 22 forks source link

rounding model has unexpected values due to numeric error #81

Closed enekomartinmartinez closed 3 years ago

enekomartinmartinez commented 3 years ago

test: rounding

We expect StockA to take values from -5 to 5 in intervals of 0.1. However, Integ sometimes returns non-exact values. For example, we can see in the output that StockA has value 3, but StockA modulo 3 has also value 3 which makes no sense. What is happening is that when running Vensim is taking 2.999999999... instead of 3, which is the expected value.

I will update the model using a variable instead of INTEG to generate the MODULO and INTEGER inputs.

JamesPHoughton commented 3 years ago

Is this a problem with the test model, or with Vensim? Should we pass this along to Ventana?

enekomartinmartinez commented 3 years ago

@JamesPHoughton I think that the problem is with Vensim. While running Vensim the output from INTEG should be rounded taking into account the numerical precision of Vensim to properly compute the MODULO or INTEGER. I have updated the model in a PR, so we can test MODULO and INTEGER without worrying about the numerical error. Maybe, we can keep the old one and inform Ventana.

JamesPHoughton commented 3 years ago

Great. Sent you an email with contact info. I'd suggest simplifying the test model to show only that issue, and a fresh output, and passing them along to Tom via email.

enekomartinmartinez commented 3 years ago

Fine, I have just noticed that the bug happens only when running vensim in single precision but not in double.