3 ms·
if "answer" overflows, switch to symbolic mode.
by est 2y ago
if "answer" overflows, switch to symbolic mode.
- anon-3988 2y agonot that simple, 1/3 + 5 - 1/3 should be 5. It doesn't overflow in IEEE754
- coder543 2y agoThat does appear to equal exactly 5... would you care to show how it doesn't? $ cat check_math.c #include <stdio.h> int main() { // Define the values as float (32-bit floating point) float one_third = 1.0f / 3.0f; float five = 5.0f; // Compute the equation float result = one_third + five - one_third; // Check for exact equality if (result == five) { printf("The equation evaluates EXACTLY to 5.0 (True)\n"); } else { // Print the actual result and the difference printf("The equation does NOT evaluate exactly to 5.0 (False)\n"); printf("Computed result: %.10f\n", result); printf("Difference: %.10f\n", result - five); } return 0; } $ gcc -O0 check_math.c -o check_math; ./check_math The equation evaluates EXACTLY to 5.0 (True)
- anon-3988 2y agoOkay..that was just an example (and a false one apparently). Its easy enough to find an example where your typical FP operations doesn't work out. https://godbolt.org/z/Mr4Ez8xz1 https://godbolt.org/z/Mr4Ez8xz1