[Python-Dev] Cross-platform math functions?
Nick Maclaren
nmm1 at cus.cam.ac.uk
Tue Sep 5 10:51:43 CEST 2006
Andreas Raab <andreas.raab at gmx.de> wrote:
>
> I'm curious if there is any interest in the Python community to achieve
> better cross-platform math behavior. A quick test[1] shows a
> non-surprising difference between the platform implementations.
> Question: Is there any interest in changing the behavior to produce
> identical results across platforms (for example by utilizing fdlibm
> [2])? Since I have need for a set of cross-platform math functions I'll
> probably start with a math-compatible fdlibm module (unless somebody has
> done that already ;-)
>
> [1] Using Python 2.4:
> >>> import math
> >>> math.cos(1.0e32)
>
> WinXP: -0.39929634612021897
> LinuxX86: -0.49093671143542561
Well, I hope not, but I am afraid that there is :-(
The word "better" is emotive and inaccurate. Such calculations are
numerically meaningless, and merely encourage the confusion between
consistency and correctness. There is a strong sense in which giving
random results between -1 and 1 would be better.
Now, I am not saying that you don't have a requirement for consistency
but I am saying that confusing it with correctness (as has been fostered
by IEEE 754, Java etc.) is harmful. One of the great advantages of the
wide variety of arithmetics available in the 1970s is that numerical
testing was easier and more reliable - if you got wildly different
results on two platforms, you got a strong pointer to numerical problems.
That viewpoint is regarded as heresy nowadays, but used not to be!
Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email: nmm1 at cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
More information about the Python-Dev
mailing list