Re: Interesting list Validity (True/False)



En Fri, 18 May 2007 01:48:29 -0300, Alex Martelli <aleax@xxxxxxx> escribió:

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.

--
Gabriel Genellina

.



Relevant Pages

  • Re: Completely baffled on what should be simple
    ... the same thing I previously did, changing format to custom ... sort, it didn't work. ... if a cell contains the text ...
    (microsoft.public.excel.misc)
  • Re: Completely baffled on what should be simple
    ... And remember just changing the format of the cell won't change the underlying ... sort, it didn't work. ... for the extensions that have either one or two 0's as the first numbers, ...
    (microsoft.public.excel.misc)
  • Re: Sane Syntax
    ... It's sort of like a game of telephone - if converting ... I don't know much about DocBook, but tsy's "Super DocBook" format does ... capability for visual markup, ... material before it was typeset. ...
    (comp.text.tex)
  • Re: Sort order - Data midified / Created
    ... What you suggest is a kludge to get around a Windows flaw. ... on the sub heading "Change the date, time, or number format" On the Formats ... All I do is click on the column header and the sort happens, ...
    (microsoft.public.windows.vista.general)
  • B-Tree Index Usage
    ... to write programs using/abusing an editor instead of the proper programming ... By the way my latest testing indicates that a Sort will not use a date index ... interpretation betwwen ACCESS and a program. ... to get the proper format the program DM,BP, DATE will still give one the ...
    (comp.databases.pick)