ivplay's blog

By ivplay, 10 years ago, In English

Today I found a very interesting fact. int gcc, If you write cout << 5/0 << endl; it will cause a division by zero exception and get RTE. if you write cout << 5.0/0.0 << endl; it will output nan!!!!!!!! cout << atan(5/0) causes RTE while atan(5.0/0.0) causes correct output!

  • Vote: I like it
  • +7
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Division by zero is undefined behavior so, after all, it isn't that surprising when strange things happen :)

http://stackoverflow.com/questions/3004095/division-by-zero-undefined-behavior-or-implementation-defined-in-c-and-or-c

»
10 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Unlike integer division, floating point division by zero is well-defined.