How to play with floating point cos (x)! = Cos (x)

How to reproduce this behavior? https://isocpp.org/wiki/faq/newbie#floating-point-arith2

To be precise, in the following code the parameters xand yare equal; they can be equal to 1.0 or any other value.

void foo(double x, double y)
{
  double cos_x = cos(x);
  double cos_y = cos(y);
  // the behavior might depend on what in here
  if (cos_x != cos_y) {
    std::cout << "Huh?!?\n";  // You might end up here when x == y!!
  }
}

Some compiler options? Loop? Any idea?

+4
source share
1 answer

, : . , , , . , , , cos , cos. :

, cos (x), , tmp. cos (y) ( , ) cos (y) tmp, .. cos (x).

( ..), , cos . , ==.

+3

All Articles