[Python-Dev] 2.2.1c1 platform reports. (original) (raw)

Tim Peters tim.one@comcast.net
Fri, 22 Mar 2002 15:19:24 -0500


[Hye-Shik Chang, reports on a particular sqrt implementation]

...

I'll submit PR to both of FreeBSD and NetBSD.

[Michael Hudson]

I'm not sure it's a problem. I believe it depends on whether you believe in C89 or C99, for instance.

It's cute: even in C99, an implementation must treat sqrt(negative_number) as a domain error. However, under C99 rules:

On a domain error, the function returns an implementation-defined
value; whether the integer expression errno acquires the value
EDOM is implementation-defined.

So while it's mandatory that an implementation detect that sqrt(-1) is a domain error case, there's no x-platform way defined anymore for the library to communciate the error condition to the caller.

That's why the exception test isn't run by default: C doesn't supply any x-platform error facility Python can build on anymore. Python tries to guess whether a range error occurred ("most of the time", C99 stilll requires that HUGE_VAL specifically get returned then), but there's no way to guess about domain errors short of Python hard-coding its own rules about the proper domain on a function by function basis.

Do that, and in the end you get a library that still honks off IEEE-754 fans anyway (which has its own elaborate and precise rules for dealing with fp exceptions).

can't-win-without-more-work-than-anyone-will-give-it-ly y'rs - tim