When I'm compiling the following piece of C++ code using Clang++ and G++
void ScaleFactor(float32_t scale, int32_t &factor) {
factor = floor(log2(abs(scale))+1)
cout << factor << endl;
}
where the value of scale
equals 0.234375 and factor
is passed by reference to an integer variable in another function, I'm getting the following different outputs for factor
while debugging using GDB
(int32_t &) @0x7fffffffdaa0: -2147483648 (Clang++)
(int32_t &) @0x7fffffffda9c: -2 (G++)
But, on replacing abs()
with fabs()
each output matches with the desired output
(int32_t &) @0x7fffffffdb90: -2 (Clang++)
(int32_t &) @0x7fffffffdddc: -2 (G++)
What might be the reason for this discrepancy?