complex.js
function() {

      var a = this['re'];
      var b = this['im'];
      var r = this['abs']();

      var re, im;

      if (a >= 0) {

        if (b === 0) {
          return new Complex(Math.sqrt(a), 0);
        }

        re = 0.5 * Math.sqrt(2.0 * (r + a));
      } else {
        re = Math.abs(b) / Math.sqrt(2 * (r - a));
      }

      if (a <= 0) {
        im = 0.5 * Math.sqrt(2.0 * (r - a));
      } else {
        im = Math.abs(b) / Math.sqrt(2 * (r + a));
      }

      return new Complex(re, b < 0 ? -im : im);
    }
function() {

      var a = this['re'];
      var b = this['im'];
      var r = this['abs']();

      var re, im;

      if (a >= 0) {

        if (b === 0) {
          return new Complex(Math.sqrt(a), 0);
        }

        re = 0.5 * Math.sqrt(2.0 * (r + a));
      } else {
        re = Math.abs(b) / Math.sqrt(2 * (r - a));
      }

      if (a <= 0) {
        im = 0.5 * Math.sqrt(2.0 * (r - a));
      } else {
        im = Math.abs(b) / Math.sqrt(2 * (r + a));
      }

      return new Complex(re, b < 0 ? -im : im);
    }
function ( ) { var a = this [ 're' ] ; var b = this [ 'im' ] ; var r = this [ 'abs' ] ( ) ; var re , im ; if ( a >= 0 ) { if ( b === 0 ) { return new Complex ( Math . sqrt ( a ) , 0 ) ; } re = 0.5 * Math . sqrt ( 2.0 * ( r + a ) ) ; } else { re = Math . abs ( b ) / Math . sqrt ( 2 * ( r - a ) ) ; } if ( a <= 0 ) { im = 0.5 * Math . sqrt ( 2.0 * ( r - a ) ) ; } else { im = Math . abs ( b ) / Math . sqrt ( 2 * ( r + a ) ) ; } return new Complex ( re , b < 0 ? - im : im ) ; }
Calculate the complex square root

@returns {Complex}
Calculate the complex square root