math.isinf() tests for positive or negative infinity lumped together. What's the pythonic way to test for them distinctly?
Ways to test for positive infinity:
x == float('+inf')
math.isinf(x) and x > 0
Ways to test for negative infinity:
x == float('-inf')
math.isinf(x) and x < 0
Disassembly Way 1:
>>> def ispinf1(x): return x == float("inf")
...
>>> dis.dis(ispinf1)
1 0 LOAD_FAST 0 (x)
3 LOAD_GLOBAL 0 (float)
6 LOAD_CONST 1 ('inf')
9 CALL_FUNCTION 1
12 COMPARE_OP 2 (==)
15 RETURN_VALUE
Disassembly Way 2:
>>> def ispinf2(x): return isinf(x) and x > 0
...
>>> dis.dis(ispinfs)
1 0 LOAD_GLOBAL 0 (isinf)
3 LOAD_FAST 0 (x)
6 CALL_FUNCTION 1
9 JUMP_IF_FALSE_OR_POP 21
12 LOAD_FAST 0 (x)
15 LOAD_CONST 1 (0)
18 COMPARE_OP 4 (>)
>> 21 RETURN_VALUE
This answer seems to favor Way 2 except for the x>0.