<!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: prePEP: Decimal data type</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>Paul Moore wrote:</FONT>
</P>

<P><FONT SIZE=2>#- >> When passing floating point to the constructor, what </FONT>
<BR><FONT SIZE=2>#- should happen?</FONT>
<BR><FONT SIZE=2>#- >></FONT>
<BR><FONT SIZE=2>#- >>     j. ``Decimal(1.1) == Decimal('1.1')``</FONT>
<BR><FONT SIZE=2>#- >>     k. ``Decimal(1.1) ==</FONT>
<BR><FONT SIZE=2>#- >> Decimal('110000000000000008881784197001252...e-51')``</FONT>
<BR><FONT SIZE=2>#- ></FONT>
<BR><FONT SIZE=2>#- > Clearly, j is the correct answer. It's not all that hard </FONT>
<BR><FONT SIZE=2>#- to do, either.</FONT>
<BR><FONT SIZE=2>#- </FONT>
<BR><FONT SIZE=2>#- No way. Consider:</FONT>
<BR><FONT SIZE=2>#- </FONT>
<BR><FONT SIZE=2>#- >>> 1.1</FONT>
<BR><FONT SIZE=2>#- 1.1000000000000001</FONT>
<BR><FONT SIZE=2>#- >>> 1.1==1.1000000000000001</FONT>
<BR><FONT SIZE=2>#- True</FONT>
<BR><FONT SIZE=2>#- </FONT>
<BR><FONT SIZE=2>#- So what should Decimal(1.1000000000000001) evaluate to? It can't be</FONT>
<BR><FONT SIZE=2>#- Decimal('1.1'), as that contradicts your statement that j "clearly"</FONT>
<BR><FONT SIZE=2>#- applies. But it *also* can't be </FONT>
<BR><FONT SIZE=2>#- Decimal('1.1000000000000001'), as then</FONT>
<BR><FONT SIZE=2>#- we have the *same number* converting to two *different* Decimal</FONT>
<BR><FONT SIZE=2>#- values.</FONT>
</P>

<P><FONT SIZE=2>This is really the problem. Option (j) seems to be correct but is not. Option (k) *is* correct, but not what you want to do, :(</FONT></P>

<P><FONT SIZE=2>Maybe the more natural solution is not to accept float (you always can write that *same* number as a string, and it'll be correct, and sure i'll be doing what you expect).</FONT></P>
<BR>
<BR>

<P><FONT SIZE=2>#- into :-) Having a special method, say Decimal.round_float(f, digits),</FONT>
<BR><FONT SIZE=2>#- is probably OK, though...</FONT>
</P>

<P><FONT SIZE=2>Mmmm. Digits in the first meaning or the second? Should round or truncate?</FONT>
</P>
<BR>
<BR>
<BR>
<BR>

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

<P><B><U><FONT SIZE=2>ADVERTENCIA </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>