A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-February/097728.html below:

[Python-Dev] math.hypot, complex.__abs__, and documentation

[Python-Dev] math.hypot, complex.__abs__, and documentationSteven D'Aprano steve at pearwood.info
Tue Feb 16 23:46:38 CET 2010
On Wed, 17 Feb 2010 08:19:00 am David DiCato wrote:
> I have a minor concern about certain corner cases with math.hypot and
> complex.__abs__, namely when one component is infinite and one is not
> a number. If we execute the following code:
>
> import math
> inf = float('inf')
> nan = float('nan')
> print math.hypot(inf, nan)
> print abs(complex(nan, inf))
>
> ... then we see that 'inf' is printed in both cases. The standard
> library tests (for example, test_cmath.py:test_abs()) seem to test
> for this behavior as well, and FWIW, I personally agree with this
> convention.

What's the justification for that convention? It seems wrong to me. 

If you expand out hypot and substitute a=inf and b=nan, you get:

>>> math.sqrt(inf*inf + nan*nan)
nan

which agrees with my pencil-and-paper calculation:

sqrt(inf*inf + nan*nan)
= sqrt(inf + nan)
= sqrt(nan)
= nan



-- 
Steven D'Aprano
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4