NaN again - and IEEE arithmatics

Randall Hopper aa8vb at yahoo.com
Tue May 16 15:36:50 CEST 2000


Huaiyu Zhu:
 |Tim Peters:
 |>>>> Inf = 1e300**2
 |>>>> NaN = Inf - Inf
 |>>>> NaN
 |>-1.#IND
 |>>>> Inf
 |>1.#INF
 |>>>>
...
 |Thanks a lot.  It works on both:
 |
 |RedHat 6.1 egcs-2.91.66  Python 1.5.2 -> nan
 |Solaris 2.7 gcc 2.95.2 Python 1.6a2   -> NaN
 |
 |>> So why isn't there a predefined class or object for NaN?
...
 |>The next iteration of the C standard is supposed to address this.
...
 |In the interim it might be worthwhile to implement temporary standard Inf
 |and NaN objects for a few "popular" platforms like Solaris, NT and Linux:
 |
 |1. It helps to standardize the name, useful for dumping or loading numbers.
 |   It would be easy to change when the "true standard" arrives in the future
 |   then would a hundred differently named hacks.
 |2. For users of other OSes it provides working examples of how such things
 |   are supposed to be done so they can implemente them in a more or less
 |   standard way.


Another key point to throw into the pot is that you may not even be able to
play with NaNs or Inf's at all, depending on:
     - which OS you're on
     - the facilities provided by the system C library
     - how Python was built
     - the Python run-time environment
     - whether the signal and/or fpectl modules have been used to
       change SIGFPE behavior

Depending on the details, you may core dump Python generating one of these
values.

For example:

   ----------------------------------------------------------------------------
   > setenv TRAP_FPE "UNDERFL=DEFAULT;OVERFL=ABORT;DIVZERO=ABORT;INVALID=ABORT"
   > python
   Python 1.5.2 (#4, Apr 10 2000, 08:27:39) [C] on irix646-n32
   Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
   >>> Inf = 1e300**2

   libfpe: PID 1420826 aborting; limit reached for trap type OVERFLOW 
   Abort (core dumped)

   ----------------------------------------------------------------------------
   > setenv TRAP_FPE "UNDERFL=DEFAULT;OVERFL=DEFAULT;DIVZERO=ABORT;INVALID=ABORT"
   > python
   Python 1.5.2 (#4, Apr 10 2000, 08:27:39) [C] on irix646-n32
   Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
   >>> Inf = 1e300**2
   >>> Inf
   inf
   >>>

   ----------------------------------------------------------------------------

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list