Floating Point Errors

MJuric
Posts: 1070
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
x 31
x 875

Floating Point Errors

Unread post 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.
User avatar
AlexB
Posts: 505
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 271
x 454

Re: Floating Point Errors

Unread post by AlexB »

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
User avatar
josh
Posts: 300
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 511

Re: Floating Point Errors

Unread post by josh »

Is there something else you have to do to make this =2?
image.png
image.png (3.58 KiB) Viewed 1010 times
MJuric
Posts: 1070
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
x 31
x 875

Re: Floating Point Errors

Unread post 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.
image.png
MJuric
Posts: 1070
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
x 31
x 875

Re: Floating Point Errors

Unread post 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.
Post Reply