[ann] Minimal Python project

Andrew McGregor andrew at indranet.co.nz
Tue Jan 14 21:33:35 EST 2003


--On Tuesday, January 14, 2003 15:24:17 -0800 Jimmy Retzlaff 
<jimmy at retzlaff.com> wrote:

> Skip Montanaro wrote:
>>   Jimmy> Psyco created two specialized versions of my function - one
> for
>>   Jimmy> use with integers and another for use with floating point
>>   Jimmy> numbers.
>>
>> Which, depending on the particular computation, might differ
> semantically
>> from one another, what with floating point inaccuracies and all.
>> ...
>
> Isn't this issue inherent in Python and not introduced by Psyco? I was
> actually calling the function in question with objects of type int in
> some cases and with objects of type float in other cases. Hence the
> potential differences were already there before Psyco (but not an issue
> in my particular case). I don't think Psyco changed the situation.
>
> My C version did have potential semantic differences from the Python
> version in that parameters to it were always coerced to doubles. Hence
> any distinctive int parameter behavior was lost (again not an issue in
> my particular case).
>
> Now if Psyco were so aggressive as to look at parameter values and
> decide that, for example, 17.0 could be treated as an object of type
> int, then there indeed could be serious issues. This would be especially
> true if uses of the operator / were present without "from __future__
> import division" or if magnitudes were large enough to induce any
> overflow behavior. I don't see any other issues off the top of my head,
> but I'm certainly not an expert on the intricacies of binary floating
> point.
>
> Jimmy

Basically, if it ever matters about things like arithmetic precision, you 
coerce things to the right type and make sure of it, in any language.  It 
is nice not to have to write multiple versions of the code if there is need 
to handle several kinds of numbers, though.

Andrew





More information about the Python-list mailing list