The behaviour of floating point division by zero

C++ standard does not force the IEEE 754 standard, because that depends mostly on hardware architecture. If the hardware/compiler implement correctly the IEEE 754 standard, the division will provide the expected INF, -INF and NaN, otherwise… it depends. Undefined means, the compiler implementation decides, and there are many variables to that like the hardware architecture, … Read more

c++ division by 0

For IEEE floats, division of a finite nonzero float by 0 is well-defined and results in +infinity (if the value was >zero) or -infinity (if the value was less than zero). The result of 0.0/0.0 is NaN. If you use integers, the behaviour is undefined.

Is 1/0 a legal Java expression?

Is 1/0 actually a legal Java expression that should compile anytime anywhere? Yes. What does JLS say about it? Nothing specific … apart from saying that division by zero will result in a runtime exception. However, the JLS acknowledges that possibility of runtime exceptions in the following definition: “A compile-time constant expression is an expression … Read more

How do I catch a numpy warning like it’s an exception (not just for testing)?

It seems that your configuration is using the print option for numpy.seterr: >>> import numpy as np >>> np.array([1])/0 #’warn’ mode __main__:1: RuntimeWarning: divide by zero encountered in divide array([0]) >>> np.seterr(all=”print”) {‘over’: ‘warn’, ‘divide’: ‘warn’, ‘invalid’: ‘warn’, ‘under’: ‘ignore’} >>> np.array([1])/0 #’print’ mode Warning: divide by zero encountered in divide array([0]) This means that … Read more