mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
Renamed methods 'copy' to 'clone'
This commit is contained in:
parent
0c41367b6f
commit
cf8cf46d63
@ -52,7 +52,7 @@ function add(x, y) {
|
||||
throw new Error('Unit on right hand side of operator + has no value');
|
||||
}
|
||||
|
||||
var res = x.copy();
|
||||
var res = x.clone();
|
||||
res.value += y.value;
|
||||
res.fixPrefix = false;
|
||||
return res;
|
||||
|
||||
@ -33,7 +33,7 @@ function divide(x, y) {
|
||||
|
||||
if (x instanceof Unit) {
|
||||
if (isNumber(y)) {
|
||||
var res = x.copy();
|
||||
var res = x.clone();
|
||||
res.value /= y;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ function multiply(x, y) {
|
||||
return multiplyComplex(new Complex(x, 0), y);
|
||||
}
|
||||
else if (y instanceof Unit) {
|
||||
res = y.copy();
|
||||
res = y.clone();
|
||||
res.value *= x;
|
||||
return res;
|
||||
}
|
||||
@ -36,7 +36,7 @@ function multiply(x, y) {
|
||||
}
|
||||
else if (x instanceof Unit) {
|
||||
if (isNumber(y)) {
|
||||
res = x.copy();
|
||||
res = x.clone();
|
||||
res.value *= y;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -50,7 +50,6 @@ function pow(x, y) {
|
||||
|
||||
if (y == 0) {
|
||||
// return the identity matrix
|
||||
// TODO: implement method eye
|
||||
return eye(s[0]);
|
||||
}
|
||||
else {
|
||||
|
||||
@ -52,7 +52,7 @@ function subtract(x, y) {
|
||||
throw new Error('Unit on right hand side of operator - has no value');
|
||||
}
|
||||
|
||||
var res = x.copy();
|
||||
var res = x.clone();
|
||||
res.value -= y.value;
|
||||
res.fixPrefix = false;
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ function unaryminus(x) {
|
||||
);
|
||||
}
|
||||
else if (x instanceof Unit) {
|
||||
var res = x.copy();
|
||||
var res = x.clone();
|
||||
res.value = -x.value;
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ function unit_in(x, unit) {
|
||||
throw new Error('Unit expected on the right hand side of function in');
|
||||
}
|
||||
|
||||
var res = unit.copy();
|
||||
var res = unit.clone();
|
||||
res.value = x.value;
|
||||
res.fixPrefix = true;
|
||||
|
||||
|
||||
@ -278,9 +278,9 @@ function isComplex(value) {
|
||||
|
||||
/**
|
||||
* Create a copy of the complex value
|
||||
* @return {Complex} copy
|
||||
* @return {Complex} clone
|
||||
*/
|
||||
Complex.prototype.copy = function () {
|
||||
Complex.prototype.clone = function () {
|
||||
return new Complex(this.re, this.im);
|
||||
};
|
||||
|
||||
|
||||
@ -249,9 +249,9 @@ function isUnit(value) {
|
||||
|
||||
/**
|
||||
* create a copy of this unit
|
||||
* @return {Unit} copy
|
||||
* @return {Unit} clone
|
||||
*/
|
||||
Unit.prototype.copy = function () {
|
||||
Unit.prototype.clone = function () {
|
||||
var clone = new Unit();
|
||||
|
||||
for (var p in this) {
|
||||
|
||||
@ -31,30 +31,14 @@
|
||||
console.log('a = ' + workspace.getResult(id0));
|
||||
console.log('a + 2 = ' + workspace.getResult(id1));
|
||||
|
||||
console.log();
|
||||
console.log(new Unit('0.01m').toString());
|
||||
console.log(new Unit('0.1m').toString());
|
||||
console.log(new Unit('0.5m').toString());
|
||||
console.log(new Unit('0.6m').toString());
|
||||
console.log(new Unit('1m').toString());
|
||||
console.log(new Unit('10m').toString());
|
||||
console.log(new Unit('100m').toString());
|
||||
console.log(new Unit('200m').toString());
|
||||
console.log(new Unit('300m').toString());
|
||||
console.log(new Unit('400m').toString());
|
||||
console.log(new Unit('499m').toString());
|
||||
console.log(new Unit('500m').toString());
|
||||
console.log(new Unit('501m').toString());
|
||||
console.log(new Unit('502m').toString());
|
||||
console.log(new Unit('510m').toString());
|
||||
console.log(new Unit('520m').toString());
|
||||
console.log(new Unit('600m').toString());
|
||||
console.log(new Unit('700m').toString());
|
||||
console.log(new Unit('800m').toString());
|
||||
console.log(new Unit('900m').toString());
|
||||
console.log(new Unit('1000m').toString());
|
||||
console.log(new Unit('1100m').toString());
|
||||
console.log(new Unit('1200m').toString());
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@ -77,12 +77,12 @@ assert.equal(new Complex(1, 0).toString(), '1');
|
||||
assert.equal(new Complex(-1, 2).toString(), '-1 + 2i');
|
||||
assert.equal(new Complex(-1, 1).toString(), '-1 + i');
|
||||
|
||||
// test copy
|
||||
var copy = complex1.copy();
|
||||
copy.re = 100;
|
||||
copy.im = 200;
|
||||
assert.notEqual(complex1, copy);
|
||||
// test clone
|
||||
var clone = complex1.clone();
|
||||
clone.re = 100;
|
||||
clone.im = 200;
|
||||
assert.notEqual(complex1, clone);
|
||||
assert.equal(complex1.re, 3);
|
||||
assert.equal(complex1.im, -4);
|
||||
assert.equal(copy.re, 100);
|
||||
assert.equal(copy.im, 200);
|
||||
assert.equal(clone.re, 100);
|
||||
assert.equal(clone.im, 200);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user