5

I have this code:

#include <iostream>

int main()
{
    double A = 1e3000000;
    double B = 0;
    double C = A * B;

    std::cout << "A = " << A << "\n";
    std::cout << "B = " << B << "\n";
    std::cout << "C = " << C << "\n";
}

Output:

A = inf
B = 0
C = -nan

Why is C negative? I tested this with clang 17 and also with online C++ compiler.

green lantern
  • 1,086
  • 7
  • 10

0 Answers0