Menu ▾ ▴

#1931 rectform loses some accuracy

open
nobody
5
2012-11-18
2010-03-22
Raymond Toy
No

Consider:

rectform(1e300/(1e300+3/2*%i)) -> 1.0

But

float(rectform(10^300/(10^300+3/2*%i))) -> 1.0 - 1.5e-300 * %i

The inaccuracy is caused by Maxima computing the rectform in two parts. Maxima computes 1/(1e300+3/2*%i) and then multiplies by 1e300. Maxima correctly computes 1/(1e300+3/2*%i) as 1e-300. But doing it in two steps causes the very tiny imaginary part to be lost.

Discussion

  • Dieter Kaiser

    Dieter Kaiser - 2011-08-04

    For the record:

    With SBCL and Maxima 5.25post I get for the example an overflow error:

    (%i1) rectform(1e300/(1e300+3/2*%i));

    Maxima encountered a Lisp error:
    arithmetic error FLOATING-POINT-OVERFLOW signalled
    Automatically continuing.
    To reenable the Lisp debugger set *debugger-hook* to nil.

    I have tried the biggest possible exponent:

    (%i31) float(rectform(1e154/(1e154+3/2*%i)));
    (%o31) 1.0 - 1.5e-154 %i
    (%i32) float(rectform(10^154/(10^154+3/2*%i)));
    (%o32) 1.0 - 1.5e-154 %i

    Dieter Kaiser

     
  • Raymond Toy

    Raymond Toy - 2011-08-19

    That's odd. I tried it with sbcl, and it had no problems with overflow with the given examples.

    More investigation needed.

     
  • Dieter Kaiser

    Dieter Kaiser - 2011-08-19

    Sorry, but today I have checked the example again. Now I get the described results with SBCL:

    Maxima version: 5.25post
    Maxima build date: 19:8 8/14/2011
    Host type: i686-pc-linux-gnu
    Lisp implementation type: SBCL
    Lisp implementation version: 1.0.45

    (%i5) rectform(1e300/(1e300+3/2*%i));
    (%o5) 1.0
    (%i9) float(rectform(10^300/(10^300+3/2*%i)));
    (%o9) 1.0-1.5e-300*%i

    Perhaps, I had some own code in my sandbox. I think I have tried to use the bigfloat-package.

    Dieter Kaiser

     

Log in to post a comment.