I'm very confused with the issue. The code I am running is:
double dotProduct = dot(A, B);
std::cout << dotProduct << std::endl;
theta = acos(dotProduct);
std::cout << theta << std::endl;
The output of which is
-1
ANGLE: -nan(ind)
However, the following works:
double dotProduct = dot(A, B);
std::cout << dotProduct << std::endl;
dotProduct = -1;
theta = acos(dotProduct);
Giving the output:
-1
ANGLE: 3.14159
Also, if I cast dotProduct to a float, acos() outputs the angle correctly:
double dotProduct = dot(A, B);
std::cout << dotProduct << std::endl;
theta = acos((float) dotProduct);
Also resulting in the output
-1
ANGLE: 3.14159
For the dot() function, I am using the Armadillo library. What I don't understand is why acos() should work when I set dotProduct = -1, but will not when it is outputted by the dot() function. What am I doing wrong?