Menu

#370 Problems with IEEE-float NaN and INF

None
open
nobody
5
2022-11-10
2003-08-01
No

flinf: 2.0^1024$

flinf => Error: Can't print a non-number (lisp break)
Should print something special, e.g. INFe0

flnan: flinf-flinf$

flnan => Bind stack overflow (lisp break)
Should print something special, e.g. NaNe0

is(flnan=flnan) => TRUE NO! NaN is not equal to itself;
cf ?=(flnan,flnan).

is(flnan>0) => TRUE NO!
is(flnan<0) => TRUE NO!

flnan*0 => 0 NO!
flinf*0 => 0 NO!

GCL also can't print flnan/flinf.

Maxima 5.9.0 gcl 2.5.0 mingw Windows 2000 Athlon

Discussion

  • Robert Dodier

    Robert Dodier - 2005-06-26

    Logged In: YES
    user_id=501686

    In reference to the examples given in the original write-up,
    it is worth pointing out that GCL does indeed compute inf
    and nan; it just can't display them.

    Clisp refuses to compute the inf or nan, and there doesn't
    appear to be a way to compel it to do so.

    CMUCL is happy with inf and nan after :lisp
    (extensions::set-floating-point-modes :traps nil) is executed.

     
  • Robert Dodier

    Robert Dodier - 2006-07-08
    • labels: --> 460522
     
  • Robert Dodier

    Robert Dodier - 2006-07-08

    Logged In: YES
    user_id=501686

    Clisp does not recognize floating point INF and NAN; those 2
    values cannot be produced or recognized by Clisp's floating
    point implementation (which is all software for greater
    portability). So I can't see any way, short of modifying
    Clisp, for Maxima to accomodate INF and NAN in a way that is
    workable across Lisp implementations.

    We could probably convince the GCL team to modify GCL to
    handle INF and NAN; that seems a lesser challenge than
    getting Clisp modified.

     
  • Robert Dodier

    Robert Dodier - 2006-09-09
    • labels: 460522 --> Lisp Core - Floating point
     
  • Robert Dodier

    Robert Dodier - 2022-11-03
    • labels: Lisp Core - Floating point --> floating point, gcl, error handling
    • Group: --> None
     
  • Robert Dodier

    Robert Dodier - 2022-11-03

    Just tried it with GCL 2.6.12 (near 2.6.13) + post-5.46, and I get 2.0^1024 resulting in false. Not sure what to think about that.

     
  • Camm Maguire

    Camm Maguire - 2022-11-10

    Sorry for the terse reply!

    2.0^1024.1; => #<inf>, with which we can test the original submitters
    results (to whom I refer as "he").</inf>

    2.0^1024; => false, which I have traced to a failure somewhere in
    maxima's #'simpexpt (not simp-expt, sorry for the typo), and appears
    independent of running the code compiled or not.

    I seem to have one small remaining issue in expt, but others seem to
    remain in maxima:

    =============================================================================
    (%i16) flinf:2.0^1024;
    (%o16) false
    (%i17) flinf:2.0^1024.1;
    (%o17) #<inf>
    (%i18) flnan:flinf-flinf;
    (%o18) #<-nan>
    (%i19) flnan;
    (%o19) #<-nan>
    (%i20) is(flnan=flnan);
    (%o20) true
    (%i21) :lisp (= $flnan $flnan)</inf>

    NIL
    (%i21) cf?=(flnan,flnan);

    incorrect syntax: = is not an infix operator
    cf?=(
    ^
    (%i21) is(flnan>0);
    (%o21) true
    (%i22) is(flnan<0);
    (%o22) true
    (%i23) :lisp (< $flnan 0)

    1> (< #<-nan> 0)
    <1 (< NIL)
    NIL
    (%i23) :lisp (> $flnan 0)

    NIL
    (%i23) flnan^0;
    (%o23) 1.0
    (%i24) flinf^0;
    (%o24) 1.0
    (%i25) :lisp (expt $flnan 0)

    1.0
    (%i25) :lisp (expt $flinf 0)

    1.0
    (%i25) flinf;
    (%o25) #<inf>
    (%i26)
    (%i29) :lisp (trace simpexpt)</inf>

    (SIMPEXPT)
    (%i29) flinf:2.0^1024;

    1> (SIMPEXPT ((MEXPT) 2.0 1024) 1 NIL)
    <1 (SIMPEXPT NIL)
    (%o29) false
    (%i30) flinf:2.0^1024.1;

    1> (SIMPEXPT ((MEXPT) 2.0 1024.1) 1 NIL)
    <1 (SIMPEXPT #<inf>)
    (%o30) #<inf>
    (%i31)
    =============================================================================</inf></inf>

     
  • Camm Maguire

    Camm Maguire - 2022-11-10

    This clears the 'false' result noticed recently:

    modified src/simp.lisp
    @@ -1003,9 +1003,9 @@
    (t
    (setq b (expt a (- b)))
    (*red 1 b)))))

    • (if (float-inf-p result) ;; needed for gcl - no trap of overflow
    • (signal 'floating-point-overflow)
    • result)))
    • (when (float-inf-p result) ;; needed for gcl - no trap of overflow
    • (signal 'floating-point-overflow))
    • result))
     

Log in to post a comment.