Re: Using fractions instead of floats

2007-10-04 Thread Steven D'Aprano
On Tue, 02 Oct 2007 06:07:15 +, Rhamphoryncus wrote: > On Sep 30, 7:35 pm, andresj <[EMAIL PROTECTED]> wrote: >> I was doing some programming in Python, and the idea came to my mind: >> using fractions instead of floats when doing 2/5. > > The core problem wit

Re: Using fractions instead of floats

2007-10-04 Thread Steven D'Aprano
On Thu, 04 Oct 2007 02:47:27 -0700, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> > implementation in pure Python). Finally, arithmetic would become >> > very confusing if there were three distinct numeric types; it already >> > causes enough confusion with two! > > There's

Re: Using fractions instead of floats

2007-10-04 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > > implementation in pure Python). Finally, arithmetic would become very > > confusing if there were three distinct numeric types; it already causes > > enough confusion with two! There's already ints, longs, floats, complexes, and decimals. What's th

Re: Using fractions instead of floats

2007-10-04 Thread Steven D'Aprano
On Mon, 01 Oct 2007 09:09:21 -0700, Arnaud Delobelle wrote: > As pointed out by others, implementations of rationals in Python abound. > Whereas there is a canonical representation of floats and ints (and even > longints) in the machine, it is not the case for rationals. Moreover > most programmin

Re: Using fractions instead of floats

2007-10-03 Thread Raymond L. Buvel
Neil Cerutti wrote: >> Another guess could be that real numbers being closed under the >> four arithmetic operations, there is no danger to accidentally >> step into complex numbers. OTOH floats and rationals are two >> (conflicting) ways of extending integers. > > You would have to adopt a few s

Re: Using fractions instead of floats

2007-10-02 Thread [EMAIL PROTECTED]
On Oct 2, 10:12?pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Tue, 02 Oct 2007 01:59:35 -0300, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> escribi : > > > How does gmpy make the conversion from float to rational? > > Well, you know, these days valuable software usually comes with something

Re: Using fractions instead of floats

2007-10-02 Thread Gabriel Genellina
En Tue, 02 Oct 2007 01:59:35 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribi�: > How does gmpy make the conversion from float to rational? Well, you know, these days valuable software usually comes with something people call "documentation". Incomprehensible documents in strange formats

Re: Using fractions instead of floats

2007-10-02 Thread Robert Kern
[EMAIL PROTECTED] wrote: > On Oct 2, 1:12 am, Robert Kern <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >>> How does gmpy make the conversion from float to rational? >> gmpy has a configurable transformation between floats and the internal >> representation. I believe the default goes thr

Re: Using fractions instead of floats

2007-10-02 Thread [EMAIL PROTECTED]
On Oct 2, 5:43 pm, [EMAIL PROTECTED] wrote: > On Oct 2, 5:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > But it is still wrong to say "0.6 is definitely not the same as 3/5". > > Out of context, I'd certainly agree. But from the context, I assumed > it was clear that the 0.6 was a Pyt

Re: Using fractions instead of floats

2007-10-02 Thread richyjsm
On Oct 2, 5:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > But it is still wrong to say "0.6 is definitely not the same as 3/5". Out of context, I'd certainly agree. But from the context, I assumed it was clear that the 0.6 was a Python float. I probably should have made this clearer.

Re: Using fractions instead of floats

2007-10-02 Thread [EMAIL PROTECTED]
On Oct 2, 1:12 am, Robert Kern <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > On Oct 1, 8:17?pm, [EMAIL PROTECTED] wrote: > >> On Oct 1, 9:03 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > >>> On Oct 1, 7:20 pm, [EMAIL PROTECTED] wrote: > On Oct 1, 8:30 am, Nick Craig-Wood <

Re: Using fractions instead of floats

2007-10-02 Thread Neil Cerutti
On 2007-10-02, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Oct 2, 12:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> > Scheme has prefix numeric operators, so that 1/2 is >> > unambiguously (for the interpreter and the user) a lit

Re: Using fractions instead of floats

2007-10-02 Thread Arnaud Delobelle
On Oct 2, 12:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > > Scheme has prefix numeric operators, so that 1/2 is > > unambiguously (for the interpreter and the user) a litteral for > > 'the fraction 1/2'. You can't avoid the confusion

Re: Using fractions instead of floats

