Created
January 30, 2015 11:16
-
-
Save simonbyrne/c59282e9c4f4eac35ca4 to your computer and use it in GitHub Desktop.
detect fma error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
static double fct (double a) | |
{ | |
double x = fma(a,a,-a); | |
return 1.0 - x; | |
} | |
static void test (double x) | |
{ | |
printf ("test(%.20a) = %.20a\n", x, fct (x)); | |
} | |
int main (int argc, char **argv) | |
{ | |
int i; | |
if (argc <= 1) | |
{ | |
fprintf (stderr, "Usage: test2 <double> ...\n"); | |
return 1; | |
} | |
for (i = 1; i < argc; i++) | |
test (atof (argv[i])); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results:
GCC
(the correctly rounded answer)
clang
(the incorrectly rounded answer).