-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Floating point error in currentTime and stepSize? #14
Comments
This is a fundamental problem of floating-point arithmetic: It is only possible to exactly represent numbers on the form So you're right, if you start at 0 and add 0.1 ten times, you don't get 1. Assuming double precision, you actually get a number which is 1.1e-16 too small. (I wrote a small program to check.) If you keep adding 0.1 until you reach what should have been one million, the discrepancy has grown to -1.6e-4. But if we're talking simulated seconds here, that would amount to 278 hours, which is a pretty long simulation. :-) So it's definitely a thing, and there is going to be some drift, but I am having trouble coming up with cases where that would be a problem. The important thing is that if But I am very interested to hear some more specific examples of where that might pose a problem! |
Just a few more thoughts: Firstly, I guess there could be an issue if user code keeps time in single precision, i.e., as a Secondly, I thought of a case where small errors in time step length could really matter, and that is if user code performs numerical differentiation using the step size (or a fraction thereof) as the time differential. For example,
Thirdly, the FMI 2.0 spec (sec. 4.2.2) says the following about why
(Some formatting was lost in the paste; the s'es and i's should be subscripts.) |
Had some discussions with Christian Steinebach where he mentioned that simulations they have performed in a tool using HLA had issues due to floating point inaccuracies in current simulation time and step size.
Example:
The situation below is what we would expect with a stepSize set to 0.1
The situation below is what can happen with a stepSize set to 0.1
Example End
The situation described by the above example will probably cause user code in the fmu on the following form to brake:
Also, if the step size in the execonf file is set to 0.1, but internally coral increments currentTime with a step size of 0.100...01, things might start to drift?
I'm not 100% sure whether this is a problem for us now, but this was Christians experience from the HLA tool, so we should probably give it some thought.
The text was updated successfully, but these errors were encountered: