Re:Things I will tell my kids if they become entrepreneurs [...
by mangeletti on Monday October 31, 2016 @08:42AM
(#12836171)
Can an interpreter shirt curcuit a multiplication if the left side is 0? In Python, for instance, is the following:
computed like this?:
Or is it computed like this?:
If the former is the case, then the chongli optimization could help, right?
[ Parent
| on HN ]
Re:Things I will tell my kids if they become entrepreneurs [...
by palunon on Monday October 31, 2016 @09:20AM
(#12836424)
If you have IEEE compliant floats, you can't, because the right side may result in Infinity, making the complete product NaN.
Re:Things I will tell my kids if they become entrepreneurs [...
by mangeletti on Monday October 31, 2016 @10:02AM
(#12836744)
Interesting.
We're talking integers here, though (re: Python).
Re:Things I will tell my kids if they become entrepreneurs [...
by nayuki on Monday October 31, 2016 @01:16PM
(#12838781)
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()
Re:Things I will tell my kids if they become entrepreneurs [...
by mangeletti on Monday October 31, 2016 @01:46PM
(#12839123)
Ah, of course. In hindsight, I now feel pretty silly even asking that.
Re:Things I will tell my kids if they become entrepreneurs [...
by chrisseaton on Monday October 31, 2016 @09:32AM
(#12836508)
Short circuiting means branching, which is likely to be slower than running operators that you know to result is zero.