A use for integer quotients

Stephen Horne steve at lurking.demon.co.uk
Tue Jul 24 00:23:33 CEST 2001


On 23 Jul 2001 13:57:59 -0700, Johann Hibschman
<johann at physics.berkeley.edu> wrote:

>[followup accidentally mailed as well; sorry Steve!]
>
>Steve Horne writes:
>
>> Tell that to a mathematician, or an engineer, or even an accountant -
>> all of these need to deal with inherently integer measures and
>> therefore using integer operations. Any of these people who have
>> Python scripts using division are going to have a problem.
>
>Well, I'll believe you for accountants, but they generally want
>a fixed decimal class anyway, don't they?  However...

No - converting pence to pounds is just a presentation issue - all you
do is draw a point. In a lot of my code you'll find a 'GUI' equivalent
of...

print "£ " + str(amount / 100) + "." + str(amount % 100)

I have *THOUSANDS* of lines like that.

>
>> Engineering - How would you feel if you knew a bridge was going to be
>> built with 2.5 supports on each side?
>
>Engineers who use division almost always use floating point division.

For tasks where it is appropriate yes - but those two half-supports
aren't really doing much supporting, are they ;-)

I use floats a lot for signal processing in C++ as a hobby, and I have
worked in defence applications using C, Ada and assembler. These are
all doing physics-style calculations in real time - if you can imagine
the code to derive helicopter intrument data from two pressure
sensors, a thermometer and a stick that tends to point into the wind,
you're starting to get a vague idea. Now realise that that the
pressure sensors rely on resonant frequency detection - you've got to
keep them vibrating at roughly the right frequency (well into KHz
range) and detect their tendency towards a higher frequency to watch
for changes. All with a very slow microcontroller, a few registers,
less than 1K RAM, and less ROM than a Spectrum. And *that* was *easy*
compared with the direction probe and temperature sensor - the result
of reducing mass production costs by having the absolute minimum
hardware (the microcontroller and a few mainly passive extra
components) and use easily copied software to do the job.

Sorry - I forgot the bit about implementing a military standard
communication protocol on dual redundant busses to pass the results
on, and of course keeping an eye on the dual redundant box to detect
and handle inconsistent results.

I *KNOW* how programming for real engineering tasks works because I
have spent quite a few years doing it.

>> Mathematics - Mathemeticians practically *invented* integers, and note
>> that integers were understood thousands of years before fractions,
>> decimals or standard form.
>
>And mathematicians know you can't divide the integers, because they're
>a ring and not a field.

Depends on the context. A quotient and a remainder is common and
simple, and the only thing that makes sense for general integers.

>> Have you noticed how none of these groups consists of experienced
>> programmers?
>
>Anyway, there are two camps.  The proposed new behavior would make my
>life easier, so I like it.  It's also "the right thing" from a
>mathematical point of view.  Others clearly disagree.

They are *NOT* the right thing from a mathematical point of view -
integer division in mathematics gives an integer quotient and integer
remainder as any five-year-old knows.

If you are so keen on int <op> int -> float, why is it *ME* that has
to change operators and not *YOU*. Is it really just that it makes
*YOUR* life easier so sod everyone else?




More information about the Python-list mailing list