Interesting list Validity (True/False)

G

Gabriel Genellina

The gmpy designer, writer and maintainer (all in the singular -- that's
me) has NOT chosen anything of the sort. gmpy.mpz does implement
__int__ and __long__ -- but '%d'%somempzinstance chooses not to call
either of them. sys.maxint has nothing to do with the case:
'%d'%somelonginstance DOES work just fine -- hey, even a *float*
instance formats just fine here (it gets truncated). I personally
consider this a bug in %d-formatting, definitely NOT in gmpy.

Yes, sorry, at first I thought it was gmpz which refused to convert itself
to long. But the fault is in the string formatting code, and it was
pointed out later on this same thread. Floats have the same problem: "%d"
% 5.2 does work, but "%d" % 1e30 does not.

After digging a bit in the implementation of PyString_Format, for a "%d"
format it does:
- test if the value to be printed is actually a long integer (using
PyLong_Check). Yes? Format as a long integer.
- else, convert the value into a plain integer (using PyInt_AsLong), and
format that.
No attempt is made to *convert* the value to a long integer. I understand
that this could be a slow operation, so the various tests should be
carefully ordered, but anyway the __long__ conversion should be done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,274
Messages
2,571,368
Members
48,060
Latest member
JerrodSimc

Latest Threads

Top