Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-04 Thread Greg Ewing
James Y Knight wrote: > And it does in C because C doesn't have arbitrary size integers, so if > round returned integers, round(1e+308) couldn't work. Also, in C you can use the result directly in an int context without complaint. In Python these days, that is usually disallowed. -- Greg _

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-03 Thread James Y Knight
On Aug 3, 2006, at 2:34 AM, Greg Ewing wrote: > Raymond Hettinger wrote: > >> -1 on an extra built-in just to save the time for function call > > The time isn't the main issue. The main issue > is that almost all the use cases for round() > involve doing an int() on it afterwards. At > least nobo

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-03 Thread Greg Ewing
M.-A. Lemburg wrote: > If you are eventually rounding to say 2 decimal > places in the end of the calculation, you won't > want to find yourself presenting the user 1.12 > and 1.13 as equal values :-) Even if, before rounding, they were actually 1.124 and 1.1251? And if the differ

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-03 Thread Ron Adam
Nick Coghlan wrote: > Ron Adam wrote: >> Consider an example where you are combining data that had different >> number of significant digits. Keeping all the digits of your answer >> gives a false since of accuracy. The extra digits are meaningless >> because the margin of error is greater tha

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-03 Thread Ka-Ping Yee
On Thu, 3 Aug 2006, Greg Ewing wrote: > The time isn't the main issue. The main issue > is that almost all the use cases for round() > involve doing an int() on it afterwards. That's my experience as well. In my opinion, the purpose of round() is most commonly described as "to make an integer".

[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-03 Thread Jim Jewett
Greg Ewing wrote: > The time isn't the main issue. The main issue > is that almost all the use cases for round() > involve doing an int() on it afterwards. At > least nobody has put forward an argument to > the contrary yet. Or, more accurately, they *should* involve an int afterwards, but often

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-03 Thread Nick Coghlan
Ron Adam wrote: > Consider an example where you are combining data that had different > number of significant digits. Keeping all the digits of your answer > gives a false since of accuracy. The extra digits are meaningless > because the margin of error is greater than any of the digits that

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-03 Thread Ron Adam
Greg Ewing wrote: > Raymond Hettinger wrote: > >> -1 on an extra built-in just to save the time for function call > > The time isn't the main issue. The main issue > is that almost all the use cases for round() > involve doing an int() on it afterwards. At > least nobody has put forward an argume

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-03 Thread M.-A. Lemburg
Greg Ewing wrote: > M.-A. Lemburg wrote: > >> Believe me: you have to if you want to do more >> advanced calculus related to pricing and risk >> analysis of derivatives. > > When you do things like that, you're treating > money as though it were a continuous quantity. > This is an approximation,

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-02 Thread Greg Ewing
Raymond Hettinger wrote: > -1 on an extra built-in just to save the time for function call The time isn't the main issue. The main issue is that almost all the use cases for round() involve doing an int() on it afterwards. At least nobody has put forward an argument to the contrary yet. Sure you

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-02 Thread James Y Knight
On Aug 2, 2006, at 11:26 PM, Raymond Hettinger wrote: > Also, -10 on changing the semantics of int() to round instead of > truncate. The truncating version is found is so many other languages > and book examples, that it would be a disaster for us to choose a > different meaning. I'd be happy to

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-02 Thread Raymond Hettinger
>> Most typical uses of round() don't use the >> optional argument, true, but I still fail >> to see what returning an integer instead of >> a float would buy you. > > > It saves you a function call in the vast > majority of cases, where an int is what > you ultimately want. > -1 on an extra buil

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-02 Thread Greg Ewing
M.-A. Lemburg wrote: > Believe me: you have to if you want to do more > advanced calculus related to pricing and risk > analysis of derivatives. When you do things like that, you're treating money as though it were a continuous quantity. This is an approximation, so you can tolerate having small

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-02 Thread Simon Burton
On Wed, 2 Aug 2006 07:21:02 -0400 "Chermside, Michael" <[EMAIL PROTECTED]> wrote: > > You wrote: > > (ie. I am wondering if truncating the float representation > > of an int always gives back the original int). > > Yes it does, because all integers that can be expressed as floats > can be expres

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-02 Thread BJörn Lindqvist
On 8/2/06, M.-A. Lemburg <[EMAIL PROTECTED]> wrote: > Greg Ewing wrote: > > In all my programming so far I've found > > numerous uses for round-to-int, and exactly > > zero uses for round-binary-float-to-decimal- > > places. So from my point of view, the YAGNI > > applies to the *current* behavour

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-02 Thread M.-A. Lemburg
Greg Ewing wrote: > M.-A. Lemburg wrote: > >> You often have a need for controlled rounding when doing >> financial calculations > > You should NOT be using binary floats for money > in the first place. Believe me: you have to if you want to do more advanced calculus related to pricing and risk

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-01 Thread Simon Burton
On Sat, 29 Jul 2006 15:44:33 +1200 Greg Ewing <[EMAIL PROTECTED]> wrote: > Michael Urman wrote: > > The fact that > > round returns a float rather than an int, while intentional, does not > > feature prominently in one's mine when the first version yielded the > > expected results. > > As an asid

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-01 Thread Greg Ewing
M.-A. Lemburg wrote: > You often have a need for controlled rounding when doing > financial calculations You should NOT be using binary floats for money in the first place. > or in situations where you want to > compare two floats with a given accuracy, Pseudo-rounding to decimal places is n

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-01 Thread Aahz
On Tue, Aug 01, 2006, M.-A. Lemburg wrote: > > You often have a need for controlled rounding when doing financial > calculations or in situations where you want to compare two floats > with a given accuracy, e.g. to work around rounding problems ;-) > > The usual approach is to use full float accur

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-01 Thread M.-A. Lemburg
Greg Ewing wrote: > M.-A. Lemburg wrote: > >> I suppose you don't know about the optional argument >> to round that lets you round up to a certain decimal ?! > > Yes, I know about, but I rarely if ever use it. > Rounding a binary float to a number of decimal > places seems a fundamentally ill-con

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-01 Thread Greg Ewing
M.-A. Lemburg wrote: > I suppose you don't know about the optional argument > to round that lets you round up to a certain decimal ?! Yes, I know about, but I rarely if ever use it. Rounding a binary float to a number of decimal places seems a fundamentally ill-considered thing to do anyway. What

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-08-01 Thread M.-A. Lemburg
Greg Ewing wrote: > Raymond Hettinger wrote: > >> I think this would harm more than it would help. It more confusing to >> have several rounding-thingies to choose from than it is have an >> explicit two-step. > > But is it more confusing enough to be worth forcing > everyone to pay two functi

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-07-31 Thread Greg Ewing
Raymond Hettinger wrote: > I think this would harm more than it would help. It more confusing to > have several rounding-thingies to choose from than it is have an > explicit two-step. But is it more confusing enough to be worth forcing everyone to pay two function calls instead of one in the

Re: [Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-07-31 Thread Raymond Hettinger
Greg Ewing wrote: >As an aside, does anyone else think that it would be >useful to have a builtin which rounds and converts to >an int in one go? Whenever I use round(), I almost >always want the result as an int, and making me do >it in two steps seems unnecessarily bothersome. > > I think this

[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

2006-07-28 Thread Greg Ewing
Michael Urman wrote: > The fact that > round returns a float rather than an int, while intentional, does not > feature prominently in one's mine when the first version yielded the > expected results. As an aside, does anyone else think that it would be useful to have a builtin which rounds and con