From: Steven D'Aprano on
On Fri, 02 Apr 2010 12:35:55 -0700, Mensanator wrote:

>> If you want an exact result when multiplying arbitrary fractions, you
>> need to avoid floats and decimals and use Fractions:
>>
>> >>> Fraction(1, 2)**2
>>
>> Fraction(1, 4)
>
> Where do you get that from?

Where do I get what from? Fraction? Oops, sorry about that.

In Python2.6:

>>> from fractions import Fraction

In older Pythons, there was a demo module Demo/classes/Rat.py but it may
not be installed on your system. See http://bugs.python.org/issue1682

If you meant, where did I get the statement about exact results from,
both float and Decimal are fixed precision numbers. float precision is
fixed by the operating system and/or hardware; Decimal precision can be
arbitrarily chosen by the caller, but having made that choice,
calculations are rounded to that precision. Only Fraction gives exact
results for any arbitrary rational number.



--
Steven
From: Mensanator on
On Apr 2, 6:07 pm, Steven D'Aprano <st...(a)REMOVE-THIS-
cybersource.com.au> wrote:
> On Fri, 02 Apr 2010 12:35:55 -0700, Mensanator wrote:
> >> If you want an exact result when multiplying arbitrary fractions, you
> >> need to avoid floats and decimals and use Fractions:
>
> >> >>> Fraction(1, 2)**2
>
> >> Fraction(1, 4)
>
> > Where do you get that from?
>
> Where do I get what from? Fraction? Oops, sorry about that.
>
> In Python2.6:
>
> >>> from fractions import Fraction

Ok, thanks. I've been using gmpy to do rational arithmetic:

>>> import gmpy
>>> gmpy.mpq(1,2)**2
mpq(1,4)

But I don't have a lot of call for it.

>
> In older Pythons, there was a demo module Demo/classes/Rat.py but it may
> not be installed on your system. Seehttp://bugs.python.org/issue1682
>
> If you meant, where did I get the statement about exact results from,
> both float and Decimal are fixed precision numbers. float precision is
> fixed by the operating system and/or hardware; Decimal precision can be
> arbitrarily chosen by the caller, but having made that choice,
> calculations are rounded to that precision. Only Fraction gives exact
> results for any arbitrary rational number.

Yes, rationals are handy sometimes.

>
> --
> Steven

From: Mensanator on
On Apr 2, 2:34 pm, Patrick Maupin <pmau...(a)gmail.com> wrote:
> On Apr 2, 2:41 pm, Andreas Waldenburger <use...(a)geekmail.INVALID>
> wrote:
>
> > While everyone else is mocking you: Can you please elaborate on why you
> > want to know and what kind of problem you're trying to solve with this?
> > Also, don't you think you should have picked a maths forum for this
> > kind of question?
>
> Methinks the OP is fluent in the way of choosing newsgroups.
> According to google, he has posted 6855 messages in 213 groups.

Does that really mean anything? Hell, I have 12765 messages
posted to 332 groups, but I only use 10 regularly.

>
> http://groups.google.com/groups/profile?enc_user=ul3SQhIAAAAYmLD0Oj5Y....
>
> And I can't speak for anybody else, but I just assumed it was an April
> Fool's question.  I meant to be laughing with the OP, not at him, so
> sorry if I misunderstood.
>
> Regards,
> Pat

From: Patrick Maupin on
On Apr 2, 6:50 pm, Mensanator <mensana...(a)aol.com> wrote:
> On Apr 2, 2:34 pm, Patrick Maupin <pmau...(a)gmail.com> wrote:
>
> > Methinks the OP is fluent in the way of choosing newsgroups.
> > According to google, he has posted 6855 messages in 213 groups.
>
> Does that really mean anything? Hell, I have 12765 messages
> posted to 332 groups, but I only use 10 regularly.

Well, I have been very wrong in my assumptions before, but yes, I do
assume it means something:

- I assume that the OP knows of the existence of more than one
newsgroup.

- I assume the OP knows how to locate different newsgroups, either via
search or some directory like yahoo, and is able to think about which
one he wants to post to and why.

- I assume that he is comfortable with the process of posting. In
fact, looking at the stats, about half as comfortable as mensanator,
and over 18 times as comfortable as me ;-)

Of course, I could be all wet in my assumptions, and it may just be
that the OP has a cat constantly walking back and forth across his
keyboard...

Regards,
Pat
From: Mensanator on
On Apr 2, 7:32 pm, Patrick Maupin <pmau...(a)gmail.com> wrote:
> On Apr 2, 6:50 pm, Mensanator <mensana...(a)aol.com> wrote:
>
> > On Apr 2, 2:34 pm, Patrick Maupin <pmau...(a)gmail.com> wrote:
>
> > > Methinks the OP is fluent in the way of choosing newsgroups.
> > > According to google, he has posted 6855 messages in 213 groups.
>
> > Does that really mean anything? Hell, I have 12765 messages
> > posted to 332 groups, but I only use 10 regularly.
>
> Well, I have been very wrong in my assumptions before, but yes, I do
> assume it means something:

Yes, you are, in fact, all wet.

>
> - I assume that the OP knows of the existence of more than one
> newsgroup.

"More than one", that's fair. 213, unlikely.

>
> - I assume the OP knows how to locate different newsgroups, either via
> search or some directory like yahoo, and is able to think about which
> one he wants to post to and why.

And most of those probably involved no thought at all, probably
due to cross-posting from a relatively small number of sources
(certainly in my case). So, no, this stat proves nothing about
the OP's ability to find newsgroups or think about their
appropriateness.

>
> - I assume that he is comfortable with the process of posting.  In
> fact, looking at the stats, about half as comfortable as mensanator,
> and over 18 times as comfortable as me ;-)

Well, _I've_ been here on Usenet for 10 years. But despite the stats,
I know little about most to the groups I've "posted to".

>
> Of course, I could be all wet in my assumptions, and it may just be
> that the OP has a cat constantly walking back and forth across his
> keyboard...

Don't you know how Usenet works?

>
> Regards,
> Pat

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Prev: free proxy & fast
Next: C-style static variables in Python?