[PYTHON MATRIX-SIG] type coercion one more time

James Hugunin jjh@Goldilocks.LCS.MIT.EDU
Thu, 25 Jan 96 10:45:58 EST

   From: Guido van Rossum <guido@CNRI.Reston.VA.US>

   > No automatic coercion will take place between these precisions.

   This surprises me (especially since C does support float -> double
   coercions).  Would you care to explain it?

Naive users of the system are only expected to use arrays of longs,
doubles, and complex doubles.  I wanted to make sure that all of the
automatic coercion rules would work for these most frequently used
types so that they'll work just like the corresponding python scalars.

On the other hand, I see the other types as being used for cases where
the programmer really wants to use a particular precision, ie. 2-byte
integers for dealing with 16-bit sound data.  In a case like this it
seems decidely unfriendly to automatically coerce to another

One can imagine dividing each sample in a sound by 2, and then trying
to play it back and hearing garbage because it got automatically
converted to an array of longs during the division.

I do have one other possible set of rules that I would be happy with.
These are basically the same as the last post, except:

4) Coercion to a higher precision is allowed within the main

5) The precision of a python scalar is allowed to change to match the
other arguments (3.14 can be either a float or a double depending on
which one is "desired").

I don't like this rule, but without it I think that it is too easy to
get bitten by python scalars when writing "real" code.

Does this make sense?

Do people prefer this revised scheme?


MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org