I use the function trace() to calculate the trace of a matrix. This is not important. But for this specific matrix this value is -1. My variable "trace" is set to this from the function. However when I compare this value as a boolean it shows they are not equal. Why is this happening?
double trace = R.trace(); double t = -1; std::cout << "\nTrace: \n" << trace << "\n Matrix: \n" << R; printf("\nbool: %d: sub: %f type: %s\n", trace == -1.0, trace, typeid(trace).name()); printf("\nbool: %d: sub: %f type: %s\n", t == -1.0, t, typeid(t).name());
Trace: -1 Matrix: 1 3.52206e-06 -2.42913e-11 3.52206e-06 -1 6.44708e-06 -1.58434e-12 -6.44708e-06 -1 bool: 0: sub: -1.000000 type: d bool: 1: sub: -1.000000 type: d
So for some reason it does not realize they are equal?
I am using g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0 x86_64