2007-10-02 Thread Neil Cerutti
On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Oct 1, 6:26 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> >> > Finally, arithmetic would become very confusing if there were >> > three distinct numeric types; it already c

Re: Using fractions instead of floats

2007-10-01 Thread Robert Kern
[EMAIL PROTECTED] wrote: > On Oct 1, 8:17?pm, [EMAIL PROTECTED] wrote: >> On Oct 1, 9:03 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> >>> On Oct 1, 7:20 pm, [EMAIL PROTECTED] wrote: On Oct 1, 8:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > >>> mpq(1,3)+0.6 > mpq(14,1

Re: Using fractions instead of floats

2007-10-01 Thread Rhamphoryncus
On Sep 30, 7:35 pm, andresj <[EMAIL PROTECTED]> wrote: > I was doing some programming in Python, and the idea came to my mind: > using fractions instead of floats when doing 2/5. The core problem with rationals (other than the inability to handle irrationals) is their tendency to requ

Re: Using fractions instead of floats

2007-10-01 Thread [EMAIL PROTECTED]
On Oct 1, 8:17?pm, [EMAIL PROTECTED] wrote: > On Oct 1, 9:03 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > On Oct 1, 7:20 pm, [EMAIL PROTECTED] wrote: > > > > On Oct 1, 8:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > > > >>> mpq(1,3)+0.6 > > > > mpq(14,15) > > > > Golly! T

Re: Using fractions instead of floats

2007-10-01 Thread Terry Reedy
"andresj" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] || I know from __future__ import division changes the behaivour to return | floats instead of ints, but what I meant is to be able to implement a | function (or class/method) which would return what _I_ want/decide. When you d

Re: Using fractions instead of floats

2007-10-01 Thread richyjsm
On Oct 1, 9:03 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Oct 1, 7:20 pm, [EMAIL PROTECTED] wrote: > > > On Oct 1, 8:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > > >>> mpq(1,3)+0.6 > > > mpq(14,15) > > > Golly! That's quite impressive. And more than a little bit magic

Re: Using fractions instead of floats

2007-10-01 Thread [EMAIL PROTECTED]
On Oct 1, 7:20 pm, [EMAIL PROTECTED] wrote: > On Oct 1, 8:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > >>> mpq(1,3)+0.6 > > mpq(14,15) > > Golly! That's quite impressive. And more than a little bit magic as > well, since 0.6 is definitely not the same as 3/5. It's not? Since whe

Re: Using fractions instead of floats

2007-10-01 Thread [EMAIL PROTECTED]
On Oct 1, 7:09 pm, andresj <[EMAIL PROTECTED]> wrote: > > > On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > > > > > Finally, arithmetic would become very confusing if there were > > > > three distinct numeric types; it already causes enough > > > > confusion with two! > > Well, yeah...

Re: Using fractions instead of floats

2007-10-01 Thread richyjsm
On Oct 1, 8:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > >>> mpq(1,3)+0.6 > mpq(14,15) Golly! That's quite impressive. And more than a little bit magic as well, since 0.6 is definitely not the same as 3/5. How on earth does this work? Richard -- http://mail.python.org/mailman/list

Re: Using fractions instead of floats

2007-10-01 Thread andresj
> > On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > > > > Finally, arithmetic would become very confusing if there were > > > three distinct numeric types; it already causes enough > > > confusion with two! Well, yeah... I get what you are saying, that would be confusing... Terry Re

Re: Using fractions instead of floats

2007-10-01 Thread Arnaud Delobelle
On Oct 1, 6:26 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > > > Finally, arithmetic would become very confusing if there were > > three distinct numeric types; it already causes enough > > confusion with two! > > Scheme says: It's not th

Re: Using fractions instead of floats

2007-10-01 Thread Neil Cerutti
On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > Finally, arithmetic would become very confusing if there were > three distinct numeric types; it already causes enough > confusion with two! Scheme says: It's not that bad. -- Neil Cerutti I am free of all prejudices. I hate everyone e

Re: Using fractions instead of floats

2007-10-01 Thread Arnaud Delobelle
On Oct 1, 2:35 am, andresj <[EMAIL PROTECTED]> wrote: [snip Rational numbers in Python] > I would like to get some feedback on this idea. Has this been posted > before? If so, was it rejected? and for what? > Also, I would like to know if you have improvements on the initial > design, and if it w

Re: Fwd: Using fractions instead of floats

