
Michael Chermside wrote:
#- I think that we'd do even better to ommit the second #- use. People who #- really want to convert floats exactly can easily write #- "Decimal(1.1, 60)". But #- hardly anyone wants to convert floats exactly, while lots of #- newbies would #- forget to include the second parameter. I'd say just make #- Decimal(someFloat) #- raise a TypeError with a helpful message about how you need #- that second #- parameter when using floats.
I take this in consideration in another response.
#- Really, that's all I came up with. This is great, and I'm #- looking forward to #- using it. I would, though, be interested in a couple more #- syntax-related #- details: #- (a) What's the syntax for changing the context? I'd #- think we'd want #- a "pushDecimalContext()" and "popDecimalContext()" sort of #- approach, since most #- well-behaved routines will want to restore their caller's context.
You can save a copy of the context in a variable and then restore it. No stack.
#- (b) How about querying to determine a thread's current #- context? I don't #- have any use cases, but it would seem peculiar not to provide it.
You do it to save it in a variable.
For example:
from Decimal import * import copy c = getcontext() cc = copy.copy(c) d = Decimal(5.065253542) d
Decimal( (0, (5, 0, 6, 5, 2, 5, 3, 5, 4, 2), -9) )
d + 1 # it will be rounded down
Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 4), -8L) )
c.set_rounding('up') # returns the old rounding
'half_even'
d + 1 # it will be rounded up
Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 5), -8L) )
setcontext(cc) d + 1
Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 4), -8L) )
One question: This kind of stuff, should be in the final documentation? And in the final PEP?
#- (c) Given a Decimal object, is there a straightforward #- way to determine its #- coefficient and exponent? Methods named .precision() and #- .exponent() might do #- the trick.
No. I think it's a good idea.
. 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.