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

X/0.0 is safe, and will always return NaN, no matter the language -- as long as 0.0 is a representation of an IEEE754 floating-point value, and as long as the expression "X/0.0" is interpreted as coercing X into a floating-point value in order to do fpdiv(X, 0.0) -- then safely returning Infinity here (or NaN in the case of 0/0.0) is required of the FPU in order for it to be considered IEEE754-compliant.

On the other hand, X/0 (integer division-by-zero, where X is not a floating-point value either) usually does cause an exception. In fact, in bare-metal ASM without a trap-handler interrupt set up, it halts the processor entirely.



> On the other hand, X/0 (integer division-by-zero, where X is not a floating-point value either) usually does cause an exception.

That's true for x86, but not for most other architectures.




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

Search: