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