[Python-ideas] Consider adding clip or clamp function to math

Steven D'Aprano steve at pearwood.info
Thu Aug 4 21:05:11 EDT 2016


On Thu, Aug 04, 2016 at 04:17:47PM -0700, Chris Barker wrote:

> I think it would also require more special case checking in the code....

I think you are over-complicating this, AND ignoring what the IEEE-754 
standard says about this.

> if NaN is passed in as a limit, it's probably a error of some sort

That's not what the standard says. The standard says NAN as a limit 
should be treated as "no limit".

> And you have inf and -inf if you do want "no limit"

That will still apply. You can also pass 1.7976931348623157E+308, the 
largest possible float. (If we're talking about float arguments -- for 
int and Decimal, you can easily exceed that.)


-- 
Steve


More information about the Python-ideas mailing list