Message205729
> Anyway, why not round(1.2) -> 1.0 in the first place? Just curious.
All this changed as part of PEP 3141. I wasn't watching Python 3 development closely back then, but I *think* at least part of the motivation was to provide a way to get away from the use of `int` to truncate a float to its integer part: the argument goes that a simple type conversion shouldn't throw away information, and that if you want a transformation from float to int that throws away information you should ask for it explicitly. So `math.trunc` was born as the preferred way to truncate a float to an int, and `math.floor`, `math.ceil` and `round` became alternative float -> int conversion methods. That entailed those functions returning ints.
<off-topic> In the case of `math.floor` and `math.ceil` at least, I think this is regrettable. There are plenty of places where you just want a float -> float floor or ceiling, and Python no longer has a cheap operation for that available: floor as a float-to-float operation is cheap; floor as a float-to-long-integer operation is significantly more costly.
In the case of `round`, we still have `round(x, 0)` available as a cheap float->float conversion, so it's less of a problem. And I hardly ever use `trunc`, so I don't care about that case. </off-topic> |
|
Date |
User |
Action |
Args |
2013-12-09 19:07:00 | mark.dickinson | set | recipients:
+ mark.dickinson, r.david.murray, docs@python, JBernardo, vajrasky |
2013-12-09 19:07:00 | mark.dickinson | set | messageid: <1386616020.33.0.589382546901.issue19933@psf.upfronthosting.co.za> |
2013-12-09 19:07:00 | mark.dickinson | link | issue19933 messages |
2013-12-09 19:07:00 | mark.dickinson | create | |
|