<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2654.45">
<TITLE>RE: [Python-Dev] PEP 327: Decimal Data Type</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>Michael Chermside wrote:</FONT>
</P>

<P><FONT SIZE=2>#-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I think that we'd do even better to ommit the second </FONT>
<BR><FONT SIZE=2>#- use. People who </FONT>
<BR><FONT SIZE=2>#- really want to convert floats exactly can easily write </FONT>
<BR><FONT SIZE=2>#- &quot;Decimal(1.1, 60)&quot;. But </FONT>
<BR><FONT SIZE=2>#- hardly anyone wants to convert floats exactly, while lots of </FONT>
<BR><FONT SIZE=2>#- newbies would </FONT>
<BR><FONT SIZE=2>#- forget to include the second parameter. I'd say just make </FONT>
<BR><FONT SIZE=2>#- Decimal(someFloat) </FONT>
<BR><FONT SIZE=2>#- raise a TypeError with a helpful message about how you need </FONT>
<BR><FONT SIZE=2>#- that second </FONT>
<BR><FONT SIZE=2>#- parameter when using floats.</FONT>
</P>

<P><FONT SIZE=2>I take this in consideration in another response.</FONT>
</P>
<BR>

<P><FONT SIZE=2>#- Really, that's all I came up with. This is great, and I'm </FONT>
<BR><FONT SIZE=2>#- looking forward to </FONT>
<BR><FONT SIZE=2>#- using it. I would, though, be interested in a couple more </FONT>
<BR><FONT SIZE=2>#- syntax-related </FONT>
<BR><FONT SIZE=2>#- details:</FONT>
<BR><FONT SIZE=2>#-&nbsp;&nbsp;&nbsp;&nbsp; (a) What's the syntax for changing the context? I'd </FONT>
<BR><FONT SIZE=2>#- think we'd want </FONT>
<BR><FONT SIZE=2>#- a &quot;pushDecimalContext()&quot; and &quot;popDecimalContext()&quot; sort of </FONT>
<BR><FONT SIZE=2>#- approach, since most </FONT>
<BR><FONT SIZE=2>#- well-behaved routines will want to restore their caller's context.</FONT>
</P>

<P><FONT SIZE=2>You can save a copy of the context in a variable and then restore it. No stack.</FONT>
</P>
<BR>

<P><FONT SIZE=2>#-&nbsp;&nbsp;&nbsp;&nbsp; (b) How about querying to determine a thread's current </FONT>
<BR><FONT SIZE=2>#- context? I don't </FONT>
<BR><FONT SIZE=2>#- have any use cases, but it would seem peculiar not to provide it.</FONT>
</P>

<P><FONT SIZE=2>You do it to save it in a variable.</FONT>
</P>

<P><FONT SIZE=2>For example:</FONT>
</P>

<P><FONT SIZE=2>&gt;&gt;&gt; from Decimal import *</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; import copy</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; c = getcontext()</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; cc = copy.copy(c)</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; d = Decimal(5.065253542)</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; d</FONT>
<BR><FONT SIZE=2>Decimal( (0, (5, 0, 6, 5, 2, 5, 3, 5, 4, 2), -9) )</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; d + 1&nbsp;&nbsp;&nbsp;&nbsp; # it will be rounded down</FONT>
<BR><FONT SIZE=2>Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 4), -8L) )</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; c.set_rounding('up')&nbsp;&nbsp; # returns the old rounding</FONT>
<BR><FONT SIZE=2>'half_even'</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; d + 1&nbsp;&nbsp;&nbsp;&nbsp; # it will be rounded up</FONT>
<BR><FONT SIZE=2>Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 5), -8L) )</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; setcontext(cc)</FONT>
<BR><FONT SIZE=2>&gt;&gt;&gt; d + 1</FONT>
<BR><FONT SIZE=2>Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 4), -8L) )</FONT>
</P>

<P><FONT SIZE=2>One question: This kind of stuff, should be in the final documentation? And in the final PEP?</FONT>
</P>
<BR>

<P><FONT SIZE=2>#-&nbsp;&nbsp;&nbsp;&nbsp; (c) Given a Decimal object, is there a straightforward </FONT>
<BR><FONT SIZE=2>#- way to determine its </FONT>
<BR><FONT SIZE=2>#- coefficient and exponent? Methods named .precision() and </FONT>
<BR><FONT SIZE=2>#- .exponent() might do </FONT>
<BR><FONT SIZE=2>#- the trick.</FONT>
</P>

<P><FONT SIZE=2>No. I think it's a good idea.</FONT>
</P>

<P><FONT SIZE=2>.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Facundo</FONT>
</P>
<BR>
<BR>
<BR>
<BR>

<P><B><FONT SIZE=2>. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .</FONT></B></P>

<P><B><U><FONT SIZE=2>ADVERTENCIA&nbsp;</FONT></U> </B>
</P>

<P><B><FONT SIZE=2>La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley. </FONT></B></P>

<P><B><FONT SIZE=2>Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo. </FONT></B></P>

<P><B><FONT SIZE=2>Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada. </FONT></B></P>

<P><B><FONT SIZE=2>Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje. </FONT></B></P>

<P><B><FONT SIZE=2>Muchas Gracias.</FONT></B>
</P>

</BODY>
</HTML>