30

4

I am trying to wrap my head around floating-point precision. Performing the following numeric operation:

```
275./6.*1.03692775514337
```

in **Mathematica** and **C++** and taking the difference of the two results in **~0.7e-14**. **I expected the difference to be zero** within my `$MachinePrecision`

of *~15.96*. C++ uses `double`

as variable type for each number. In addition C++ and Mathematica follow the IEEE 754, which should make division and multiplication *exactly rounded operations*.

In general I need to know why Mathematica is rounding multiplication and division differently than my C++ program, while both should yield the same result?

For anybody interested in the C++ code:

```
#include <iostream>
int main() {
std::cout << std::setprecision(17);
std::cout << 275./6.*1.03692775514337 - 47.52585544407112
return(0);
}
```

1Can you add the C++ code you used to the question and ideally the bit strings of the two resulting double precision numbers? This would make tracking down the differences (e.g. different order of operations) easier. – Thies Heidecke – 2017-12-10T20:45:16.737

1Mathematica rounds

`275./6.`

towards zero (on my machine) even though rounding away from zero introduces less absolute error. But what's you source of "Mathematica follow the IEEE 754"? – Coolwater – 2017-12-10T20:48:56.840@Coolwater know that you ask I am not even sure, but in its documentation (e.g. MachinePrecision in the Background & Context part) it mentions it several times so I assumed that they use it.

– Knowledge – 2017-12-11T07:34:04.287