Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is not true if you say division by 0 is undefined or +inf either. It really is totally fine.


No, you are assuming that 1/0= "undefined" where "undefined" is a magical value. It's not. It literally means 'That operation has no definition, and there is no reasonable result to return'.

Many languages handle this in a practical way by creating a special value "undefined", "NaN", or others that has special properties. But let's be clear that "0" is a normal number in the real number space, as so expectations about properties of real numbers are not going to hold up.


When there is no reasonable result to return does it really matter what result is returned? 1 / 0 == 0 is about the same as 1 / 0 == 3. To avoid this just don't do 1 / 0 in your program.


> 1 / 0 == 0 is about the same as 1 / 0 == 3

Sure, and both are bad.

> To avoid this just don't do 1 / 0 in your program.

If you're going to avoid doing it, better to have it throw an exception if you do it by accident.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: