Skip to content

Commit 0040376

Browse files
author
shinuza@localhost.localdomain
committed
Update Decimal#mul to work with the new representation format
1 parent 49d8534 commit 0040376

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

decimaljs.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,12 @@ Decimal.prototype.mul = function(target) {
7070
target = Decimal(target);
7171

7272
var ops = [this, target];
73-
ops.sort(function(x, y) {
74-
if(x.exp > y.exp) {
75-
return -1;
76-
}
77-
if(x.exp < y.exp) {
78-
return 1;
79-
}
80-
if(x.exp == y.exp) {
81-
return 0;
82-
}
83-
});
84-
85-
var tiniest = ops[1].exp;
86-
var greatest = ops[0].exp;
8773

8874
var fst = ops[0].repr.value;
89-
var snd = ops[1]._as_exp(greatest);
75+
var snd = ops[1].repr.value;
76+
var calc = String(fst * snd)
9077

91-
var calc = String(fst * snd);
92-
93-
return Decimal._format(calc, greatest + tiniest);
78+
return Decimal._format(calc, ops[0].repr.exp + ops[1].repr.exp);
9479
}
9580

9681

@@ -228,9 +213,9 @@ assert.equals(Decimal('1.2').add('1000'), '1001.2')
228213
assert.equals(Decimal('1.245').add('1010'), '1011.245')
229214
assert.equals(Decimal('5.1').add('1.901'), '7.001')
230215
assert.equals(Decimal('1001.0').add('7.12'), '1008.12')
216+
*/
231217

232-
233-
//* Multiplication
218+
// Multiplication
234219
assert.equals(Decimal('50').mul('2.901'), '145.05')
235220
assert.equals(Decimal('-50').mul('2.901'), '-145.05')
236221
assert.equals(Decimal('-50').mul('-2.901'), '145.05')
@@ -241,6 +226,5 @@ assert.equals(Decimal('-50').mul('-2901'), '145050')
241226

242227
assert.equals(Decimal('1.125').mul('0.1201'), '0.1351125');
243228
assert.equals(Decimal('01.125').mul('0.1201'), '0.1351125');
244-
*/
245229

246230
assert.summary();

0 commit comments

Comments
 (0)