prePEP: Decimal data type

Batista, Facundo FBatista at uniFON.com.ar
Tue Nov 4 13:26:35 EST 2003


bokr at oz.net wrote:

#- (First, thanks for the plain-text post ;-)

This is not my choice. I *always* send the mail as plain-text. 

But sometimes (and I don't know specifically when) the mail server convert
it to RTF and adds a warning ad, :(. The perils of working to a
Exchange-Mail-Server kind of enterprise.


#-     I.e., '1.1' means something different from '1.1000', 
#- even though hopefully
#-     Decimal('1.1')==Decimal('1.1000').

Decimal('1.1') == Decimal('1.1000') == Decimal(11) / Decimal(10)


#- >1. The syntax should be ``Decimal(value)``.
#-     Decimal(value, precision_info) when the value cannot be 
#- presumed exact, IWT.
#- >
#- >2. The value could be of the type:
#- >
#- >       - another Decimal
#-           presume this is just a copy, unless precision info 
#- is provided?

That's right.


#- >       - int or long
#-           assume no-fractional-bits precision?

Remember that the precision is in the context.


#-           even if there is an exponent? I.e., what does 
#- '1.000e3' mean? Same as '1000' or
#-           '1000.000' ? What about '1.000e-2' ? Same as 
#- '0.010' or as '0.01' ?

Decimal('1.000e3') == Decimal('1000') == Decimal('1000.000') 

and

Decimal('1.000e-2') == Decimal('0.010') == Decimal('0.01') 

as a human can tell! :)


#- Maybe there needs to be an abstract base class that you 
#- _have_ to subclass and
#- specify all these things?

You just specify in the context what type of rounding you want. And that's
all.


#- >       m = Decimal(...)
#- >       m == eval(repr(m))
#- Does that mean repr(m) will always look like 
#- "Decimal('<string literal>')" ?

Still don't know.


#- But what about rules for precision promotion -- i.e., if you add
#- Decimal('1.1') and Decimal('0.05') I would expect the result 
#- to have the
#- more precise precision, and repr like "Decimal('1.15')"

Remember the precision is in the context, not in each instance. 


#- I have a hunch (a*b)*c could sometimes come out different 
#- from a*(b*c)
#- if rounding-to-specified-precision is imposed at every operation.

This can happen, as with all the roundings data types.

Anyway, you always can set the "rounding" trap in the context to raise an
exception...

.	Facundo





. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
ADVERTENCIA  

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. 

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. 

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. 

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. 

Muchas Gracias.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20031104/3c6fd529/attachment.html>


More information about the Python-list mailing list