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/2006-February/060465.html below:

[Python-Dev] math.areclose ...?

[Python-Dev] math.areclose ...? [Python-Dev] math.areclose ...?Raymond Hettinger raymond.hettinger at verizon.net
Mon Feb 6 22:37:22 CET 2006
[Chris Smith]
> Does it help to spell it like this?
>
> def areclose(x, y, relative_err = 1.e-5, absolute_err=1.e-8):
>     diff = abs(x - y)
>     ave = (abs(x) + abs(y))/2
>     return diff < absolute_err or diff/ave < relative_err

There is a certain beauty and clarity to this presentation; however, it is 
problematic numerically:

* the division by either absolute_err and relative_err can overflow or 
trigger a ZeroDivisionError

* the 'or' part of the expression can introduce an unnecessary discontinuity 
in the first derivative.

The original Numeric definition is likely to be better for people who know 
what they're doing; however, I still question whether it is an appropriate 
remedy for the beginner issue
 of why 1.1 + 1.1 + 1.1 doesn't equal 3.3.

Raymond 

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