[Python-ideas] math.inf and math.nan constants
Case Van Horsen
casevh at gmail.com
Tue Jan 13 03:57:55 CET 2015
On Mon, Jan 12, 2015 at 6:39 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>
> I'm very glad that Python doesn't *require* object-oriented code for all
> things, as Java does, but there are cases where mixing procedural and OO
> interfaces is a nuisance. Now that Python has a full numeric tower,
> having the same function be a method for some numbers and a function for
> others makes it difficult to write type-agnostic code.
>
> As an alternative to float methods, perhaps the math module could be
> more polymorphic, so we could write things like (say):
>
> math.sqrt(some_decimal)
>
> and get a Decimal result instead of a float. I don't particularly care
> whether I call a function or a method, so long as I don't have to call
> isinstance() first.
>
I proposed something similar in
https://mail.python.org/pipermail/python-ideas/2011-November/012844.html
Summary:
math.trunc, math.ceil, and math.floor currently look for __trunc__,
__ceil__, and __floor__ methods on the argument. This could extended
to add a check for __sqrt__, __is_nan__, __sin__, etc. special
methods.
casevh
More information about the Python-ideas
mailing list