A use for integer quotients

David Eppstein eppstein at ics.uci.edu
Mon Jul 23 11:17:09 EDT 2001

In article <3B5BDCB4.A2010560 at letterror.com>,
 Just van Rossum <just at letterror.com> wrote:

> Do you really want 2047 bytes to be shown as 1 kbyte? Integer division
> is a lousy tool in this particular example...

In an unrelated program I had some more complicated code (in a different 
language, which is why I didn't reuse it) that would take a number n, and 
output n itself, n/1000 + "k", or n/1000000 + "M", where the output number 
was either an integer of two or three digits, or a decimal with a single 
digit on either side of the decimal point.  So 2047 would have been '2.0k'.
(Don't argue with me about decimal vs binary k, this was to output number 
of nodes in a search space not file sizes.)

In the current program, the sizes being shown are for the original 
un-shrunk images from a digicam, and are never anywhere near as small as 
2047 bytes, so I used simpler logic to simplify the size output.

In both cases, I want integer divisions (in the other program, even the 
decimals were formatted using integer division).
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/

More information about the Python-list mailing list