fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float xf_round1_f(float input, int prec) {
  5. printf("%f\t",input);
  6. int trunc = round(input * pow(10, prec));
  7. printf("%f\t",(float)trunc);
  8. input=(float)trunc / pow(10, prec);
  9. printf("%f\t",input);
  10. input=nextafterf(input, input+1.0);
  11. printf("%f\n",input);
  12. return (input);
  13. }
  14.  
  15. int main(void) {
  16. xf_round1_f(49.975002f, 3);
  17. xf_round1_f(49.980000f, 3);
  18. xf_round1_f(49.985001f, 3);
  19. xf_round1_f(49.990002f, 3);
  20. xf_round1_f(49.995003f, 3);
  21. xf_round1_f(50.000000f, 3);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
49.975002	49975.000000	49.974998	49.975002
49.980000	49980.000000	49.980000	49.980003
49.985001	49985.000000	49.985001	49.985004
49.990002	49990.000000	49.990002	49.990005
49.995003	49995.000000	49.994999	49.995003
50.000000	50000.000000	50.000000	50.000004