"Strong typing vs. strong testing"

MRAB python at mrabarnett.plus.com
Wed Sep 29 14:18:51 EDT 2010


On 29/09/2010 18:54, Thomas A. Russ wrote:
> George Neuner<gneuner2 at comcast.net>  writes:
>
>> On Tue, 28 Sep 2010 12:15:07 -0700, Keith Thompson<kst-u at mib.org>
>> wrote:
>>> He didn't say it was.  Internal calculations are done in SI units (in
>>> this case, m^3/sec); on output, the internal units can be converted to
>>> whatever is convenient.
>>
>> That's true.  But it is a situation where the conversion to SI units
>> loses precision and therefore probably shouldn't be done.
>
> I suppose that one has to choose between two fundamental designs for any
> computational system of units.  One can either store the results
> internally in a canonical form, which generally means an internal
> representation in SI units.  Then all calculations are performed using
> the interal units representation and conversion happens only on input or
> output.
>
> Or one can store the values in their original input form, and perform
> conversions on the fly during calculations.  For calculations one will
> still need to have some canonical representation for cases where the
> result value doesn't have a preferred unit provided.  For internal
> calculations this will often be the case.
>
> Now whether one will necessarily have a loss of precision depends on
> whether the conversion factors are exact or approximations.  As long as
> the factors are exact, one can have the internal representation be exact
> as well.  One method would be to use something like the Commmon Lisp
> rational numbers or the Gnu mp library.
>
> And a representation where one preserves the "preferred" unit for
> display purposes based on the original data as entered is also nice.
> Roman Cunis' Common Lisp library does that, and with the use of rational
> numbers for storing values and conversion factors allows one to do nice
> things like make sure that
>
>      30mph * 3h = 90mi
>
> even when the internal representation is in SI units (m/s, s, m).
>
You could compare it to handling strings, where Unicode is used
internally and the encoding can be preserved for when you want to
output.



More information about the Python-list mailing list