Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Decimal vs Float comparasion

Reply
Thread Tools

Decimal vs Float comparasion

 
 
Yuan HOng
Guest
Posts: n/a
 
      05-06-2008
Hi,

It seems decimal object will always be larger than float in
comparasion, which goes against common sense:

>>> from decimal import Decimal
>>> a = Decimal('0.5')
>>> a > 99999

False
>>> a > 99999.0

True

It seems to me that rather than allowing this to happen, comparasion
between the two should either be made correct (by convertion decimal
to float e.g.) or forbidden, like arithmatic operations between the
two types.

--
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn
 
Reply With Quote
 
 
 
 
Gasto
Guest
Posts: n/a
 
      05-06-2008
I still don't see why such a module exists.

On 5 mayo, 21:52, "Yuan HOng" <(E-Mail Removed)> wrote:
> Hi,
>
> It seems decimal object will always be larger than float in
> comparasion, which goes against common sense:
>
> >>> from decimal import Decimal
> >>> a = Decimal('0.5')
> >>> a > 99999

> False
> >>> a > 99999.0

>
> True
>
> It seems to me that rather than allowing this to happen, comparasion
> between the two should either be made correct (by convertion decimal
> to float e.g.) or forbidden, like arithmatic operations between the
> two types.
>
> --
> Hong Yuan
>
> 大管家网上建材超市
> 装修装潢建材一站式购物http://www.homemaster.cn


 
Reply With Quote
 
 
 
 
Marco Mariani
Guest
Posts: n/a
 
      05-06-2008
Gasto wrote:

> I still don't see why such a module exists.


There are 2.0 types of programmers: those who always use floating point,
and those who know how to use them.
 
Reply With Quote
 
Rhamphoryncus
Guest
Posts: n/a
 
      05-06-2008
On May 6, 1:31 am, Dennis Lee Bieber <(E-Mail Removed)> wrote:
> On Tue, 6 May 2008 11:52:10 +0800, "Yuan HOng" <(E-Mail Removed)>
> declaimed the following in comp.lang.python:
>
>
>
> > It seems to me that rather than allowing this to happen, comparasion
> > between the two should either be made correct (by convertion decimal
> > to float e.g.) or forbidden, like arithmatic operations between the
> > two types.

>
> Why should decimal be coerced to float? Maybe float should be
> coerced to decimal?
>
> Or... the programmer should explicitly specify what comparison is
> wanted -- if any...
>
> Or... Isn't Python 3.x supposed to forbid mixed type comparisons
> unless the types implement suitable handling?


Yes, it is fixed in 3.0. Unfortunately it's well established
behaviour in 2.x, so it won't be changing there. Don't bother
reporting a bug about this unless it's about 3.0.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
Directionality of comparasion operators Tobias Weber Ruby 10 05-27-2008 03:37 PM
Locale-specific string comparasion Yuan HOng Python 0 07-26-2007 04:10 AM
Decimal to Packed Decimal Conversion in C++ Ven C++ 3 08-01-2006 03:56 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments