1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-10-27 20:34:12 +00:00

Bugfix: #26 clone

This commit is contained in:
Michael Mclaughlin 2016-02-14 21:13:04 +00:00
parent 948d368527
commit c512eb9a5a
3 changed files with 6 additions and 14 deletions

View File

@ -4356,6 +4356,7 @@
*
*/
function clone(obj) {
var i, p, ps;
/*
* The Decimal constructor and exported function.
@ -4486,18 +4487,10 @@
Decimal.tanh = tanh; // ES6
Decimal.trunc = trunc; // ES6
if (obj === void 0) {
obj = this;
obj = {
precision: obj.precision,
rounding: obj.rounding,
modulo: obj.modulo,
toExpNeg: obj.toExpNeg,
toExpPos: obj.toExpPos,
minE: obj.minE,
maxE: obj.maxE,
crypto: obj.crypto
};
if (obj === void 0) obj = {};
if (obj) {
ps = ['precision', 'rounding', 'toExpNeg', 'toExpPos', 'maxE', 'minE', 'modulo', 'crypto'];
for (i = 0; i < ps.length;) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
}
Decimal.config(obj);

View File

@ -43,7 +43,6 @@ T('ln', function () {
t('96363417.9729392663575231665', '18.3836372059508935007674191717', 30, 0);
t('210401674.5643546532430157', '19.1645289977522148145584372801492541489626022147443118341', 57, 3);
t('952417276.8651321118737418', '20.67451381275802954644121920485653995422386303532469652920020456933991073071', 76, 3);
t('98184005.146079977', '18.4023538796720926822257754284842101571428491604633542324254915295389687459768262219847229005105726462911110014778700105379820806407462050611141071631637279703966033404550534991584986282367905158391520156932087898507160577425969648962582513228749121815449650331654608429478028655815089', 285, 6);
t('142322563.253900033190831713543268828109981967888490291406527346535501984011990242137300064766425179727442507442591862989037644368590904104621357145575632132596634560836335843482822061685451360570260600926717066081883739008412790434377893984866700040372917562269733068809727985812968781985268403920729907489962116060023323078359102582924017315196797171078484331048743611378544575282691634826207', '18.77360661165643483904346', 25, 4);
t('371400293.53826507744653292410472631048281764405036030167939649508120465472946573115185753424640793913438158589233749086894500415028950753895660006551599374916249772634013307822672548085573611750200419176163913242813545244921337312493040312898991903677477383181667469789752847529551033664230833747974881304800992388176411266053764', '19.732790997238693', 17, 5);

View File

@ -3,7 +3,7 @@ if (typeof T === 'undefined') require('../setup');
T('trunc', function () {
function t(expected, n) {
T.assertEqual(expected, Decimal.trunc(n).valueOf());
T.assertEqual(expected, new Decimal(n).trunc().valueOf());
}
Decimal.config({