Why does Mathematica results differ from C++ results within machine precision?

Something important to keep in mind is that Mathematica parses x / y as

Times[x, Power[y, -1]]

For actual floating point division, use Divide:

Divide[275., 6.]*1.03692775514337 // InputForm

(* 47.52585544407113 *)

which should agree with the C++ result.


Without code and your actual results, this question cannot be answered. Here is one thing that might help: We have a compiler that can compile to C it can show you the code it creates. So why don't you try this?

a = 275.;
b = 6.;
c = 1.03692775514337

fC = Compile[{{a, _Real}, {b, _Real}, {c, _Real}},
  a/b*c,
  CompilationTarget -> "C"
]

Now we can compare the two results:

fC[a, b, c] - (a/b*c)

This gives not difference on my machine. Let's look at the important part of the created C code:

<< CCodeGenerator`
CCodeStringGenerate[fC, "fun"]

With this, we get the core calculation:

mreal R0_0;
mreal R0_1;
mreal R0_2;
mreal R0_3;
mreal R0_4;
R0_0 = A1;
R0_1 = A2;
R0_2 = A3;
R0_3 = 1 / R0_1;
R0_4 = R0_0 * R0_3;
R0_4 = R0_4 * R0_2;
*Res = R0_4;

So the question is, how did you calculate the result?