[FRPythoneers] I must be sitting too close to the monitor.

Cary Miller Cary.Miller at UCHSC.edu
Wed Mar 16 08:25:01 MST 2005


Why the decimal module?  Wouldn't it make sense to have a and b behave 
like c and d?

//=\ Cary Miller 
\=// Center for Computational Pharmacology 
//=\ University of Colorado Health Sciences Center
\=// http://compbio.uchsc.edu/Hunter_lab/Miller 
//=\ (303) 724-0263


On Tue, 15 Mar 2005, Andrew Diederich wrote:

> This conversation closed up a while ago, but I've been thinking about
> it, anyway.  In python 2.4 they came up with a decimal type which
> fixes a lot of this.  I know you're not using 2.4 yet, though.
>
> Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> a = 35.62
>>>> b = 1.73
>>>> a+b
> 37.349999999999994
>>>> import decimal
>>>> c = decimal.Decimal('35.62')
>>>> d = decimal.Decimal('1.73')
>>>> c+d
> Decimal("37.35")
>
> There's also probably a way to fudge this a bit with some work.  Going
> back to my slide-rule days, while doing all your calculations without
> any decimals at all.  It's up to the computer (the person doing the
> computing) to keep track of where the decimal should go, then put it
> back in at the end.
>
> This should be pretty straight-forward for multiplication, harder for
> division, I think, because of remainders.  Slide rules don't really do
> addition and subtraction, so this is far from a fool-proof plan, I
> think.  Fun to think about, though.
>
>>>> e = 3562
>>>> f = 173
>>>> e*f
> 616226
>>>> c*d
> Decimal("61.6226")
>
> -- 
> Andrew
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
>



More information about the FRPythoneers mailing list