quaternion.js
function(w, x, y, z) {

      parse(P, w, x, y, z);

      if (P['y'] === 0 && P['z'] === 0) {

        if (P['w'] === 1 && P['x'] === 0) {
          return this;
        }

        if (P['w'] === 0 && P['x'] === 0) {
          return Quaternion['ONE'];
        }

        // Check if we can operate in C
        // Borrowed from complex.js
        if (this['y'] === 0 && this['z'] === 0) {

          var a = this['w'];
          var b = this['x'];

          if (a === 0 && b === 0) {
            return Quaternion['ZERO'];
          }

          var arg = Math.atan2(b, a);
          var loh = logHypot(a, b);

          if (P['x'] === 0) {

            if (b === 0 && a >= 0) {

              return new Quaternion(Math.pow(a, P['w']), 0, 0, 0);

            } else if (a === 0) {

              switch (P['w'] % 4) {
                case 0:
                  return new Quaternion(Math.pow(b, P['w']), 0, 0, 0);
                case 1:
                  return new Quaternion(0, Math.pow(b, P['w']), 0, 0);
                case 2:
                  return new Quaternion(-Math.pow(b, P['w']), 0, 0, 0);
                case 3:
                  return new Quaternion(0, -Math.pow(b, P['w']), 0, 0);
              }
            }
          }

          a = Math.exp(P['w'] * loh - P['x'] * arg);
          b = P['x'] * loh + P['w'] * arg;
          return new Quaternion(
                  a * Math.cos(b),
                  a * Math.sin(b), 0, 0);
        }
      }

      // Normal quaternion behavior
      // q^p = e^ln(q^p) = e^(ln(q)*p)
      return this.log().mul(P).exp();
    }
function(w, x, y, z) {

      parse(P, w, x, y, z);

      if (P['y'] === 0 && P['z'] === 0) {

        if (P['w'] === 1 && P['x'] === 0) {
          return this;
        }

        if (P['w'] === 0 && P['x'] === 0) {
          return Quaternion['ONE'];
        }

        // Check if we can operate in C
        // Borrowed from complex.js
        if (this['y'] === 0 && this['z'] === 0) {

          var a = this['w'];
          var b = this['x'];

          if (a === 0 && b === 0) {
            return Quaternion['ZERO'];
          }

          var arg = Math.atan2(b, a);
          var loh = logHypot(a, b);

          if (P['x'] === 0) {

            if (b === 0 && a >= 0) {

              return new Quaternion(Math.pow(a, P['w']), 0, 0, 0);

            } else if (a === 0) {

              switch (P['w'] % 4) {
                case 0:
                  return new Quaternion(Math.pow(b, P['w']), 0, 0, 0);
                case 1:
                  return new Quaternion(0, Math.pow(b, P['w']), 0, 0);
                case 2:
                  return new Quaternion(-Math.pow(b, P['w']), 0, 0, 0);
                case 3:
                  return new Quaternion(0, -Math.pow(b, P['w']), 0, 0);
              }
            }
          }

          a = Math.exp(P['w'] * loh - P['x'] * arg);
          b = P['x'] * loh + P['w'] * arg;
          return new Quaternion(
                  a * Math.cos(b),
                  a * Math.sin(b), 0, 0);
        }
      }

      // Normal quaternion behavior
      // q^p = e^ln(q^p) = e^(ln(q)*p)
      return this.log().mul(P).exp();
    }
function ( w , x , y , z ) { parse ( P , w , x , y , z ) ; if ( P [ 'y' ] === 0 && P [ 'z' ] === 0 ) { if ( P [ 'w' ] === 1 && P [ 'x' ] === 0 ) { return this ; } if ( P [ 'w' ] === 0 && P [ 'x' ] === 0 ) { return Quaternion [ 'ONE' ] ; } // Check if we can operate in C // Borrowed from complex.js if ( this [ 'y' ] === 0 && this [ 'z' ] === 0 ) { var a = this [ 'w' ] ; var b = this [ 'x' ] ; if ( a === 0 && b === 0 ) { return Quaternion [ 'ZERO' ] ; } var arg = Math . atan2 ( b , a ) ; var loh = logHypot ( a , b ) ; if ( P [ 'x' ] === 0 ) { if ( b === 0 && a >= 0 ) { return new Quaternion ( Math . pow ( a , P [ 'w' ] ) , 0 , 0 , 0 ) ; } else if ( a === 0 ) { switch ( P [ 'w' ] % 4 ) { case 0 : return new Quaternion ( Math . pow ( b , P [ 'w' ] ) , 0 , 0 , 0 ) ; case 1 : return new Quaternion ( 0 , Math . pow ( b , P [ 'w' ] ) , 0 , 0 ) ; case 2 : return new Quaternion ( - Math . pow ( b , P [ 'w' ] ) , 0 , 0 , 0 ) ; case 3 : return new Quaternion ( 0 , - Math . pow ( b , P [ 'w' ] ) , 0 , 0 ) ; } } } a = Math . exp ( P [ 'w' ] * loh - P [ 'x' ] * arg ) ; b = P [ 'x' ] * loh + P [ 'w' ] * arg ; return new Quaternion ( a * Math . cos ( b ) , a * Math . sin ( b ) , 0 , 0 ) ; } } // Normal quaternion behavior // q^p = e^ln(q^p) = e^(ln(q)*p) return this . log ( ) . mul ( P ) . exp ( ) ; }
Calculates the power of a quaternion raised to a real number or another quaternion

@param {number|Object|string} w real
@param {number=} x imag
@param {number=} y imag
@param {number=} z imag
@returns {Quaternion}
Calculates the power of a quaternion raised to a real number or another quaternion