complex.js
function(a, b) {

      var z = new Complex(a, b);

      // 0 / 0 = NaN and Infinity / Infinity = NaN
      if ((this['isZero']() && z['isZero']()) || (this['isInfinite']() && z['isInfinite']())) {
        return Complex['NAN'];
      }

      // Infinity / 0 = Infinity
      if (this['isInfinite']() || z['isZero']()) {
        return Complex['INFINITY'];
      }

      // 0 / Infinity = 0
      if (this['isZero']() || z['isInfinite']()) {
        return Complex['ZERO'];
      }

      a = this['re'];
      b = this['im'];

      var c = z['re'];
      var d = z['im'];
      var t, x;

      if (0 === d) {
        // Divisor is real
        return new Complex(a / c, b / c);
      }

      if (Math.abs(c) < Math.abs(d)) {

        x = c / d;
        t = c * x + d;

        return new Complex(
                (a * x + b) / t,
                (b * x - a) / t);

      } else {

        x = d / c;
        t = d * x + c;

        return new Complex(
                (a + b * x) / t,
                (b - a * x) / t);
      }
    }
function(a, b) {

      var z = new Complex(a, b);

      // 0 / 0 = NaN and Infinity / Infinity = NaN
      if ((this['isZero']() && z['isZero']()) || (this['isInfinite']() && z['isInfinite']())) {
        return Complex['NAN'];
      }

      // Infinity / 0 = Infinity
      if (this['isInfinite']() || z['isZero']()) {
        return Complex['INFINITY'];
      }

      // 0 / Infinity = 0
      if (this['isZero']() || z['isInfinite']()) {
        return Complex['ZERO'];
      }

      a = this['re'];
      b = this['im'];

      var c = z['re'];
      var d = z['im'];
      var t, x;

      if (0 === d) {
        // Divisor is real
        return new Complex(a / c, b / c);
      }

      if (Math.abs(c) < Math.abs(d)) {

        x = c / d;
        t = c * x + d;

        return new Complex(
                (a * x + b) / t,
                (b * x - a) / t);

      } else {

        x = d / c;
        t = d * x + c;

        return new Complex(
                (a + b * x) / t,
                (b - a * x) / t);
      }
    }
function ( a , b ) { var z = new Complex ( a , b ) ; // 0 / 0 = NaN and Infinity / Infinity = NaN if ( ( this [ 'isZero' ] ( ) && z [ 'isZero' ] ( ) ) || ( this [ 'isInfinite' ] ( ) && z [ 'isInfinite' ] ( ) ) ) { return Complex [ 'NAN' ] ; } // Infinity / 0 = Infinity if ( this [ 'isInfinite' ] ( ) || z [ 'isZero' ] ( ) ) { return Complex [ 'INFINITY' ] ; } // 0 / Infinity = 0 if ( this [ 'isZero' ] ( ) || z [ 'isInfinite' ] ( ) ) { return Complex [ 'ZERO' ] ; } a = this [ 're' ] ; b = this [ 'im' ] ; var c = z [ 're' ] ; var d = z [ 'im' ] ; var t , x ; if ( 0 === d ) { // Divisor is real return new Complex ( a / c , b / c ) ; } if ( Math . abs ( c ) < Math . abs ( d ) ) { x = c / d ; t = c * x + d ; return new Complex ( ( a * x + b ) / t , ( b * x - a ) / t ) ; } else { x = d / c ; t = d * x + c ; return new Complex ( ( a + b * x ) / t , ( b - a * x ) / t ) ; } }
Divides two complex numbers

@returns {Complex}
Divides two complex numbers