Mark Dickinson dicki...@gmail.com added the comment:
For myself, I strongly prefer that round(int, int) return an integer in
Python 3.x. Here ar\
e three reasons:
(1) Interoperability with Decimal (and, to a lesser extent, Fraction):
the decimal module is\
carefully designed so that
STINNER Victor victor.stin...@haypocalc.com added the comment:
marketdickinson (2) Accuracy
I see int/float like bytes/characters: it's not a good idea to mix
them. If you use float, you know that you loose precision (digits)
after some operations. Whereas I suppose the operations on int are
Mark Dickinson dicki...@gmail.com added the comment:
Apologies for the poor formatting in the last comment. Bad
cut-and-paste job.
One more reason:
(4) In the face of ambiguity, refuse the temptation to guess.
Why should round(int, int) be float, rather than Decimal, or Fraction?
This was the
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
It's settled then. Input type dictates output type. No dependency on
the actual values.
--
resolution: - accepted
___
Python tracker rep...@bugs.python.org
Changes by Raymond Hettinger rhettin...@users.sourceforge.net:
--
assignee: - marketdickinson
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4707
___
Mark Dickinson dicki...@gmail.com added the comment:
Committed in r69068 (py3k), r69069 (release30-maint).
The original bug with round(float, n) (loss of accuracy arising from
intermediate floating-point rounding errors) is still present; I think
further discussion for that can go into issue
Changes by STINNER Victor victor.stin...@haypocalc.com:
Removed file: http://bugs.python.org/file12407/round_int_int.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4707
___
Changes by STINNER Victor victor.stin...@haypocalc.com:
Removed file: http://bugs.python.org/file12412/round_int_int2.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4707
___
Changes by STINNER Victor victor.stin...@haypocalc.com:
Removed file: http://bugs.python.org/file12414/round_int_int3.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4707
___
Changes by STINNER Victor victor.stin...@haypocalc.com:
Removed file: http://bugs.python.org/file12415/round_int_int4.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4707
___
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
Someone ought to ping Guido on this. He may have some strong thoughts
on the signature (having it sometimes return ints and sometimes floats).
But in this case, accuracy may be the more important consideration.
Raymond Hettinger rhettin...@users.sourceforge.net added the comment:
Guido, do you have any thoughts on this?
Basically, it's a choice between giving round() a weird signature
(sometimes returning floats and sometimes int/longs) versus having
accurate roundings of integers (which become
Guido van Rossum gu...@python.org added the comment:
I think it's fine if it returns an int iff the first arg is an int. In
other languages this would be overloaded as follows:
round(int)int
round(float)float
round(int, int)int
round(float, int)float
--
assignee: gvanrossum -
David W. Lambert lamber...@corning.com added the comment:
I'd prefer round(x,positive_integer) return float. Returning int is a
bit of a lie, except that the decimal module is available to avoid this
sort of lie.
For non-positive integer roundings I'd like an integer return.
In my opinion,
Guido van Rossum gu...@python.org added the comment:
Well, that would leave a function whose return *type* depends on the
*value* of one of the arguments, which I find very ugly.
I don't know why you think rounding an int to X (X0) digits after the
decimal point should return a float -- it's
David W. Lambert lamber...@corning.com added the comment:
The value of one of the arguments controls how many digits there are.
Certainly if you rounded $10 to the nearest cents you'd expect $10.00.
Thus round(10,2) should be 10.00. Without using decimal module, the
best we can do is produce
Guido van Rossum gu...@python.org added the comment:
I'm sorry, but I don't see a significant difference between $10 and
$10.00. If you want to display a certain number of digits, use %.2f %
x. And trust me, I'm not doing this for Fortran's sake.
___
Python
Mark Dickinson dicki...@gmail.com added the comment:
Clearer title.
--
title: round() shows undocumented behaviour - round(25, 1) should return an
integer, not a float
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4707
Mark Dickinson dicki...@gmail.com added the comment:
Some minor modifications to the last patch:
- fix round docstring: it now reads round(number[, ndigits]) - number
instead of round(number[, ndigits]) - floating-point number
- add Misc/NEWS entry
- add extra tests for round(x, n) with
19 matches
Mail list logo