fork(5) download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float floatMod(float a, float b)
  5. {
  6. return a - (round(a / b) * b);
  7. }
  8.  
  9. int main()
  10. {
  11. printf("%f\n", fmodf(18.5f, 4.2f));
  12. printf("%f\n", floatMod(18.5f, 4.2f));
  13.  
  14. printf("%f\n", fmodf(-18.5f, 4.2f));
  15. printf("%f\n", floatMod(-18.5f, 4.2f));
  16.  
  17. }
  18.  
Success #stdin #stdout 0s 4300KB
stdin
Standard input is empty
stdout
1.700001
1.700001
-1.700001
-1.700001