Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4. struct b {
  5. float m_inv;
  6. } body[]={0.0};
  7. double mass=1e-200;
  8. double INFINITY=1e20;
  9. printf("INFINITY = %f\n",INFINITY);
  10. printf("mass = %f\n",mass);
  11. body->m_inv = mass == 0.0f ? INFINITY : 1.0f/mass;
  12. printf("body->m_inv = %f\n",body->m_inv);
  13. return 0;
  14. }
  15.  
  16. /*
  17. -*- mode: compilation; default-directory: "~/src/c/pitfalls/" -*-
  18. Compilation started at Fri May 3 01:34:30
  19.  
  20. SRC="/Users/pjb/src/c/pitfalls/float-div-0.c" ; EXE="float-div-0" ; gcc -I. -L. -g3 -ggdb3 -o ${EXE} ${SRC} && ./${EXE} && echo status = $?
  21. INFINITY = 100000000000000000000.000000
  22. mass = 0.000000
  23. body->m_inv = inf
  24. status = 0
  25.  
  26. Compilation finished at Fri May 3 01:34:30
  27. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement