[PYTHON MATRIX-SIG] type coercion one more time

Hinsen Konrad hinsenk@ere.umontreal.ca
Thu, 25 Jan 1996 13:46:05 -0500

   You can also lose precision by coercing a long to a double, but
   nobody's complaining about that.  Also, the only place you can lose

That's not exactly the same problem. More importantly, it is
a much less frequent problem.

   precision is in a python scalar so I'm not really worried about this.
   Admittedly, array([1,2,3], 'f')*3.1415926535 might cause you to lose
   some precision in pi, but I assume that this is what most people would

In this case, with an explicit constant, I agree that most people
would probably want a float result. But suppose you are using a
library function that does float calculations and returns a float
array as a result. You call this function and multiply its result with
a double that you have obtained from some complicated high-precision
calculation. Wouldn't you be both surprised and annoyed if the
result were a float array?

   Add three more names, "GenericInt", "GenericFloat", "GenericComplex"
   (or whatever).

   Now I can say a = array(1, "GenericFloat") and this means that in
   general a will behave as a double, but it can be coerced downwards to
   a float if required.

Why not make it float from the beginning? If you can't rely on the
extra precision being conserved, you could just as well forget about
it. I don't see much use for "unknown precision" numbers.

   Now, 3.14 -> array(3.14, "GenericFloat").

   Does this seem conceptually clean?

Conceptually clean, yes. But it is a somewhat weird concept.

Let me start another approach to the problem: do you see a need for
"downcasting" anything else than constants? In that case one could
think about some special treatment for them.

Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. Centre-Ville     | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)

MATRIX-SIG  - SIG on Matrix Math for Python

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