A use for integer quotients

Terry Reedy tjreedy at home.com
Mon Jul 23 10:06:30 EDT 2001


"Just van Rossum" <just at letterror.com> wrote in message
news:3B5BDCB4.A2010560 at letterror.com...
> David Eppstein wrote:
>
> > Ok, you convinced me to look more carefully at all the divisions
in my
> > recent small project, a program to generate web pages from
collections of
> > JPEGs.  I found:
> >
> > 3 instances of simplifying numbers prior to output (e.g. I want
file size
> > in kbytes rather than bytes).
> > [ ... ]
>
> Do you really want 2047 bytes to be shown as 1 kbyte?
> Integer division is a lousy tool in this particular example...

Just, this is stupid, wrong, and gratuitously insulting,
and therefore, in my opinion, ugly and nasty.

As for the first line: unless you have seen Eppstein's code, which I
assume not, you do not know what divisor he uses (both k = 1000 and
1024 have been by various people, as have both m = 1000000 and
1024*1024).  You do no know whether he truncates down, rounds [(bytes
+ k/2)/k], or truncates up.  You do not know that a difference of +-1
matters a bit to him and his audience, or that his program ever
encounters 2K microjpegs.  Given the care he described in choosing his
focal length formula and the care he exhibited in examining his code
and reporting the results, it is reasonable to assume that he made
what he considers to be sensible choices for reporting file sizes.
Who are you to assume otherwise?

As for the second line: do you really think
int(float(bytes)/float(k)+.5) is signigicantly better for rounding?
If so, that is a statement of anti-integer float-religion preference,
not fact.

I am beginning to think that there is something wrong with a proposal
that apparently has to be promoted by bulldozing away reasonable
skepticism.

Terry J. Reedy





More information about the Python-list mailing list