T
Tim Rowe
I'm reading Mark Summerfield's "Programming Python 3.0" at the moment,
and I'm puzzled by some of his uses of sys.float_info.epsilon. I
appreciate the issues of comparing floating point numbers, but I'm
puzzled by code like:
...
x = float(input(msg))
if abs(x) < sys.float_info.epsilon:
...
What could the float() conversion return that would give different results for:
if abs(x) < sys.float_info.epsilon
and (to my mind, more obvious):
if abs(x) == 0.0
I didn't realise that float() could return anything with an absolute
value less than sys.float_value.epsilon other than 0.0 (which I think
all representations can represent exactly). What am I missing here?
and I'm puzzled by some of his uses of sys.float_info.epsilon. I
appreciate the issues of comparing floating point numbers, but I'm
puzzled by code like:
...
x = float(input(msg))
if abs(x) < sys.float_info.epsilon:
...
What could the float() conversion return that would give different results for:
if abs(x) < sys.float_info.epsilon
and (to my mind, more obvious):
if abs(x) == 0.0
I didn't realise that float() could return anything with an absolute
value less than sys.float_value.epsilon other than 0.0 (which I think
all representations can represent exactly). What am I missing here?