In random.py’s source code, there is the following constant definition:
BPF = 53 # Number of bits in a float
RECIP_BPF = 2**-BPF
I’m no math major, but isn’t it more readable to invert BPF by placing a 1 over it?
Or is there something about multiplication that is more convenient than division in programming?
Nevermind.
In an effort to clean up my question I found this:
“On many machines, particularly those without hardware support for division, division is a slower operation than multiplication, so this approach can yield a considerable speedup. The first step is relatively slow but only needs to be done once.”
Redability is subjective. That said, I personally find
2**-BPFeasier to read than1.0/2**BPF(with or without parentheses around2**BFP).As to performance differences, I doubt they are relevant since the expression is only evaluated once, when the module is imported.