On 10Oct2013 17:48, Neil Cerutti <ne...@norwich.edu> wrote: > On 2013-10-10, MRAB <pyt...@mrabarnett.plus.com> wrote: > > If r is real (float) and c is complex: > > r == c means r == c.real and c.imag == 0.0 > > Woah. I thought I was going by what the docs say: > > Python fully supports mixed arithmetic: when a binary > arithmetic operator has operands of different numeric types, > the operand with the “narrower” type is widened to that of the > other, where integer is narrower than floating point, which is > narrower than complex. Comparisons between numbers of mixed > type use the same rule. [2] The constructors int(), float(), > and complex() can be used to produce numbers of a specific > type. > > [...] > > [2] Not for complex numbers. Instead convert to floats using > abs() if appropriate. > > I guess the "if appropriate" part eluded my eye. When *is* it > appropriate? Apparently not during an equal test.
I must say that I read the footnote [2] as a directive to the programmer. "If you need to do this, a good way is to compare magnitudes is appropriate." Cheers, -- Cameron Simpson <c...@zip.com.au> My life is a never ending battle for the forces of good. Unfortunately, unlike many other crusaders for righteousness, in my system of morality, the right thing to do is very often to sit around reading the paper or watching TV. - Tim_Mefford <t...@physics.orst.edu> -- https://mail.python.org/mailman/listinfo/python-list