fork download
  1. #include <stdio.h>
  2. #include <fenv.h>
  3. #pragma STDC FENV_ACCESS ON
  4.  
  5. int main(void)
  6. {
  7. int roundMode = fegetround( );
  8.  
  9. volatile double d1;
  10. volatile double d2;
  11. volatile double result;
  12. volatile int rounded;
  13.  
  14. fesetround(FE_TONEAREST);
  15.  
  16. d1 = 0.41;
  17. d2 = 100;
  18. result = d1 * d2;
  19. rounded = result;
  20.  
  21. printf("nearest rounded=%i\n", rounded);
  22.  
  23. fesetround(FE_TOWARDZERO);
  24.  
  25. d1 = 0.41;
  26. d2 = 100;
  27. result = d1 * d2;
  28. rounded = result;
  29.  
  30. printf("zero rounded=%i\n", rounded);
  31.  
  32. fesetround(roundMode);
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
nearest rounded=41
zero rounded=40