Incorrect Math Answer
btd (2)

Whenever I type this C++ code segment, i get an answer of 1.32679e-06. Does anyone know why this happens, or how to make the cosine of pi divided by 2 equal zero? It's a radians measurement, not a degrees measurement.

#include <iostream>
#include <cmath>
using namespace std;

int main()
const double PI = 3.14159;

cout << "cos(PI / 2) = " << cos(PI / 2) << "\n\n";

return 0;

You are viewing a single comment. View All
SPQR (332)

You'll probably never get exactly 0, but you can get much closer (0.0000000000000000612323) by using M_PI as I did here.