Skip to main content
1-Visitor
March 12, 2015
Solved

Mathcad odd result

  • March 12, 2015
  • 8 replies
  • 2850 views

Please find attached the description of a bad result found by my colleague working with mathcad.

Does anyone have an explanation or solution to this issue?

Best Regards

Diego Signoretti

Best answer by athurin

This is down to the way computers store and handle numbers.

Unlike humans do, computers usually don't handle exact number. For instance, a number is stored on a limited amount of disk space, which means that a number can only have a limite number of decimal places. Think of pi, or e, and you will instantly see how that can be an issue.

The consequence of that is that every time you describe a number that doesn't have an exact representation in binary (wikipedia will explain how "float" are implemented), there are rounding errors.

In your particular example, 0.220m doesn't have an "exact" representation in binary, so the number that is actually used is the closest binary representation of it, and I think you will agree that an error that is 13 orders of magnitude smaller than what you are looking at is in most cases (not all, but most) negligible.

So here, you are comparing 2 numbers that are actually different. so the result is right. In my opinion, this should never happen though. I would expect from a software such as mathcad to define a=b as |a-b|<2*rounting error, but hey, that's not how it's implemented, unfortunately...

I hope that makes sense ...

8 replies

athurin1-VisitorAnswer
1-Visitor
March 12, 2015

This is down to the way computers store and handle numbers.

Unlike humans do, computers usually don't handle exact number. For instance, a number is stored on a limited amount of disk space, which means that a number can only have a limite number of decimal places. Think of pi, or e, and you will instantly see how that can be an issue.

The consequence of that is that every time you describe a number that doesn't have an exact representation in binary (wikipedia will explain how "float" are implemented), there are rounding errors.

In your particular example, 0.220m doesn't have an "exact" representation in binary, so the number that is actually used is the closest binary representation of it, and I think you will agree that an error that is 13 orders of magnitude smaller than what you are looking at is in most cases (not all, but most) negligible.

So here, you are comparing 2 numbers that are actually different. so the result is right. In my opinion, this should never happen though. I would expect from a software such as mathcad to define a=b as |a-b|<2*rounting error, but hey, that's not how it's implemented, unfortunately...

I hope that makes sense ...

1-Visitor
March 12, 2015

BTW : you will find the exact same problem in EXCEL, but, because OpenSource software programmers are usually smarter, it works just fine in LibreOffice.