[Maxima] sign(exp(2009)) --> floating point overflow

Barton Willis willisb at unk.edu
Sat Oct 17 17:12:52 CDT 2009

In sign1, I see some code that looks broken. I commented it out and
then sign(exp(2009)) --> pos. I'm not claiming that a good fix is to
comment out this code--it's just a place I might start looking. Also,
the signbfloat scheme is fundamentally broken.

(defun sign1 (x)
  (setq x (specrepcheck x))
  (setq x (infsimp* x))
  (when (and *complexsign* (atom x) (eq x '$infinity))
    ;; In Complex Mode the sign of infinity is complex.
    (when *debug-compar* (format t "~& in sign1 detect $infintiy.~%"))
    (return-from sign1 '$complex))
  (if (member x '($und $ind $infinity) :test #'eq)
      (if limitp '$pnz (merror (intl:gettext "sign: sign of ~:M is
      undefined.") x)))
  (prog (dum exp)
     (setq dum (constp x) exp x)
     (cond ((or (numberp x) (ratnump x)))
    ((eq dum 'bigfloat)
     (if (prog2 (setq dum ($bfloat x)) ($bfloatp dum))
  (setq exp dum)))
    ((eq dum 'float)
     (if (and (setq dum (numer x)) (numberp dum)) (setq exp dum)))
    ((and (member dum '(numer symbol) :test #'eq) ;; <---- looks bogus to
    me (especially the (< (abs dum) 1.0e-6))
   (prog2 (setq dum (numer x))
       (or (null dum)
    (and (numberp dum)
         (prog2 (setq exp dum)
      (< (abs dum) 1.0e-6)))))) ;; <---- surely this is bogus.
     (cond ($signbfloat
     (and (setq dum ($bfloat x)) ($bfloatp dum) (setq exp dum)))
    (t (setq sign '$pnz evens nil odds (ncons x) minus nil)
       (return sign)))))
     (or (and (not (atom x)) (not (mnump x)) (equal x exp)
       (let (s o e m lhs rhs)
  (compsplt x)
  (dcompare lhs rhs)
  (cond ((member sign '($pos $neg $zero) :test #'eq))
        ((eq sign '$pnz) nil)
        (t (setq s sign o odds e evens m minus)
    (sign x)
    (if (not (strongp sign s))
        (if (and (eq sign '$pnz) (eq s '$pn))
     (setq sign s)
     (setq sign s odds o evens e minus m)))
  (sign exp))
     (return sign)))

-----maxima-bounces at math.utexas.edu wrote: -----

>To: Richard Fateman <fateman at cs.berkeley.edu>
>From: Stavros Macrakis <macrakis at alum.mit.edu>
>Sent by: maxima-bounces at math.utexas.edu
>Date: 10/17/2009 04:06PM
>cc: maxima at math.utexas.edu, Barton Willis <willisb at unk.edu>
>Subject: Re: [Maxima] sign(exp(2009)) --> floating point overflow
>On Sat, Oct 17, 2009 at 4:43 PM, Richard Fateman <fateman at cs.berkeley.edu>
>This problem is somewhere between " not worth fixing" and "too hard to
>solve in general".
>exp(2009) is about 1.5e871, which is too big for a float.
>There's no reason sign needs to convert exp(...) to a float to determine
>that it's positive, since exp(x) is positive for all real x.  Of course,
>if you have sign(exp(2009) - tan(%pi/2-10^-870)), it's harder to avoid
>...but not impossible.  taylor(exp(a)-tan(%pi/2-10^-(k*a),a,inf,0) lets
>you approximate the crossover pretty closely as k=1/log(10) for large a.
>And you can calculate the error term as well.  But no point in going into
>details here.
>               -s
>Maxima mailing list
>Maxima at math.utexas.edu

More information about the Maxima mailing list