Same with Math.cos(Math.PI/2) = 6.123233995736766e-17

Why is this happening?

I advance thank you for your help! ]]>

Same with Math.cos(Math.PI/2) = 6.123233995736766e-17

Why is this happening?

I advance thank you for your help! ]]>

e-16 in 1.2246467991473532e-16, i say about sin(pi) should be equal 0 as cos(pi/2) ]]>

e-16 in 1.2246467991473532e-16, i say about sin(pi) should be equal 0 as cos(pi/2)[/quote]

I'm afraid they are right, mate. With floating point, you cannot really get exactly 0, save for a few cases.

]]>e-16 in 1.2246467991473532e-16, i say about sin(pi) should be equal 0 as cos(pi/2)[/quote]

Well, 6.123233995736766e-17 ≈ 0, as far as floating point numbers are concerned.

]]>As Andre suggested, test it with an epsilon (small value) to see if it is in agreement with your criteria. i.e.

@

const double eps = 1.0e-10; // as an arbitrary example

double value = sin( pi ); // pi defined somewhere else

const double test = 0.0;

if ( qAbs( value - test ) < eps )

qDebug() << "Values agree within some small value epsilon";

@

Obviously you can use different values for eps and test as needed in your particular cases. This is just a fact of life when working with floating point representations on machines with limited memory.

]]>