Skip to main content
8-Gravel
July 13, 2025
Solved

Equal operation for comparison in Mathcad prime is not working

  • July 13, 2025
  • 3 replies
  • 1680 views

Hi there, as shown in the following screenshot, could someone kindly tell what is wrong with this mathcad operation? There are are same values of 6 inches. But still it is showing "NOT OK". I would be much obliged if someone can resolve my this problem.

 

Best answer by Werner_E

While you may think that both variables are of exact same value, that's not true.

You can see that there is a difference of slightly more than 10^-15 in and t.provided is actually smaller than t.required for that tiny amount. Hence you get "Not OK" as the answer.

Werner_E_0-1752403959155.png

These round-off errors or numerical inaccuracies are normal and to be expected. Tiny round-off errors when doing calculations or unit conversions (Prime stores internally in SI unit meter) are the cause.

Its a golden rule never to check float values for equality but rather for approximate equality.

So don't use "if a=b ..." but rather  "if |a-b| < 10^-10 ...". You decide for the level of accuracy and it does not matter if you use < or <=.

In your case you could cope with the problem by doing it that way:

Werner_E_1-1752404292005.png

10^-14 in might be too small for other values. You have to decide if an accuracy of 10^-6 in or 10^-8 in wouldn't be al you need.

 

To turn it into a function you could make the accuracy level a third function argument:

Werner_E_2-1752404422280.png

 

Or you may use

Werner_E_0-1752404759454.png

Here the third function argument represents the number of decimals needed as accuracy.

The division by the unit in does not affect the variables. Its just needed for the usage of "round".

You may also use the "Round" function (note the capital "R") to again provide the tolerance in inches as third argument:

Werner_E_1-1752405030536.png

A float value usually is said to be accurate up to 15 to 16 decimals. Given that 10^-15 meter is roughly 4*10^-14 inches, I would not expect a higher precision than 10^-14 inches. And round-off errors can accumulate if the value is derived by a series of calculations.

So demanding a precision of 10^-10 inches might be considered realistic but nonetheless ambitious. Normally I guess a much larger precision might suffice.

3 replies

21-Topaz II
July 13, 2025

Hi,

Very hard to actually diagnose problem without the worksheet.  Worksheets can be uploaded.

 

Check with many more decimal places for tprovided and trequired it could be round off errors.

 

Compare to a defined accuracy round(tprovided,3)>=round(trequired,3) works better.

 

Cheers

Terry

Minuteman8-GravelAuthor
8-Gravel
July 13, 2025

This is an incomplete mathcad file though. Only the simple mathcad operation is seeming to be wrong. It was supposed to show "OK" but showing "Not Ok" whereas the situation is like 6 inches = 6 inches. I have attached the whole file below

23-Emerald I
July 13, 2025

There's nothing wrong with Mathcad, you're experiencing small differences in actual numerical results and mathematical formatting:

 

Fred_Kohlhepp_0-1752397523751.png

 

Minuteman8-GravelAuthor
8-Gravel
July 13, 2025

Is there any solution to this one, please?

duo1663_0-1752398401041.png

 

21-Topaz II
July 13, 2025
Werner_E25-Diamond IAnswer
25-Diamond I
July 13, 2025

While you may think that both variables are of exact same value, that's not true.

You can see that there is a difference of slightly more than 10^-15 in and t.provided is actually smaller than t.required for that tiny amount. Hence you get "Not OK" as the answer.

Werner_E_0-1752403959155.png

These round-off errors or numerical inaccuracies are normal and to be expected. Tiny round-off errors when doing calculations or unit conversions (Prime stores internally in SI unit meter) are the cause.

Its a golden rule never to check float values for equality but rather for approximate equality.

So don't use "if a=b ..." but rather  "if |a-b| < 10^-10 ...". You decide for the level of accuracy and it does not matter if you use < or <=.

In your case you could cope with the problem by doing it that way:

Werner_E_1-1752404292005.png

10^-14 in might be too small for other values. You have to decide if an accuracy of 10^-6 in or 10^-8 in wouldn't be al you need.

 

To turn it into a function you could make the accuracy level a third function argument:

Werner_E_2-1752404422280.png

 

Or you may use

Werner_E_0-1752404759454.png

Here the third function argument represents the number of decimals needed as accuracy.

The division by the unit in does not affect the variables. Its just needed for the usage of "round".

You may also use the "Round" function (note the capital "R") to again provide the tolerance in inches as third argument:

Werner_E_1-1752405030536.png

A float value usually is said to be accurate up to 15 to 16 decimals. Given that 10^-15 meter is roughly 4*10^-14 inches, I would not expect a higher precision than 10^-14 inches. And round-off errors can accumulate if the value is derived by a series of calculations.

So demanding a precision of 10^-10 inches might be considered realistic but nonetheless ambitious. Normally I guess a much larger precision might suffice.

Minuteman8-GravelAuthor
8-Gravel
July 13, 2025

This explains well. Thank you for your elaborate explanation and help. This worked in eliminating the issue.