define

Jeff Epler jepler at unpythonic.net
Mon May 12 12:00:48 EDT 2003


On Mon, May 12, 2003 at 09:21:30AM -0600, Daniel Fackrell wrote:
> "Bengt Richter" <bokr at oz.net> wrote in message
> news:b9j286$74l$0 at 216.39.172.122...
> > Ok, let's do the whole deal ;-)
> >
> >     b = self.b
> >     sign = self.sign
> >     a = self.a
> >     c = self.c
> >     y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a
> >     self.y = y
> > vs
> >     with self ~ sqrt:
> >         y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a
> 
> 
> I would probably write the former as:
> 
> (a, b, c, sign) = (self.a, self.b, self.c, self.sign)
> self.y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a

I can't help but notice that when you wrote
> >         y = (-b + sign*sqrt(b**2 - 4.0*a*c))/2.0*a
you were wrong.  The correct code is
|           y = (-b + sign*sqrt(b**2 - 4.0*a*c))/(2.0*a)
because a/b*c == (a/b)*c, not a/(b*c).

I'm not sure how far back in the thread this error goes, but it's some
kind of argument against overly complex expressions <sqrt(3)/2 wink>

Jeff





More information about the Python-list mailing list