It's good.

I've heard this called tuple packing/unpacking.  I think behind the scenes
python creates a tuple with the values max(x,y) and max(x,y).  After the
tuple is created, the values are "unpacked" to x and y.

On Mon, Mar 26, 2012 at 6:17 PM, Peter Bittner <[email protected]>wrote:

> Just some sort of code review...
>
> def hypot(x, y):
>    """Calculate the hypotenuse the safe way, avoiding over- and
> underflows"""
>    x = abs(x)
>    y = abs(y)
>    x, y = max(x, y), min(x, y)
>    return x * sqrt(1 + (y/x) * (y/x))
>
> Is the calculation correct in line 3? What if "max(x,y)" is y? Doesn't
> "min(x,y)" then evaluate to "min(y,y)"?
>
> It seems to work correctly, and looks odd to me at the same time.
> (Note that the example from Wikipedia uses a temporary variable t.)
>
> Feel free to ignore,
> Peter
>
>
> 2012/3/26 Michael Perkonigg <[email protected]>:
> > On 26 Mar 2012 at 21:03, lkcl luke wrote:
> >
> >> On Mon, Mar 26, 2012 at 8:26 PM, Michael Perkonigg <[email protected]>
> wrote:
> >> > On 26 Mar 2012 at 10:57, Peter Bittner wrote:
> >> >
> >> >> Shouldn't we use the safe version of calculating the hypotenuse?
> >> >> http://en.wikipedia.org/wiki/Hypot
> >> >
> >> > Sounds reasonable. I have a diff for that too, want me to raise a new
> issue,
> >> > reopen the old one (if that's possible) or forget it?
> >>
> >>  reopen.
> >
> > I attached the diff file (against HEAD!) but cannot change the state of
> the
> > issue.
> > http://code.google.com/p/pyjamas/issues/detail?id=705
> >
> >
> > Mike
>

Reply via email to