Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-23 Thread Steven D'Aprano
On Mon, 24 May 2010 03:06:28 am Wayne Werner wrote: > On Sat, May 22, 2010 at 9:58 AM, Steven D'Aprano wrote: > > On Sun, 23 May 2010 12:19:07 am Wayne Werner wrote: > > > On Sat, May 22, 2010 at 7:32 AM, Steven D'Aprano > > > > wrote: > > > > Why do people keep recommending Decimal? Decimals suff

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-23 Thread Wayne Werner
On Sat, May 22, 2010 at 9:58 AM, Steven D'Aprano wrote: > On Sun, 23 May 2010 12:19:07 am Wayne Werner wrote: > > On Sat, May 22, 2010 at 7:32 AM, Steven D'Aprano > wrote: > > > Why do people keep recommending Decimal? Decimals suffer from the > > > exact same issues as floats, > > > > This is exa

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-23 Thread Lie Ryan
On 05/22/10 22:32, Steven D'Aprano wrote: > On Sat, 22 May 2010 07:16:20 am wesley chun wrote: >> correct, it is a floating point issue regardless of language.. it's >> not just Python. you cannot accurately represent repeating fractions >> with binary digits (bits). more info specific to Python he

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-22 Thread Steven D'Aprano
On Sun, 23 May 2010 12:19:07 am Wayne Werner wrote: > On Sat, May 22, 2010 at 7:32 AM, Steven D'Aprano wrote: > > Why do people keep recommending Decimal? Decimals suffer from the > > exact same issues as floats, > > This is exactly incorrect! The Decimal operator offers /exact/ > decimal point op

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-22 Thread Wayne Werner
On Sat, May 22, 2010 at 7:32 AM, Steven D'Aprano wrote: > Why do people keep recommending Decimal? Decimals suffer from the exact > same issues as floats, > This is exactly incorrect! The Decimal operator offers /exact/ decimal point operations. They implement non-hardware operations to preserve

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-22 Thread Steven D'Aprano
On Sat, 22 May 2010 07:16:20 am wesley chun wrote: > correct, it is a floating point issue regardless of language.. it's > not just Python. you cannot accurately represent repeating fractions > with binary digits (bits). more info specific to Python here: > http://docs.python.org/tutorial/floatingp

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-22 Thread Steven D'Aprano
On Sat, 22 May 2010 07:51:31 am Alan Gauld wrote: > "Neven Gorsic" wrote > > > I run into Python error in rounding and not know how to predict > > when it will > > occur in order to prevent wrong result. > > It depends how you define wrong. When I was at scvhool the rules f > or rounding decimals

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Mark Tolonen
"Alan Gauld" wrote in message news:ht6v97$63...@dough.gmane.org... "Neven Gorsic" wrote I run into Python error in rounding and not know how to predict when it will occur in order to prevent wrong result. It depends how you define wrong. When I was at scvhool the rules f or rounding dec

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Alan Gauld
"Neven Goršić" wrote It's pity that Python has such unreliable functions so you never know in advanced when you will hit new one ... The functions are not unreliable. That would imply they give out unpredictable answers. In fact the answers are completely predictable and consistent and correc

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Alan Gauld
"Neven Gorsic" wrote I run into Python error in rounding and not know how to predict when it will occur in order to prevent wrong result. It depends how you define wrong. When I was at scvhool the rules f or rounding decimals said that if it ended in 5 you rounded to the nearest even digit.

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread wesley chun
correct, it is a floating point issue regardless of language.. it's not just Python. you cannot accurately represent repeating fractions with binary digits (bits). more info specific to Python here: http://docs.python.org/tutorial/floatingpoint.html also, keep in mind that '%f' is not a rounding o

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Emile van Sebille
On 5/21/2010 8:30 AM Neven Goršić said... Thanks! It's pity that Python has such unreliable functions so you never know in advanced when you will hit new one ... The problem is with floats, and all languages suffer similarly. Most of us develop various techniques for avoiding these types of i

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Thanks for the assistance and the article. Neven -- On Fri, May 21, 2010 at 5:35 PM, Lie Ryan wrote: > On 05/22/10 01:30, Neven Goršić wrote: > > Thanks! > > It's pity that Python has such unreliable functions so you never know in > > advanced when you will hit new one ...

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Lie Ryan
On 05/22/10 01:30, Neven Goršić wrote: > Thanks! > It's pity that Python has such unreliable functions so you never know in > advanced when you will hit new one ... Well, it's not Python but the machine. Floating point number is not Real numbers; there are certain limitations imposed by physical l

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Thanks! It's pity that Python has such unreliable functions so you never know in advanced when you will hit new one ... --- On Fri, May 21, 2010 at 2:14 PM, Lie Ryan wrote: > On 05/21/10 20:17, Neven Goršić wrote: > > Hi! > > > > I run into Python error in rounding and n

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Lie Ryan
On 05/21/10 20:17, Neven Goršić wrote: > Hi! > > I run into Python error in rounding and not know how to predict when it will > occur in order to prevent wrong result. That's because it's floating point number. > What can I do to assure accurate result? Use decimal module to do precise control

[Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Hi! I run into Python error in rounding and not know how to predict when it will occur in order to prevent wrong result. What can I do to assure accurate result? >>> "%.2f" % 0.445 '0.45' correct >>> "%.2f" % 0.455 '0.46' correct