Short-circuit Logic
Roy Smith
roy at panix.com
Sun May 26 16:22:26 EDT 2013
In article <mailman.2196.1369599562.3114.python-list at python.org>,
Terry Jan Reedy <tjreedy at udel.edu> wrote:
> On 5/26/2013 7:11 AM, Ahmed Abdulshafy wrote:
>
> > if not allow_zero and abs(x) < sys.float_info.epsilon:
> > print("zero is not allowed")
>
> The reason for the order is to do the easy calculation first and the
> harder one only if the first passes.
This is a particularly egregious case of premature optimization. You're
worried about how long it takes to execute abs(x)? That's silly.
More information about the Python-list
mailing list