https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66736
Bug ID: 66736 Summary: float rounding differences when using constant literal versus variable Product: gcc Version: 5.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dhekir at gmail dot com Target Milestone: --- Calling function "log10f(3)" with a constant literal or via a variable, such as "float f = 3; log10f(f)" gives different rounding results, which are incorrect in the latter case. Note that the bug is not about imprecision in the result, but inconsistency between two statements which should be equivalent. The difference only appears with no optimization flag or with -O0; activating -O1 or greater makes the difference disappear. It is especially annoying (although not forbidden) that the rounding differences in this case do not respect usual order (i.e. changing the rounding mode allows one to see that FE_DOWNWARD is larger than FE_TONEAREST in the version using the variable). This behavior has been observed in several GCCs, from 4.8.4 (Ubuntu) to 5.1.1 (Fedora), including a 5.0.0 compiled from trunk, and using different versions of glibc (2.19, and also tried compiling 2.21). All of them produced the same result. Also, there are several constants for which this happen, but 3 would be one of the most notable ones. #include <math.h> #include <stdio.h> int main() { float r = log10f(3); printf("literal constant: %g (%a)\n", r, r); float x = 3; r = log10f(x); printf("with variable: %g (%a)\n", r, r); return 0; }