Changeset 39097
- Timestamp:
- 01/05/12 13:40:20 (17 months ago)
- Files:
-
- 1 modified
-
lang/javascript/math-complex/trunk/complex.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/math-complex/trunk/complex.js
r39093 r39097 1 1 /* 2 * $Id: complex.js,v 0.1 0 2012/01/04 08:57:08dankogai Exp dankogai $2 * $Id: complex.js,v 0.11 2012/01/05 04:31:57 dankogai Exp dankogai $ 3 3 * 4 4 * Licensed under the MIT license. … … 12 12 if (global.Math.Complex) return; 13 13 Math.Complex = function Complex(re, im) { 14 if (this instanceof Math.Complex) { 14 if (re instanceof Math.Complex) { 15 return new Math.Complex(re.re, re.im); 16 } else if (this instanceof Math.Complex) { 15 17 this.re = re ? 0 + re : 0; 16 18 this.im = im ? 0 + im : 0; … … 35 37 for (var p in methods) CPLX.prototype[p] = methods[p]; 36 38 for (var p in methods) CPLX[p] = (function(method) { 37 return function() { 38 var args = slice.call(arguments), 39 self = args.shift(); 39 return function(self) { 40 40 if (! (self instanceof CPLX)) self = new CPLX(self); 41 return method.apply(self, args);41 return method.apply(self, slice.call(arguments, 1)); 42 42 } 43 43 })(methods[p]); … … 150 150 }); 151 151 /* functions exported for convenience */ 152 global.cplx = function(re, im) { return new CPLX(re, im) };152 global.cplx = function(re, im) { return new CPLX(re, im) }; 153 153 global.cplxe = function(abs, arg) { 154 154 return new CPLX(abs * Math.cos(arg), abs * Math.sin(arg));
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)