samedi 23 avril 2016

C++ Same Equation but different results with (Calculator vs C++) [duplicate]

This question already has an answer here:

I have been working on a short project the last two days, but now everything falls apart, because there is one equation which returns 8.660254 when calculated in a C++/C# program but 0 when you try to calculate it by hand or with a calculator.

Equation:

float mgr1 = (x + tr * 0.5f - tr / 2) * 1.73205f * 10.0f;

In my case:

x = 0;
tr = 1;
float mgr1 = (0 + 1 * 0.5f - 1 / 2) * 1.73205f * 10.0f;

The right result is 0 but when calculated in C++, like this, it returns 8.660254? Am I getting crazy? Is there something about C++ which I do not know? What is it?

enter image description here

enter image description here

Aucun commentaire:

Enregistrer un commentaire