This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Ramchandra Apte, cvrebert, eric.smith, joncle, mark.dickinson, rhettinger, skrah, terry.reedy, zach.ware
Date 2012-08-24.08:53:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1345798406.06.0.972462058511.issue15136@psf.upfronthosting.co.za>
In-reply-to
Content
> I think *both* proposals are sensible. Fraction already has .from_decimal
> (using Decimal), so .to_decimal (also using Decimal) is sensible.

Well, there's a difference: conversion from Decimal to Fraction is well-defined, with a unique, unambiguous result (excluding non-convertibles like infinities and nans);  in particular, the value of any Decimal is exactly representable as a Fraction, so there's little information loss.  (There *is* still some information loss, since Decimal('1.00') and Decimal('1.0') both covert to the same fraction, for example.)

On the other hand, not every Fraction is exactly representable as a Decimal, so the result of conversion from Fraction to Decimal needs information about how many decimal places to produce, what rounding mode to use, what the ideal exponent should be in the case of exact results, etc.  I think Zachary's idea of supporting a context argument, and using the current context if none is supplied, is the way to go here.  The division should end up using an ideal exponent of 0, which doesn't seem unreasonable.

To the patch:  It looks fine, as far as it goes.  It needs tests.  To avoid the repetition of the division code, I'd suggest doing something like:

    if context is None:
        context = getcontext()

Yes, supporting __format__ is going to be a bit more work. :-)
History
Date User Action Args
2012-08-24 08:53:26mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, terry.reedy, eric.smith, cvrebert, skrah, joncle, Ramchandra Apte, zach.ware
2012-08-24 08:53:26mark.dickinsonsetmessageid: <1345798406.06.0.972462058511.issue15136@psf.upfronthosting.co.za>
2012-08-24 08:53:25mark.dickinsonlinkissue15136 messages
2012-08-24 08:53:24mark.dickinsoncreate