fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float implementation_1(float x)
  5. {
  6. return powf(x, 4) - 10 * powf(x, 3) + 35 * powf(x, 2) - 50 * x + 24;
  7. }
  8.  
  9. float implementation_2(float x)
  10. {
  11. return (x - 1) * (x - 2) * (x - 3) * (x - 4);
  12. }
  13.  
  14. float implementation_3(float x)
  15. {
  16. return x * (x * ((x - 10) * x + 35) - 50) + 24;
  17. }
  18.  
  19. int main()
  20. {
  21. float x = 3.14159263f;
  22. printf ("Implementation 1: %a\n", implementation_1(x));
  23. printf ("Implementation 2: %a\n", implementation_2(x));
  24. printf ("Implementation 3: %a\n", implementation_3(x));
  25.  
  26. printf("Does implementation 1 match 2? %d\n", implementation_1(x) == implementation_2(x));
  27. printf("Does implementation 1 match 3? %d\n", implementation_1(x) == implementation_3(x));
  28. printf("Does implementation 2 match 3? %d\n", implementation_2(x) == implementation_3(x));
  29. return 0;
  30. }
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
Implementation 1: -0x1.30482bc9354p-2
Implementation 2: -0x1.30494cp-2
Implementation 3: -0x1.3049p-2
Does implementation 1 match 2? 0
Does implementation 1 match 3? 0
Does implementation 2 match 3? 0