C++ float division
Floating point division delivers wrong results in C++.
Q x = 1 / 2
;
The value of x
should be 0.5.
The generated C++ code looks like:
double x = 1 / 2
;
In this case C++ performs an integer division, because 1
and 2
are handled as Integer values. The (wrong result is x == 0
).