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

He's saying the left hand side of the equation. The order of the items on the right hand side does not matter.


Can an interpreter shirt curcuit a multiplication if the left side is 0? In Python, for instance, is the following:

    a * b * c * d
computed like this?:

    ((a * b) * c) * d
Or is it computed like this?:

    a * ((b * c) * d)
If the former is the case, then the chongli optimization could help, right?


If you have IEEE compliant floats, you can't, because the right side may result in Infinity, making the complete product NaN.


Interesting.

We're talking integers here, though (re: Python).


No, an interpreter cannot short-circuit a zero multiplication. This is because the expressions could be functions that raise exceptions.

e.g. 0 * (0/0)

e.g. f() * raise_some_exception()


Ah, of course. In hindsight, I now feel pretty silly even asking that.


Short circuiting means branching, which is likely to be slower than running operators that you know to result is zero.




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

Search: