Mark Dickinson dickinsm at
Thu Feb 5 04:40:52 EST 2009

On Feb 4, 9:44 pm, Tim Rowe <digi... at> wrote:
> That just leaves me puzzled as to why Mark Summerfield used it instead
> of a check against zero on user input.

No idea:  you'd have to ask Mark Summerfield.  If there's
an email address published in his book, I'm sure he
wouldn't object to the question.

> So my next question is whether there is any x that can
> be returned by float() such that x != 0 but some_number / (2 * x)
> raises a ZeroDivisionError?

Nope.  If x is nonzero, then 2*x is definitely nonzero.
It could be an infinity, or a nan, or the '2*x'
computation could raise an exception, or perhaps
cause the interpreter to crash (it shouldn't, but
you never know...), but it's never going to be zero.

Well, okay, *never* is a strong word:  if 2*x is
subnormal, and you're operating on a platform that
for whatever reasons flushes subnormal results
to zero, then it could happen.  But not in *real*
life. :)


More information about the Python-list mailing list