预订演示
前页 后页

cdiv

Division.

SYNOPSIS:

typedef struct {
      double r;     real part
      double i;     imaginary part
     }cmplx;

cmplx *a, *b, *c;

cdiv(a, b, c);     c = b / a

DESCRIPTION:

    d    =  a.r * a.r  +  a.i * a.i
    c.r  = (b.r * a.r  + b.i * a.i)/d
    c.i  = (b.i * a.r  -  b.r * a.i)/d

ACCURACY:

In DEC arithmetic, the test (1/z) * z = 1 had peak relative error 3.1e-17, rms 1.2e-17.  The test (y/z) * (z/y) = 1 had peak relative error 8.3e-17, rms 2.1e-17.

Tests in the rectangle {-10,+10}:

                      Relative error:
arithmetic   function  # trials      peak         rms
    DEC        cadd       10000       1.4e-17     3.4e-18
    IEEE       cadd      100000       1.1e-16     2.7e-17
    DEC        csub       10000       1.4e-17     4.5e-18
    IEEE       csub      100000       1.1e-16     3.4e-17
    DEC        cmul        3000       2.3e-17     8.7e-18
    IEEE       cmul      100000       2.1e-16     6.9e-17
    DEC        cdiv       18000       4.9e-17     1.3e-17
    IEEE       cdiv      100000       3.7e-16     1.1e-16

JavaScript:

var a = {"r":0.5,"i",0.5};
var b = {"r":0.5,"i",0.5};
var c = cephes.cdiv(a,b);
Session.Output("c.r=" + c.r + ", c.i=" + c.i);