[Python-Dev] trunc() (original) (raw)
Daniel Stutzbach daniel at stutzbachenterprises.com
Sun Jan 27 19:55:26 CET 2008
- Previous message: [Python-Dev] trunc()
- Next message: [Python-Dev] trunc()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Jan 27, 2008 10:43 AM, Guido van Rossum <guido at python.org> wrote:
- trunc(), round(), floor() and ceil() should all be built-ins, corresponding to trunc, round, floor and ceil. Then we have the four standard ways to go from Reals to Integers, which are properly extensible for folks who write their own number types. (We can't control how folks implement round, but we can document expected behavior -- that's how we treat add and all other operators too, after all.)
If I'm following this discussion properly, the advantage of trunc() is that a Real-class-that-isn't-float can define a trunc that can return an Integer-class-that-isn't-int, right?
In that case, why not have the Real ABC grow trunc(), ceil(), floor(), and round() methods (replacing the __ varieties), and get rid of the builtins/math-module functions?
x.trunc() is just as clear as trunc(x), and doesn't require a builtin.
The syntax when used on float literals is ugly ("2.56 .round()"), but there's no use case for these methods on literals (just write "3").
2to3 could handle this conversion pretty easily in most cases, so there won't be much breakage.
-- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises LLC
- Previous message: [Python-Dev] trunc()
- Next message: [Python-Dev] trunc()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]