Why does cosf(angle) or any cos function sometimes gives me negative number example (from -1 to 1 )but when i calculate it on a calculator... it never gives me a negative value
It certainly should not be negative. Do this: std::cout << "cos(theta) = " << cosf(angle * M_PI / 180) << ", where theta = " << angle << " deg, = " << angle * M_PI / 180 << " rad\n";
When angle is 45, this should write:
cos(theta) = 0.7, where theta = 45 deg, = 0.78 rad
See what you get.