Hack request: rational numbers
Pearu Peterson
pearu at ioc.ee
Fri Jan 26 06:11:45 EST 2001
On 25 Jan 2001, Michael Hudson wrote:
> > is rather clumsy. Clearly, minimal representation of this rational number
> > is
> >
> > 3/4
> >
> > but in Python this expression has different meaning.
>
> Here's an idea: subclass code.InteractiveConsole. Use bytecodehacks
> to find bytecodes like
>
> LOAD_CONST <integer1>
> LOAD_CONST <integer2>
> BINARY_DIVIDE
>
> to
>
> LOAD_GLOBAL "mpq"
> LOAD_CONST <integer1>
> LOAD_CONST <integer2>
> CALL_FUNCTION 2
>
> This isn't actually very difficult, but I'm not going to do it.
And it will break other codes/modules where `3/4' is expected to return
`0'. And it will work only for interactive session, right?
So, I'll not going to do that either.
> > 3) What are changes that these hooks will be accepted to Python core?
>
> Can't speak for the people whose opinions really count, but my guess: none.
It is rather disappointing estimation:(
And it makes me think that (some? most?) people want to keep
Python usage only in web/gui based applications rather than extending its
usage to scientific computing (both *numerical* and *symbolical*).
Sorry to bother you.
> > 4) Is anybody else working with builtin rational number support for
> > Python?
>
> Maybe. I suspect not enough to make a difference. It's mooted that
>
> 1/2
>
> will produce something other than "0" in Py3K, but I can't remember
> whether a rational or a floating point result seemed most likely last
> time this went around.
Though, I'll wait (hope) for Alex's PEP about this and I'll probably try
to implement `3r' hooks to Python myself (it's just too appeling to me;).
Regards,
Pearu
More information about the Python-list
mailing list