[issue15136] Decimal accepting Fraction

2012-08-27 Thread Raymond Hettinger
Raymond Hettinger added the comment: Thanks Nick. I'll go ahead and close this one, leaving the Decimal module only with lossless coercions that do not depend on the decimal context (this matches the underlying design of the decimal module which treats all numbers as exact, and only applying

[issue15136] Decimal accepting Fraction

2012-08-25 Thread Terry J. Reedy
Terry J. Reedy added the comment: After reading the comments, I am ambivalent about a conversion function, and given the lack of consensus or even a clear majority, -1. (Which implies a change in issue title.) I am +1 on using the new .format() machinery to have fractions format themselves. (

[issue15136] Decimal accepting Fraction

2012-08-25 Thread Nick Coghlan
Nick Coghlan added the comment: There is indeed a regression in decimal.localcontext with the C accelerator: omitting the argument entirely still works, but passing None explicitly now fails. I created #15783 for that. On the topic of this thread, I'm also -1 on conversion methods, but +1 on

[issue15136] Decimal accepting Fraction

2012-08-24 Thread Zachary Ware
Zachary Ware added the comment: (Mark:) >To the patch: It looks fine, as far as it goes. It needs tests. I remembered tests about 5 minutes after I submitted the initial patch :P. Here's a patch with some tests. Note that I've never really done tests, so please let me know if there need t

[issue15136] Decimal accepting Fraction

2012-08-24 Thread Stefan Krah
Stefan Krah added the comment: I agree with Mark's arguments. Yesterday I tried to use as_decimal() in a small program and it did not feel natural to me. I'll probably continue to use Decimal(f.numerator) / f.denominator. If this goes in, I'd prefer that as_decimal() always uses a localcontext()

[issue15136] Decimal accepting Fraction

2012-08-24 Thread Mark Dickinson
Mark Dickinson added the comment: > 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 (e

[issue15136] Decimal accepting Fraction

2012-08-24 Thread Chris Rebert
Changes by Chris Rebert : -- nosy: +cvrebert ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python

[issue15136] Decimal accepting Fraction

2012-08-23 Thread Zachary Ware
Zachary Ware added the comment: I came across this issue and thought it might be within my means to attempt a patch, so here's the first step towards one. I liked Terry's suggestion of implementing __format__ using .as_decimal, so that's what I'm working towards with this. The first part is

[issue15136] Decimal accepting Fraction

2012-06-23 Thread Terry J. Reedy
Terry J. Reedy added the comment: I think *both* proposals are sensible. Fraction already has .from_decimal (using Decimal), so .to_decimal (also using Decimal) is sensible. It also has .from_float, with 'f.to_float' spelled f.__float__, normally called as float(f). On the other hand, part of

[issue15136] Decimal accepting Fraction

2012-06-23 Thread Mark Dickinson
Mark Dickinson added the comment: > Something like Fraction.as_decimal(prec=28) would be reasonable. I'd prefer an implementation of Fraction.__format__. That solves the SO user's need exactly. Note that he/she didn't care about the Decimal type, but only wanted to be able to *print* digits

[issue15136] Decimal accepting Fraction

2012-06-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: Something like Fraction.as_decimal(prec=28) would be reasonable. -- priority: normal -> low ___ Python tracker ___ _

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Jon Clements
Jon Clements added the comment: The more I think about this - the shades of grey kick in. D.from_fraction(F or creatable F) Then it would be 'reasonable to assume' for a F.to_decimal() to exist. Possibly with an optional context argument. Then, what happens if I do D('2.45') * F(24 / 19)...

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- versions: +Python 3.4 -Python 3.3 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Mark Dickinson
Mark Dickinson added the comment: BTW, the StackOverflow question helped me understand the use-case here: http://stackoverflow.com/q/11154954/270986 The perspective is that of a *Fraction* user who wants to be able to easily see the Decimal expansion of a Fraction to an arbitrary number of

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Mark Dickinson
Changes by Mark Dickinson : -- nosy: +rhettinger, skrah ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Mark Dickinson
Mark Dickinson added the comment: > would not a classmethod of .from_fraction be welcome? That depends. :-) Certainly a new classmethod seems better to me than extending the constructor to allow Fractions. I'm not convinced that there's a real need for this feature, though, especially given

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Jon Clements
Jon Clements added the comment: Not sure what's going on with my machine today: keep sending things to early. I meant: D.from_fraction(F) where if F is not of type Fraction, then the args are used to construct a Fraction - so can use an existing or create one. -- __

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Jon Clements
Jon Clements added the comment: Mark - I bow to your superiour knowledge here. However, would not a classmethod of .from_fraction be welcome? ie, I could write: d = D.from_fraction(5, 7) Then the documents labour the point about what you've mentioned? Just an idea, but fully realise you're

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Mark Dickinson
Mark Dickinson added the comment: > I guess my question is - should Decimal do this implicitly for Fraction? I'd prefer not. All other cases of Decimal construction (from float, from string, etc.) are lossless with results that don't depend on the current context; construction from a Fracti

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Ramchandra Apte
Ramchandra Apte added the comment: +1 -- nosy: +ramchandra.apte ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue15136] Decimal accepting Fraction

2012-06-22 Thread Jon Clements
New submission from Jon Clements : I'm not a numeric expert but I was looking at a post on S/O which related to converting a Fraction to a certain amount of decimal places. I've had a hunt on the tracker but couldn't find anything relevant, but if I've missed it, I apologise. # F=Fraction, D=