A Revised Rational Proposal

Batista, Facundo FBatista at uniFON.com.ar
Mon Dec 27 08:17:23 EST 2004


[Mike Meyer]

#- When combined with a floating type - either complex or float - or a
#- decimal type, the result will be a TypeError.  The reason for this is
#- that floating point numbers - including complex - and decimals are
#- already imprecise.  To convert them to rational would give an

I'm ok with raising TypeError when mixing with float.

Bu tI think that it should interact with decimal, as decimal is not
imprecise: you can go Decimal->Rational and viceversa without losing
information.

As I posted in a previous message:

To convert a Decimal to Rational, just take the number and divide it by
1E+n:

  Decimal(5) -> Rational(5)
  Decimal("5.35") -> Rational(535, 100)

To convert a Rational to a Decimal, it would be a good idea to have a method
that converts the Rational to a Decimal string...

  Rational(5).tostring(6) -> "5.00000"
  Rational(4, 5).tostring(3) -> "0.80"
  Rational(5321351343, 2247313131).tostring(5000) -> whatever

... and then take that string as input to Decimal and it will work.


#- - Should raising a rational to a non-integer rational 
#- silently produce
#-   a float, or raise an InvalidOperation exception?

I think that it never should decay into float silently.


  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
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/20041227/0e8d3e85/attachment.html>


More information about the Python-list mailing list