2007-10-01 Thread Stargaming
On Sun, 30 Sep 2007 20:10:05 -0700, Andres Riofrio wrote: [snip] >>From what I've read, seems that the principal reason for rejecting the > PEP is that there was not much need (enthusiasm)... Well, then I have a > question: Is there a way to make 5/2 return something other than an > integer? I can

Re: Using fractions instead of floats

2007-10-01 Thread Nick Craig-Wood
Gabriel Genellina <[EMAIL PROTECTED]> wrote: > And gmpy: http://www.aleax.it/gmpy.html And a concrete example >>> from gmpy import mpq >>> mpq(1,3)+mpq(0.4) mpq(11,15) >>> mpq(1,3)+mpq(4,10) mpq(11,15) >>> mpq(1,3)+mpq(6,10) mpq(14,15) >>> mpq(1,3)+0.6 mpq(14,15) >>> mpq(5,2)

Re: Fwd: Using fractions instead of floats

2007-10-01 Thread Laurent Pointal
Andres Riofrio a écrit : > Well, then I have > a question: Is there a way to make 5/2 return something other than an > integer? >>> from __future__ import division >>> 5/2 2.5 -- http://mail.python.org/mailman/listinfo/python-list

Re: Fwd: Using fractions instead of floats

2007-09-30 Thread Gabriel Genellina
En Mon, 01 Oct 2007 00:10:05 -0300, Andres Riofrio <[EMAIL PROTECTED]> escribi�: > From what I've read, seems that the principal reason for rejecting the > PEP is that there was not much need (enthusiasm)... Well, then I have > a question: Is there a way to make 5/2 return something other than a

Re: Using fractions instead of floats

2007-09-30 Thread Terry Reedy
"Andres Riofrio" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | a question: Is there a way to make 5/2 return something other than an | integer? >>> from __future__ import division >>> 1/2 0.5 >>> 5/2 2.5 tjr -- http://mail.python.org/mailman/listinfo/python-list

Re: Using fractions instead of floats

2007-09-30 Thread Gabriel Genellina
En Sun, 30 Sep 2007 23:36:23 -0300, George Sakkis <[EMAIL PROTECTED]> escribi�: > On Sep 30, 9:35 pm, andresj <[EMAIL PROTECTED]> wrote: >> I was doing some programming in Python, and the idea came to my mind: >> using fractions instead of floats when doing 2/5.

Fwd: Using fractions instead of floats

2007-09-30 Thread Andres Riofrio
35 pm, andresj <[EMAIL PROTECTED]> wrote: > > I was doing some programming in Python, and the idea came to my mind: using > > fractions instead of floats when doing 2/5. > > (...) > > I would like to get some feedback on this idea. Has this been posted > > before?

Re: Using fractions instead of floats

2007-09-30 Thread George Sakkis
On Sep 30, 9:35 pm, andresj <[EMAIL PROTECTED]> wrote: > I was doing some programming in Python, and the idea came to my mind: using > fractions instead of floats when doing 2/5. > (...) > I would like to get some feedback on this idea. Has this been posted > before? If so,

Re: Using fractions instead of floats

2007-09-30 Thread [EMAIL PROTECTED]
On Sep 30, 8:35?pm, andresj <[EMAIL PROTECTED]> wrote: > I was doing some programming in Python, and the idea came to my mind: > using fractions instead of floats when doing 2/5. > > The problem arises when you try to represent some number, like 0.4 in > a float. It will tel

Re: Using fractions instead of floats

2007-09-30 Thread andresj
On Sep 30, 6:48 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > andresj <[EMAIL PROTECTED]> writes: > > The problem arises when you try to represent some number, like 0.4 in > > a float. > > Which is really a specific case of the general problem that, for any > given number base, some non-integer numbe

Re: Using fractions instead of floats

2007-09-30 Thread Ben Finney
andresj <[EMAIL PROTECTED]> writes: > The problem arises when you try to represent some number, like 0.4 in > a float. Which is really a specific case of the general problem that, for any given number base, some non-integer numbers cannot be exactly represented as fractions. > Secondly, what hap

Using fractions instead of floats

2007-09-30 Thread andresj
I was doing some programming in Python, and the idea came to my mind: using fractions instead of floats when doing 2/5. The problem arises when you try to represent some number, like 0.4 in a float. It will tell you that it's equal to 0.40002. "This is easy to fix", yo