[Matrix-SIG] Numeric Nits--a slightly different proposal

Rick White rlw@stsci.edu
Thu, 15 Jul 1999 18:33:35 -0400 (EDT)


Michael Haggerty writes:

>Instead of creating new datatypes with weird places the type
>hierarchy, let's rather define an additional attribute of the array
>typecodes which might be called `force'.  So an array with typecode
>ForcedFloat32 (I prefer a spelling such as 'f*') would be identical to
>an array with typecode 'f' except that the result of ANY operation
>involving such an array would be coerced to the same typecode, namely
>'f*'.  Similarly, all of the other existing typecodes would have
>forced versions.

I think this is fine, and this was one of the first ideas
that we discussed internally to solving the unwanted promotion
problem.  As you say, the results are really the same whether
it is called a separate type or the same type with an additional
attribute.  Whichever is cleanest in implementation and use
should be preferred.

I'd prefer a shorter name than 'ForcedFloat32', but the basic
idea looks good to me.

>An expression involving two incompatible
>forced objects would raise an exception.

I can't agree with that, though.  I'm afraid that will result
in more ugly, hard-to-read code with lots of explicit casts.
I believe that an operation between two forced objects should
obey the normal promotion rules, with the lower forced type
being promoted to the higher forced type.

- Rick White