Page 1 of 1
Floating Point Errors
Posted: Fri Aug 20, 2021 9:30 am
by MJuric
So I was doing some excel stuff yesterday and ran into what I would consider an egregious rounding error. Turns out it's a floating point issue that in my opinion is just handled very poorly. I wanted to check the exact same calculation in SW but not sure if it can be done.
Essentially most/many "ROUNDUP" functions in excel that are supposed to land on an exact integer that is rounded to zero decimals, ends up rounding up to the next integer. So for instance 11.21-10.21, which equals one, ROUNDUP to 2 because excel sees this as 1.0000000010000. So =ROUNDUP((11.21-10.21),0) gives you "2" rather than "1" like it should in Excel.
I don't see availability of roundup in the functions for equations and it didn't seem to work the way I formatted it so I thought I'd check here and see if it is possible or not.
Re: Floating Point Errors
Posted: Fri Aug 20, 2021 10:33 am
by AlexB
A quick work-around to round up in the equations editor is to add one and then convert it to an integer.
I can tell you that there is some floating point error within solidworks like you're seeing in excel. If I am looking to see if a value is equal to another value, I'll typically do the following.
Instead of checking if the values are equal, I'll calculate the difference of the two values and check if it's less than an "almost zero" value.
Edit: wording
Re: Floating Point Errors
Posted: Fri Aug 20, 2021 10:49 am
by josh
Is there something else you have to do to make this =2?
- image.png (3.58 KiB) Viewed 992 times
Re: Floating Point Errors
Posted: Fri Aug 20, 2021 11:49 am
by MJuric
josh wrote: ↑Fri Aug 20, 2021 10:49 am
Is there something else you have to do to make this =2?
image.png
Nope, apparently it's rather random since it's a FP error. Change that to a number and extend it out to 30 decimal places. Below are a bunch of simple subtraction, division etc problems that I did yesterday.
For some reason addition seems to work flawlessly.
Re: Floating Point Errors
Posted: Fri Aug 20, 2021 11:53 am
by MJuric
AlexB wrote: ↑Fri Aug 20, 2021 10:33 am
A quick work-around to round up in the equations editor is to add one and then convert it to an integer.
image.png
I can tell you that there is some floating point error within solidworks like you're seeing in excel. If I am looking to see if a value is equal to another value, I'll typically do the following.
Instead of checking if the values are equal, I'll calculate the difference of the two values and check if it's less than an "almost zero" value.
image.png
Edit: wording
There's defiantly FP issues in SW but I've not seen so many cases that are so egregious. For instance I created a Driveworks model that did these same calcs and it always came back with the correct numbers.
The "Work around" I got from an Excel forum is to ROUND the calculation so you can't just enter A1-B1 because instead of 1 you get 1.000000001 and if you round that up you get 2. So you have to ROUNDUP(ROUND((A1-B1),6 ),0). My guess is that SW probably does that lower level rounding inside the software somehow.