Skip to main content
1-Visitor
September 2, 2011
Question

Bug? Error in simple sum...

  • September 2, 2011
  • 5 replies
  • 8004 views

Hello,

I just stumbled upon the weird fact that for Prime1 certain sums are not absolutely correct. For example, Prime1 calculates

1.4 + 0.2 = 1.6

So far, so good.

But if I check if (1.4+0.2) is the same as 1.6, Prime1 tells me it is NOT!

When I create the difference it gives out

1.4 + 0.2 - 1.6 = 2.22*10^-16

which is almost correct but just not correct enough!

In the case of

1.2 + 0.4 = 1.6

Prime1 works correctly.

Please see the attached Prime1-sheet for further examples.

Is this a common error with any calculation software or is this just mathcad?

Is there a way to avoid this error?

Best regards

Sebastian

5 replies

24-Ruby IV
September 2, 2011

I think it is "a bug". We have same "bug" in Mathcad 15 when we have not 3-16 digits in rezult 1.4+.2-1.6= but 17 digits (maximum).

BUT why "a bug" not a bug!

The first rule by working with floating point (in Fortran, for example) - do not use the "exact equal" operator and use only the "approximately equal" (see the picture). We can use an "exact equal" operator only by working with strings, boolean, intrgers etc variables.
We must always remember it too by working with "smart" Mathcad .

AEqu.png

24-Ruby III
September 2, 2011

Hello!

Here what result turns out in Mathcad 15 M010 (so, there is no problem with that):

MC15.jpg

And in Mathcad Prime 1.0 (It is possible to see what numerical value is accepted for "0"):

Prime 1.0.jpg

24-Ruby IV
September 2, 2011

Mathcad 15

17.PNG

24-Ruby III
September 2, 2011

Above shows the result in Mathcad 15 with default settings (number of decimals: 3).

1-Visitor
September 2, 2011

Have you formatted the results?

Increased the exponential threshold?

Mike

1-Visitor
September 2, 2011

The difference between Mathcad 15 and earlier versions and Mathcad Prime 1.0, is that Mathcad Prime displays small numbers unlike Mathcad 15.0 which displays small numbers as 0. It's an issue of floating point precision on computers. I am raising this issue with the developers since it came up in another context.

However, if this is evaluated symbolically, it shows the expected result.

zero.png

Mona

1-Visitor
September 2, 2011

Mathcad Prime 1.0 has double point floating point precision. It's not possible to represent some numbers, due to rounding errors.

If you look at the Formatting tab, you will see that we chose General as the default Result Format, so that small numbers would be displayed, such as Plank's constant:

plancks.png

If you want your small zero's to display as zero, then switch to Decimal in the Result Format, as you see above.

We are discussing ways to increase Mathcad's precision in the future, but that will have an effect on performance.

Mona

24-Ruby IV
September 3, 2011

See please the picture:

bug1-2.png

You can change a & b values in attached Mathcad-sheet and see new answer of the a-b operator

PS We have yet discussed this "bug".

10-Marble
November 28, 2020

I know this is an ancient thread, but it's the first one I found about this.

Anyway, there is an option to calculate approximate equalities by default:

http://support.ptc.com/help/mathcad/en/index.html#page/PTC_Mathcad_Help/to_set_calculation_options.html