[Tutor] Having trouble getting mind around decimal module

Luke Paireepinart rabidpoobear at gmail.com
Mon Aug 14 09:49:50 CEST 2006


Dick Moores wrote:
> I'm having trouble getting my mind around the decimal module. From 
> the tutorial (<http://docs.python.org/lib/decimal-tutorial.html>) I 
> can see how to get 1/7 to, say, 32 places:
>
>  >>> from decimal import Decimal
>  >>> getcontext().prec = 32
>  >>> Decimal(1) / Decimal(7)
> Decimal("0.14285714285714285714285714285714")
>
> But I can't figure out how to compute to 32 places things like the 
> square root of 2, or the arc tangent of .41. Could someone please show me?
>
>   
I think square root calculations, and other math operations, by the 
built-in math.py package
only work on floats since they wrap math.c
So you'd have to find a pure-python implementation that supported 
Decimal objects I guess,
or write your own.
> Thanks,
>
> Dick Moores
> rdm at rcblue.com
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   



More information about the Tutor mailing list