mirror of
https://github.com/MikeMcl/decimal.js.git
synced 2026-03-02 03:49:24 +00:00
Initial commit
This commit is contained in:
489
test/perf/bigtime.js
Normal file
489
test/perf/bigtime.js
Normal file
@@ -0,0 +1,489 @@
|
||||
/*
|
||||
For help:
|
||||
$ node bigtime -h
|
||||
|
||||
Usage example:
|
||||
Compare the time taken by the Decimal plus method and the BigDecimal add method.
|
||||
Time 10000 calls to each.
|
||||
Use operands of up to 40 random digits (each unique for each iteration).
|
||||
Check that the Decimal results match the BigDecimal results.
|
||||
|
||||
$ node bigtime plus 10000 40
|
||||
*/
|
||||
|
||||
var arg, i, j, max, mc, method, methodIndex, precision, rounding, reps, start,
|
||||
timesEqual, xs, ys, prevRss, prevHeapUsed, prevHeapTotal, showMemory,
|
||||
bdM, bdT, bdR, bdRs, dM, dT, dR, dRs,
|
||||
args = process.argv.splice(2),
|
||||
bigdecimal = require('./lib/bigdecimal_GWT/bigdecimal'),
|
||||
BigDecimal = bigdecimal.BigDecimal,
|
||||
MathContext = bigdecimal.MathContext,
|
||||
Decimal = require('../../decimal'),
|
||||
bdMs = ['add', 'subtract', 'multiply', 'divide', 'remainder', 'compareTo', 'pow', 'negate', 'abs'],
|
||||
dMs1 = ['plus', 'minus', 'times', 'dividedBy', 'modulo', 'comparedTo', 'toPower', 'negated', 'abs'],
|
||||
dMs2 = ['', '', '', 'div', 'mod', 'cmp', '', 'neg', ''],
|
||||
Ms = [bdMs, dMs1, dMs2],
|
||||
allMs = [].concat.apply([], Ms),
|
||||
bdTotal = 0,
|
||||
dTotal = 0,
|
||||
BD = {},
|
||||
BN = {},
|
||||
modes = ['UP', 'DOWN', 'CEILING', 'FLOOR', 'HALF_UP', 'HALF_DOWN', 'HALF_EVEN'],
|
||||
|
||||
ALWAYS_SHOW_MEMORY = false,
|
||||
DEFAULT_MAX_DIGITS = 20,
|
||||
DEFAULT_POW_MAX_DIGITS = 20,
|
||||
DEFAULT_REPS = 1e4,
|
||||
DEFAULT_POW_REPS = 1e2,
|
||||
DEFAULT_PRECISION = 20,
|
||||
MAX_POWER = 50,
|
||||
MAX_RANDOM_EXPONENT = 100,
|
||||
|
||||
getRandom = function (maxDigits) {
|
||||
var z,
|
||||
i = 0,
|
||||
// number of digits - 1
|
||||
n = Math.random() * ( maxDigits || 1 ) | 0,
|
||||
// No numbers between 0 and 1 or BigDecimal remainder operation may fail with 'Division impossible' error.
|
||||
r = ( ( bdM == 'remainder' ? Math.random() * 9 + 1 : Math.random() * 10 ) | 0 ) + '';
|
||||
//r = ( Math.random() * 10 | 0 ) + '';
|
||||
|
||||
if (n) {
|
||||
|
||||
if ( z = r === '0' ) {
|
||||
r += '.';
|
||||
}
|
||||
|
||||
for ( ; i++ < n; r += Math.random() * 10 | 0 ) {
|
||||
}
|
||||
|
||||
// 20% chance of integer
|
||||
if ( !z && Math.random() > 0.2 ) {
|
||||
r = r.slice( 0, i = ( Math.random() * n | 0 ) + 1 ) + '.' + r.slice(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid 'division by zero' error with division and modulo.
|
||||
if ((bdM == 'divide' || bdM == 'remainder') && parseFloat(r) === 0) {
|
||||
r = ( ( Math.random() * 9 | 0 ) + 1 ) + '';
|
||||
}
|
||||
|
||||
// 50% chance of negative
|
||||
return Math.random() > 0.5 ? r : '-' + r;
|
||||
},
|
||||
|
||||
/*
|
||||
// Returns exponential notation.
|
||||
getRandom = function (maxDigits) {
|
||||
var i = 0,
|
||||
// n is the number of significant digits - 1
|
||||
n = Math.random() * (maxDigits || 1) | 0,
|
||||
r = ( ( Math.random() * 9 | 0 ) + 1 ) + ( n ? '.' : '' );
|
||||
|
||||
for (; i++ < n; r += Math.random() * 10 | 0 ) {}
|
||||
|
||||
// Add exponent.
|
||||
r += 'e' + ( Math.random() > 0.5 ? '+' : '-' ) +
|
||||
( Math.random() * MAX_RANDOM_EXPONENT | 0 );
|
||||
|
||||
// 50% chance of being negative.
|
||||
return Math.random() > 0.5 ? r : '-' + r
|
||||
},
|
||||
*/
|
||||
|
||||
getFastest = function (d, bd) {
|
||||
var r;
|
||||
|
||||
if (Math.abs(d - bd) > 2) {
|
||||
r = ((d < bd)
|
||||
? 'Decimal was ' + (d ? parseFloat((bd / d).toFixed(1)) : bd)
|
||||
: 'BigDecimal was ' + (bd ? parseFloat((d / bd).toFixed(1)) : d)) + ' times faster';
|
||||
} else {
|
||||
timesEqual = 1;
|
||||
r = 'Times approximately equal';
|
||||
}
|
||||
|
||||
return r;
|
||||
},
|
||||
|
||||
getMemory = function (obj) {
|
||||
|
||||
if (showMemory) {
|
||||
var mem = process.memoryUsage(),
|
||||
rss = mem.rss,
|
||||
heapUsed = mem.heapUsed,
|
||||
heapTotal = mem.heapTotal;
|
||||
|
||||
if (obj) {
|
||||
obj.rss += (rss - prevRss);
|
||||
obj.hU += (heapUsed - prevHeapUsed);
|
||||
obj.hT += (heapTotal - prevHeapTotal);
|
||||
}
|
||||
prevRss = rss;
|
||||
prevHeapUsed = heapUsed;
|
||||
prevHeapTotal = heapTotal;
|
||||
}
|
||||
},
|
||||
|
||||
toKB = function (m) { return parseFloat((m / 1024).toFixed(1)) },
|
||||
|
||||
getMemoryTotals = function (obj) {
|
||||
|
||||
return '\trss: ' + toKB(obj.rss) + '\thU: ' + toKB(obj.hU) + '\thT: ' + toKB(obj.hT);
|
||||
};
|
||||
|
||||
arg = args[0];
|
||||
|
||||
if ( typeof arg != 'undefined' && !isFinite(arg) &&
|
||||
allMs.indexOf(arg) == -1 && !/^-*m$/i.test(arg)) {
|
||||
console.log(
|
||||
'\n node bigtime [METHOD] [METHOD CALLS [MAX DIGITS [precision]]]\n' +
|
||||
'\n METHOD: The method to be timed and compared with the' +
|
||||
'\n \t corresponding method from BigDecimal or Decimal\n' +
|
||||
'\n BigDecimal: add subtract multiply divide remainder compareTo pow' +
|
||||
'\n\t\tnegate abs\n\n Decimal: plus minus times dividedBy modulo comparedTo toPower' +
|
||||
'\n\t\tnegated abs (div mod cmp pow neg)' +
|
||||
'\n\n METHOD CALLS: The number of method calls to be timed' +
|
||||
'\n\n MAX DIGITS: The maximum number of digits of the random ' +
|
||||
'\n\t\tnumbers used in the method calls\n\n ' +
|
||||
'precision: The maximum number of significant digits of a result' +
|
||||
'\n\t\t(The rounding mode is randomly chosen)' +
|
||||
'\n\n Default values: METHOD: randomly chosen' +
|
||||
'\n\t\t METHOD CALLS: ' + DEFAULT_REPS + ' (pow: ' + DEFAULT_POW_REPS + ')' +
|
||||
'\n\t\t MAX DIGITS: ' + DEFAULT_MAX_DIGITS + ' (pow: ' + DEFAULT_POW_MAX_DIGITS + ')' +
|
||||
'\n\t\t precision: ' + DEFAULT_PRECISION + '\n' +
|
||||
'\n E.g. node bigtime\n\tnode bigtime minus\n\tnode bigtime add 100000' +
|
||||
'\n\tnode bigtime times 20000 100\n\tnode bigtime div 100000 50 20' +
|
||||
'\n\tnode bigtime 9000\n\tnode bigtime 1000000 20\n' +
|
||||
'\n To show memory usage, include an argument m or -m' +
|
||||
'\n E.g. node bigtime m add'
|
||||
);
|
||||
} else {
|
||||
|
||||
|
||||
// INITALISE
|
||||
|
||||
|
||||
Decimal.config({
|
||||
toExpNeg: -9e15,
|
||||
toExpPos: 9e15,
|
||||
minE: -9e15,
|
||||
maxE: 9e15
|
||||
});
|
||||
|
||||
Number.prototype.toPlainString = Number.prototype.toString;
|
||||
|
||||
for (i = 0; i < args.length; i++) {
|
||||
arg = args[i];
|
||||
|
||||
if (isFinite(arg)) {
|
||||
arg = Math.abs(parseInt(arg));
|
||||
|
||||
if (reps == null) reps = arg <= 1e10 ? arg : 0;
|
||||
else if (max == null) max = arg <= 1e6 ? arg : 0;
|
||||
else if (precision == null) precision = arg <= 1e6 ? arg : DEFAULT_PRECISION;
|
||||
} else if (/^-*m$/i.test(arg)) {
|
||||
showMemory = true;
|
||||
} else if (method == null) {
|
||||
method = arg;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < Ms.length && (methodIndex = Ms[i].indexOf(method)) == -1; i++) {}
|
||||
|
||||
dM = methodIndex == -1
|
||||
? dMs1[methodIndex = Math.floor(Math.random() * bdMs.length)]
|
||||
: (Ms[i][0] == 'add' ? dMs1 : Ms[i])[methodIndex];
|
||||
|
||||
bdM = bdMs[methodIndex];
|
||||
|
||||
if (!reps) reps = bdM == 'pow' ? DEFAULT_POW_REPS : DEFAULT_REPS;
|
||||
|
||||
if (!max) max = bdM == 'pow' ? DEFAULT_POW_MAX_DIGITS : DEFAULT_MAX_DIGITS;
|
||||
|
||||
if (precision == null) precision = DEFAULT_PRECISION;
|
||||
|
||||
/*
|
||||
BigDecimal remainder needs precision to be >= number of digits of operands:
|
||||
"Division impossible: This occurs and signals invalid-operation if the integer result of a
|
||||
divide-integer or remainder operation had too many digits (would be longer than precision)."
|
||||
*/
|
||||
if ( bdM == 'remainder' && max > precision ) {
|
||||
max = precision;
|
||||
}
|
||||
|
||||
// Get random rounding mode.
|
||||
rounding = Math.floor(Math.random() * 7);
|
||||
|
||||
xs = [reps], ys = [reps], bdRs = [reps], dRs = [reps];
|
||||
BD.rss = BD.hU = BD.hT = BN.rss = BN.hU = BN.hT = 0;
|
||||
showMemory = showMemory || ALWAYS_SHOW_MEMORY;
|
||||
|
||||
console.log('\n Decimal %s vs BigDecimal %s\n' +
|
||||
'\n Method calls: %d\n\n Random operands: %d', dM, bdM, reps,
|
||||
bdM == 'abs' || bdM == 'negate' || bdM == 'abs' ? reps : reps * 2);
|
||||
|
||||
console.log(' Max. digits of operands: %d', max);
|
||||
|
||||
console.log('\n Precision: %d\n Rounding mode: %d', precision, rounding);
|
||||
|
||||
process.stdout.write('\n Testing started');
|
||||
|
||||
|
||||
// TEST
|
||||
|
||||
|
||||
outer:
|
||||
for (; reps > 0; reps -= 1e4) {
|
||||
|
||||
j = Math.min(reps, 1e4);
|
||||
|
||||
|
||||
// GENERATE RANDOM OPERANDS
|
||||
|
||||
|
||||
for (i = 0; i < j; i++) {
|
||||
xs[i] = getRandom(max);
|
||||
}
|
||||
|
||||
if (bdM == 'pow') {
|
||||
for (i = 0; i < j; i++) {
|
||||
ys[i] = Math.floor(Math.random() * (MAX_POWER + 1));
|
||||
}
|
||||
} else if (bdM != 'abs' && bdM != 'negate') {
|
||||
for (i = 0; i < j; i++) {
|
||||
ys[i] = getRandom(max);
|
||||
}
|
||||
}
|
||||
|
||||
getMemory();
|
||||
|
||||
|
||||
// BIGDECIMAL
|
||||
|
||||
|
||||
/*
|
||||
// Rounding modes 0 UP, 1 DOWN, 2 CEILING, 3 FLOOR, 4 HALF_UP, 5 HALF_DOWN, 6 HALF_EVEN
|
||||
|
||||
new BigDecimal('100').divide( new BigDecimal('3') ); // Exception, needs a rounding mode.
|
||||
new BigDecimal('100').divide( new BigDecimal('3'), 0 ).toString(); // 34
|
||||
|
||||
var x = new BigDecimal('5');
|
||||
var y = new BigDecimal('3');
|
||||
|
||||
// MathContext objects need to be initialised with a string!?
|
||||
var mc = new MathContext('precision=5 roundingMode=HALF_UP');
|
||||
console.log( x.divide( y, mc ).toString() ); // '1.6667'
|
||||
|
||||
// UNLIMITED precision=0 roundingMode=HALF_UP
|
||||
// DECIMAL32 precision=7 roundingMode=HALF_EVEN
|
||||
// DECIMAL64 precision=16 roundingMode=HALF_EVEN
|
||||
// DECIMAL128 precision=34 roundingMode=HALF_EVEN
|
||||
// Note that these are functions!
|
||||
console.log( x.divide( y, MathContext.DECIMAL64() ).toString() ); // '1.666666666666667'
|
||||
|
||||
// Set scale (i.e. decimal places) and rounding mode.
|
||||
console.log( x.divide( y, 2, 4 ).toString() ); // '1.67'
|
||||
|
||||
// DOWN is a function, ROUND_DOWN is not!
|
||||
console.log( x.divide( y, 6, RoundingMode.DOWN() ).toString() ); // '1.666666'
|
||||
console.log( x.divide( y, 6, BigDecimal.ROUND_DOWN ).toString() ); // '1.666666'
|
||||
*/
|
||||
|
||||
|
||||
mc = new MathContext('precision=' + precision + ' roundingMode=' + modes[rounding] );
|
||||
|
||||
if (bdM == 'pow') {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < j; i++) {
|
||||
bdRs[i] = new BigDecimal(xs[i])[bdM](ys[i], mc);
|
||||
}
|
||||
bdT = +new Date() - start;
|
||||
|
||||
} else if (bdM == 'abs' || bdM == 'negate') {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < j; i++) {
|
||||
bdRs[i] = new BigDecimal(xs[i])[bdM]();
|
||||
}
|
||||
bdT = +new Date() - start;
|
||||
|
||||
} else {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < j; i++) {
|
||||
bdRs[i] = new BigDecimal(xs[i])[bdM](new BigDecimal(ys[i]), mc);
|
||||
}
|
||||
bdT = +new Date() - start;
|
||||
|
||||
}
|
||||
|
||||
getMemory(BD);
|
||||
|
||||
|
||||
/*
|
||||
// Debug: insert the following into the for-loop above.
|
||||
try {
|
||||
bdRs[i] = new BigDecimal(xs[i])[bdM](new BigDecimal(ys[i]), mc);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
console.log('\n Error. Operation number ' + i);
|
||||
console.log('\n x: %s\n y: %s', xs[i], ys[i]);
|
||||
console.log('\n precision: %d\n rounding: %d', precision, rounding);
|
||||
bdRs[i] = { toPlainString: function () { return 'failed' } };
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// BIGNUMBER
|
||||
|
||||
|
||||
Decimal.config({ precision: precision, rounding: rounding });
|
||||
|
||||
if (bdM == 'abs' || bdM == 'negate') {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < j; i++) {
|
||||
dRs[i] = new Decimal(xs[i])[dM]();
|
||||
}
|
||||
dT = +new Date() - start;
|
||||
|
||||
} else {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < j; i++) {
|
||||
dRs[i] = new Decimal(xs[i])[dM](ys[i]);
|
||||
}
|
||||
dT = +new Date() - start;
|
||||
|
||||
}
|
||||
|
||||
getMemory(BN);
|
||||
|
||||
|
||||
// CHECK FOR MISMATCHES
|
||||
|
||||
|
||||
for (i = 0; i < j; i++) {
|
||||
dR = dRs[i].toString();
|
||||
bdR = bdRs[i].toPlainString();
|
||||
|
||||
// Strip any trailing zeros from non-integer BigDecimals
|
||||
if (bdR.indexOf('.') != -1) {
|
||||
bdR = bdR.replace(/\.?0+$/, '');
|
||||
}
|
||||
|
||||
if (bdR !== dR) {
|
||||
console.log(
|
||||
'\n breaking on first mismatch (result number %d):' +
|
||||
'\n\n BigDecimal: %s\n Decimal: %s', i, bdR, dR
|
||||
);
|
||||
|
||||
console.log('\n x: %s\n y: %s', xs[i], ys[i]);
|
||||
console.log('\n precision: %d\n rounding: %d', precision, rounding);
|
||||
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
|
||||
bdTotal += bdT;
|
||||
dTotal += dT;
|
||||
|
||||
process.stdout.write(' .');
|
||||
}
|
||||
|
||||
|
||||
// TIMINGS SUMMARY
|
||||
|
||||
|
||||
if (i == j) {
|
||||
console.log(' done\n\n No mismatches.');
|
||||
|
||||
if (showMemory) {
|
||||
console.log(
|
||||
'\n Change in memory usage (KB):' +
|
||||
'\n\tBigDecimal' + getMemoryTotals(BD) +
|
||||
'\n\tDecimal ' + getMemoryTotals(BN)
|
||||
);
|
||||
}
|
||||
|
||||
console.log(
|
||||
'\n Time taken:' + '\n\tBigDecimal ' + (bdTotal || '<1') + ' ms' +
|
||||
'\n\tDecimal ' + ( dTotal || '<1') + ' ms\n\n ' +
|
||||
getFastest(dTotal, bdTotal) + '\n'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
BigDecimal notes:
|
||||
Java standard class library: java.math.BigDecimal
|
||||
|
||||
Exports:
|
||||
RoundingMode
|
||||
MathContext
|
||||
BigDecimal
|
||||
BigInteger
|
||||
|
||||
BigDecimal properties:
|
||||
ROUND_CEILING
|
||||
ROUND_DOWN
|
||||
ROUND_FLOOR
|
||||
ROUND_HALF_DOWN
|
||||
ROUND_HALF_EVEN
|
||||
ROUND_HALF_UP
|
||||
ROUND_UNNECESSARY
|
||||
ROUND_UP
|
||||
__init__
|
||||
valueOf
|
||||
log
|
||||
logObj
|
||||
ONE
|
||||
TEN
|
||||
ZERO
|
||||
|
||||
BigDecimal instance properties/methods:
|
||||
( for (var i in new BigDecimal('1').__gwt_instance.__gwtex_wrap) {...} )
|
||||
|
||||
byteValueExact
|
||||
compareTo
|
||||
doubleValue
|
||||
equals
|
||||
floatValue
|
||||
hashCode
|
||||
intValue
|
||||
intValueExact
|
||||
max
|
||||
min
|
||||
movePointLeft
|
||||
movePointRight
|
||||
precision
|
||||
round
|
||||
scale
|
||||
scaleByPowerOfTen
|
||||
shortValueExact
|
||||
signum
|
||||
stripTrailingZeros
|
||||
toBigInteger
|
||||
toBigIntegerExact
|
||||
toEngineeringString
|
||||
toPlainString
|
||||
toString
|
||||
ulp
|
||||
unscaledValue
|
||||
longValue
|
||||
longValueExact
|
||||
abs
|
||||
add
|
||||
divide
|
||||
divideToIntegralValue
|
||||
multiply
|
||||
negate
|
||||
plus
|
||||
pow
|
||||
remainder
|
||||
setScale
|
||||
subtract
|
||||
divideAndRemainder
|
||||
*/
|
||||
771
test/perf/decimal-vs-bigdecimal.html
Normal file
771
test/perf/decimal-vs-bigdecimal.html
Normal file
@@ -0,0 +1,771 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8' />
|
||||
<meta name="Author" content="M Mclaughlin">
|
||||
<title>Testing Decimal against BigDecimal</title>
|
||||
<style>
|
||||
body {margin: 0; padding: 0; font-family: Calibri, Arial, Sans-Serif;}
|
||||
div {margin: 1em 0;}
|
||||
h1, #counter {text-align: center; background-color: rgb(225, 225, 225);
|
||||
margin-top: 1em; padding: 0.2em; font-size: 1.2em;}
|
||||
a {color: rgb(0, 153, 255); margin: 0 0.6em;}
|
||||
.links {position: fixed; bottom: 1em; right: 2em; font-size: 0.8em;}
|
||||
.form, #time {width: 36em; margin: 0 auto;}
|
||||
.form {text-align: left; margin-top: 1.4em;}
|
||||
.random input {margin-left: 1em;}
|
||||
.small {font-size: 0.9em;}
|
||||
.methods {margin: 1em auto; width: 18em;}
|
||||
.iterations input, .left {margin-left: 1.6em;}
|
||||
.info span {margin-left: 1.6em; font-size: 0.9em;}
|
||||
.info {margin-top: 1.6em;}
|
||||
.random input, .iterations input {margin-right: 0.3em;}
|
||||
.random label, .iterations label, .bigd label {font-size: 0.9em;
|
||||
margin-left: 0.1em;}
|
||||
.methods label {width: 5em; margin-left: 0.2em; display: inline-block;}
|
||||
.methods label.right {width: 2em;}
|
||||
.red {color: red; font-size: 1.1em; font-weight: bold;}
|
||||
button {width: 10em; height: 2em;}
|
||||
#sd, #r, #digits, #reps {margin-left: 0.8em;}
|
||||
#bigint {font-style: italic; display: none;}
|
||||
#gwt, #icu4j, #bd, #bigint {margin-left: 1.5em;}
|
||||
#counter {font-size: 2em; background-color: rgb(235, 235, 235);}
|
||||
#time {text-align: center;}
|
||||
#results {margin: 0 1.4em;}
|
||||
</style>
|
||||
<script src='../../decimal.js'></script>
|
||||
<script src='./lib/bigdecimal_GWT/bigdecimal.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Testing Decimal against BigDecimal</h1>
|
||||
|
||||
<div class='form'>
|
||||
|
||||
<div class='methods'>
|
||||
<input type='radio' id=0 name=1/><label for=0>plus</label>
|
||||
<input type='radio' id=3 name=1/><label for=3>div</label>
|
||||
<input type='radio' id=6 name=1/><label for=6 class='right'>abs</label>
|
||||
<br>
|
||||
<input type='radio' id=1 name=1/><label for=1>minus</label>
|
||||
<input type='radio' id=4 name=1/><label for=4>mod</label>
|
||||
<input type='radio' id=7 name=1/><label for=7 class='right'>neg</label>
|
||||
<br>
|
||||
<input type='radio' id=2 name=1/><label for=2>times</label>
|
||||
<input type='radio' id=5 name=1/><label for=5>cmp</label>
|
||||
<input type='radio' id=8 name=1/><label for=8 class='right'>pow</label>
|
||||
</div>
|
||||
|
||||
<div class='bigd'>
|
||||
<span>BigDecimal:</span>
|
||||
<input type='radio' name=2 id='gwt' /><label for='gwt'>GWT</label>
|
||||
<input type='radio' name=2 id='icu4j' /><label for='icu4j'>ICU4J</label>
|
||||
<span id='bigint'>BigInteger</span>
|
||||
<span id='bd'>add</span>
|
||||
</div>
|
||||
|
||||
<div class='random'>
|
||||
Random number digits:<input type='text' id='digits' size=12 />
|
||||
<input type='radio' name=3 id='fix' /><label for='fix'>Fixed</label>
|
||||
<input type='radio' name=3 id='max' /><label for='max'>Max</label>
|
||||
<input type='checkbox' id='int' /><label for='int'>Integers only</label>
|
||||
</div>
|
||||
|
||||
<div id='context'>
|
||||
<span>Precision:<input type='text' id='sd' size=9 /></span>
|
||||
<span class='left'>Rounding:<select id='r'>
|
||||
<option>UP</option>
|
||||
<option>DOWN</option>
|
||||
<option>CEIL</option>
|
||||
<option>FLOOR</option>
|
||||
<option>HALF_UP</option>
|
||||
<option>HALF_DOWN</option>
|
||||
<option>HALF_EVEN</option>
|
||||
</select></span>
|
||||
</div>
|
||||
|
||||
<div class='iterations'>
|
||||
Iterations:<input type='text' id='reps' size=11 />
|
||||
<input type='checkbox' id='show'/><label for='show'>Show all (no timing)</label>
|
||||
</div>
|
||||
|
||||
<div class='info'>
|
||||
<button id='start'>Start</button>
|
||||
<span>Click a method to stop</span>
|
||||
<span>Press space bar to pause/unpause</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id='counter'>0</div>
|
||||
<div id='time'></div>
|
||||
<div id='results'></div>
|
||||
|
||||
<div class='links'>
|
||||
<a href='https://github.com/MikeMcl/bignumber.js' target='_blank'>Decimal</a>
|
||||
<a href='https://github.com/iriscouch/bigdecimal.js' target='_blank'>GWT</a>
|
||||
<a href='https://github.com/dtrebbien/BigDecimal.js/tree/' target='_blank'>ICU4J</a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
var i, completedReps, targetReps, cycleReps, cycleTime, prevCycleReps, cycleLimit,
|
||||
isFixed, isIntOnly, maxDigits, mc, precision, rounding, calcTimeout,
|
||||
counterTimeout, script, isGWT, BigDecimal_GWT, BigDecimal_ICU4J,
|
||||
bdM, bdTotal, dM, dTotal,
|
||||
bdMs = ['add', 'subtract', 'multiply', 'divide', 'remainder', 'compareTo', 'abs', 'negate', 'pow'],
|
||||
dMs = ['plus', 'minus', 'times', 'div', 'mod', 'cmp', 'abs', 'neg', 'pow'],
|
||||
modes = ['UP', 'DOWN', 'CEILING', 'FLOOR', 'HALF_UP', 'HALF_DOWN', 'HALF_EVEN'],
|
||||
lastRounding = 4,
|
||||
pause = false,
|
||||
up = true,
|
||||
timingVisible = false,
|
||||
showAll = false,
|
||||
|
||||
// EDIT DEFAULTS HERE
|
||||
|
||||
DEFAULT_REPS = 10000,
|
||||
DEFAULT_DIGITS = 20,
|
||||
DEFAULT_PRECISION = 20,
|
||||
DEFAULT_rounding = 4,
|
||||
MAX_POWER = 20,
|
||||
CHANCE_NEGATIVE = 0.5, // 0 (never) to 1 (always)
|
||||
CHANCE_INTEGER = 0.2, // 0 (never) to 1 (always)
|
||||
MAX_RANDOM_EXPONENT = 100,
|
||||
SPACE_BAR = 32,
|
||||
ICU4J_URL = './lib/bigdecimal_ICU4J/BigDecimal-all-last.js',
|
||||
|
||||
//
|
||||
|
||||
$ = function (id) { return document.getElementById(id) },
|
||||
$INPUTS = document.getElementsByTagName('input'),
|
||||
$BD = $('bd'),
|
||||
$BIGINT = $('bigint'),
|
||||
$DIGITS = $('digits'),
|
||||
$GWT = $('gwt'),
|
||||
$ICU4J = $('icu4j'),
|
||||
$FIX = $('fix'),
|
||||
$MAX = $('max'),
|
||||
$INT = $('int'),
|
||||
$SD = $('sd'),
|
||||
$R = $('r'),
|
||||
$REPS = $('reps'),
|
||||
$SHOW = $('show'),
|
||||
$START = $('start'),
|
||||
$COUNTER = $('counter'),
|
||||
$TIME = $('time'),
|
||||
$RESULTS = $('results'),
|
||||
|
||||
// Get random number in normal notation.
|
||||
getRandom = function () {
|
||||
var z,
|
||||
i = 0,
|
||||
// n is the number of digits - 1
|
||||
n = isFixed ? maxDigits - 1 : Math.random() * (maxDigits || 1) | 0,
|
||||
// No numbers between 0 and 1 or BigDecimal remainder operation may fail with 'Division impossible' error.
|
||||
r = ( ( bdM == 'remainder' ? Math.random() * 9 + 1 : Math.random() * 10 ) | 0 ) + '';
|
||||
//r = ( Math.random() * 10 | 0 ) + '';
|
||||
|
||||
if (n) {
|
||||
|
||||
if (r == '0') {
|
||||
r = isIntOnly ? ( ( Math.random() * 9 | 0 ) + 1 ) + '' : (z = r + '.');
|
||||
}
|
||||
|
||||
for ( ; i++ < n; r += Math.random() * 10 | 0 ){}
|
||||
|
||||
if (!z && !isIntOnly && Math.random() > CHANCE_INTEGER) {
|
||||
r = r.slice( 0, i = (Math.random() * n | 0) + 1 ) + '.' + r.slice(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid division by zero error with division and modulo
|
||||
if ((bdM == 'divide' || bdM == 'remainder') && parseFloat(r) === 0) {
|
||||
r = ( ( Math.random() * 9 | 0 ) + 1 ) + '';
|
||||
}
|
||||
|
||||
return Math.random() > CHANCE_NEGATIVE ? r : '-' + r;
|
||||
},
|
||||
|
||||
/*
|
||||
// Get random number in exponential notation (if isIntOnly is false).
|
||||
// GWT BigDecimal BigInteger does not accept exponential notation.
|
||||
getRandom = function () {
|
||||
var i = 0,
|
||||
// n is the number of significant digits - 1
|
||||
n = isFixed ? maxDigits - 1 : Math.random() * (maxDigits || 1) | 0,
|
||||
r = ( ( Math.random() * 9 | 0 ) + 1 ) + '';
|
||||
|
||||
for (; i++ < n; r += Math.random() * 10 | 0 ) {}
|
||||
|
||||
if ( !isIntOnly ) {
|
||||
|
||||
// Add exponent.
|
||||
r += 'e' + ( Math.random() > 0.5 ? '+' : '-' ) +
|
||||
( Math.random() * MAX_RANDOM_EXPONENT | 0 );
|
||||
}
|
||||
|
||||
return Math.random() > CHANCE_NEGATIVE ? r : '-' + r
|
||||
},
|
||||
*/
|
||||
|
||||
showTimings = function () {
|
||||
var i, bdS, dS,
|
||||
sp = '',
|
||||
r = dTotal < bdTotal
|
||||
? (dTotal ? bdTotal / dTotal : bdTotal)
|
||||
: (bdTotal ? dTotal / bdTotal : dTotal);
|
||||
|
||||
bdS = 'BigDecimal: ' + (bdTotal || '<1');
|
||||
dS = 'Decimal: ' + ( dTotal || '<1');
|
||||
|
||||
for ( i = bdS.length - dS.length; i-- > 0; sp += ' ') {}
|
||||
dS = 'Decimal: ' + sp + (dTotal || '<1');
|
||||
|
||||
$TIME.innerHTML = 'No mismatches<div>' + bdS + ' ms<br>' + dS + ' ms</div>' + (
|
||||
(r = parseFloat(r.toFixed(1))) > 1
|
||||
? (dTotal < bdTotal ? 'Decimal' : 'BigDecimal') + ' was ' + r + ' times faster'
|
||||
: 'Times approximately equal'
|
||||
);
|
||||
},
|
||||
|
||||
clear = function () {
|
||||
clearTimeout(calcTimeout);
|
||||
clearTimeout(counterTimeout);
|
||||
|
||||
$COUNTER.style.textDecoration = 'none';
|
||||
$COUNTER.innerHTML = '0';
|
||||
$TIME.innerHTML = $RESULTS.innerHTML = '';
|
||||
$START.innerHTML = 'Start';
|
||||
},
|
||||
|
||||
begin = function () {
|
||||
var i;
|
||||
clear();
|
||||
targetReps = +$REPS.value;
|
||||
|
||||
if (!(targetReps > 0)) return;
|
||||
|
||||
$START.innerHTML = 'Restart';
|
||||
i = +$DIGITS.value;
|
||||
$DIGITS.value = maxDigits = i && isFinite(i) ? i : DEFAULT_DIGITS;
|
||||
|
||||
for (i = 0; i < 9; i++) {
|
||||
|
||||
if ($INPUTS[i].checked) {
|
||||
dM = dMs[$INPUTS[i].id];
|
||||
bdM = bdMs[$INPUTS[i].id];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
isFixed = $FIX.checked;
|
||||
isIntOnly = $INT.checked;
|
||||
showAll = $SHOW.checked;
|
||||
isGWT = $GWT.checked;
|
||||
|
||||
precision = isFinite(i = +$SD.value) ? i : DEFAULT_PRECISION;
|
||||
|
||||
/*
|
||||
// BigDecimal_ICU4J rounds operands to precision before performing the calculation.
|
||||
if (precision < maxDigits && !isGWT) {
|
||||
precision = maxDigits + 1;
|
||||
}
|
||||
*/
|
||||
$SD.value = precision
|
||||
|
||||
rounding = $R.selectedIndex;
|
||||
|
||||
// Set precision and rounding
|
||||
Decimal.config({ precision: precision, rounding: rounding });
|
||||
|
||||
if (isGWT) {
|
||||
BigDecimal = isIntOnly ? BigInteger : BigDecimal_GWT;
|
||||
mc = new MathContext_GWT('precision=' + precision + ' roundingMode=' + modes[rounding]);
|
||||
} else {
|
||||
BigDecimal = BigDecimal_ICU4J;
|
||||
mc = new MathContext_ICU4J(precision, MathContext_ICU4J.PLAIN, false, rounding);
|
||||
}
|
||||
|
||||
prevCycleReps = cycleLimit = completedReps = bdTotal = dTotal = 0;
|
||||
pause = false;
|
||||
|
||||
cycleReps = showAll ? 1 : 0.5;
|
||||
cycleTime = +new Date();
|
||||
|
||||
setTimeout(updateCounter, 0);
|
||||
},
|
||||
|
||||
updateCounter = function () {
|
||||
|
||||
if (pause) {
|
||||
|
||||
if (!timingVisible && !showAll) {
|
||||
showTimings();
|
||||
timingVisible = true;
|
||||
}
|
||||
counterTimeout = setTimeout(updateCounter, 50);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$COUNTER.innerHTML = completedReps;
|
||||
|
||||
if (completedReps < targetReps) {
|
||||
|
||||
if (timingVisible) {
|
||||
$TIME.innerHTML = '';
|
||||
timingVisible = false;
|
||||
}
|
||||
|
||||
if (!showAll) {
|
||||
|
||||
// Adjust cycleReps so counter is updated every second-ish
|
||||
if (prevCycleReps != cycleReps) {
|
||||
|
||||
// cycleReps too low
|
||||
if (+new Date() - cycleTime < 1e3) {
|
||||
prevCycleReps = cycleReps;
|
||||
|
||||
if (cycleLimit) {
|
||||
cycleReps += ((cycleLimit - cycleReps) / 2);
|
||||
} else {
|
||||
cycleReps *= 2;
|
||||
}
|
||||
|
||||
// cycleReps too high
|
||||
} else {
|
||||
cycleLimit = cycleReps;
|
||||
cycleReps -= ((cycleReps - prevCycleReps) / 2);
|
||||
}
|
||||
|
||||
cycleReps = Math.floor(cycleReps) || 1;
|
||||
cycleTime = +new Date();
|
||||
}
|
||||
|
||||
if (completedReps + cycleReps > targetReps) {
|
||||
cycleReps = targetReps - completedReps;
|
||||
}
|
||||
}
|
||||
|
||||
completedReps += cycleReps;
|
||||
calcTimeout = setTimeout(calc, 0);
|
||||
|
||||
// Finished - show timings summary
|
||||
} else {
|
||||
$START.innerHTML = 'Start';
|
||||
$COUNTER.style.textDecoration = 'underline';
|
||||
|
||||
if (!showAll) {
|
||||
showTimings();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
calc = function () {
|
||||
var start, bdT, dT, bdR, dR,
|
||||
xs = [cycleReps],
|
||||
ys = [cycleReps],
|
||||
bdRs = [cycleReps],
|
||||
dRs = [cycleReps];
|
||||
|
||||
|
||||
// GENERATE RANDOM OPERANDS
|
||||
|
||||
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
xs[i] = getRandom();
|
||||
}
|
||||
|
||||
if (bdM == 'pow') {
|
||||
|
||||
// GWT pow argument must be Number type and integer
|
||||
if (isGWT) {
|
||||
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
ys[i] = Math.floor(Math.random() * (MAX_POWER + 1));
|
||||
}
|
||||
|
||||
// ICU4J pow argument must be BigDecimal
|
||||
} else {
|
||||
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
ys[i] = Math.floor(Math.random() * (MAX_POWER + 1)) + '';
|
||||
}
|
||||
}
|
||||
|
||||
// No second operand needed for abs and negate
|
||||
} else if (bdM != 'abs' && bdM != 'negate') {
|
||||
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
ys[i] = getRandom();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************//
|
||||
//************************** START TIMING ****************************//
|
||||
//********************************************************************//
|
||||
|
||||
|
||||
// BIGDECIMAL
|
||||
|
||||
|
||||
/*
|
||||
// BigDecimalICU4J
|
||||
|
||||
// Rounds operands to precision before performing a calculation.
|
||||
// Rounding to precision of add, subtract and pow seems unfathomable/unreliable, but it
|
||||
// matches the java version, see <http://speleotrove.com/decimal/dax3274.html>.
|
||||
// Pass a MathContext object to an arithmetic operation to set a precision/rounding mode.
|
||||
// Pass integers to set the scale (i.e. dp) and rounding mode for divide only.
|
||||
// (Passing one integer to divide sets the rounding mode.)
|
||||
|
||||
// Default scale (i.e. dp) if no MathContext object or integers are passed:
|
||||
// divide: lhs, add/subtract: max(lhs, rhs), multiply: lhs + rhs
|
||||
new BigDecimal('100').divide( new BigDecimal('3') ).toString() // 33
|
||||
new BigDecimal('100').divide( new BigDecimal('3'), new MathContext(5, MathContext.PLAIN, false, MathContext.ROUND_HALF_UP) ).toString() // 33.333
|
||||
new BigDecimal('100').divide( new BigDecimal('3'), 4, BigDecimal.ROUND_HALF_UP) ).toString() // 33.3333
|
||||
|
||||
|
||||
|
||||
// BigDecimalGWT
|
||||
|
||||
// Rounding modes 0 UP, 1 DOWN, 2 CEILING, 3 FLOOR, 4 HALF_UP, 5 HALF_DOWN, 6 HALF_EVEN
|
||||
|
||||
new BigDecimal('100').divide( new BigDecimal('3') ); // Exception, needs a rounding mode.
|
||||
new BigDecimal('100').divide( new BigDecimal('3'), 0 ).toString(); // 34
|
||||
|
||||
var x = new BigDecimal('5');
|
||||
var y = new BigDecimal('3');
|
||||
|
||||
// MathContext objects need to be initialised with a string!?
|
||||
var mc = new MathContext('precision=5 roundingMode=HALF_UP');
|
||||
console.log( x.divide( y, mc ).toString() ); // '1.6667'
|
||||
|
||||
// UNLIMITED precision=0 roundingMode=HALF_UP
|
||||
// DECIMAL32 precision=7 roundingMode=HALF_EVEN
|
||||
// DECIMAL64 precision=16 roundingMode=HALF_EVEN
|
||||
// DECIMAL128 precision=34 roundingMode=HALF_EVEN
|
||||
// Note that these are functions!
|
||||
console.log( x.divide( y, MathContext.DECIMAL64() ).toString() ); // '1.666666666666667'
|
||||
|
||||
// Set scale (i.e. decimal places) and rounding mode.
|
||||
console.log( x.divide( y, 2, 4 ).toString() ); // '1.67'
|
||||
|
||||
// DOWN is a function, ROUND_DOWN is not!
|
||||
console.log( x.divide( y, 6, RoundingMode.DOWN() ).toString() ); // '1.666666'
|
||||
console.log( x.divide( y, 6, BigDecimal.ROUND_DOWN ).toString() ); // '1.666666' ).toString()
|
||||
*/
|
||||
|
||||
|
||||
// GWT pow argument must be Number type and integer
|
||||
if (bdM == 'pow' && isGWT) {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
bdRs[i] = new BigDecimal(xs[i])[bdM](ys[i], mc);
|
||||
}
|
||||
bdT = +new Date() - start;
|
||||
|
||||
} else if (bdM == 'abs' || bdM == 'negate') {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
bdRs[i] = new BigDecimal(xs[i])[bdM]();
|
||||
}
|
||||
bdT = +new Date() - start;
|
||||
|
||||
} else {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
bdRs[i] = new BigDecimal(xs[i])[bdM](new BigDecimal(ys[i]), mc);
|
||||
}
|
||||
bdT = +new Date() - start;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// DECIMAL
|
||||
|
||||
|
||||
if (bdM == 'abs' || bdM == 'negate') {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
dRs[i] = new Decimal(xs[i])[dM]();
|
||||
}
|
||||
dT = +new Date() - start;
|
||||
|
||||
} else {
|
||||
|
||||
start = +new Date();
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
dRs[i] = new Decimal(xs[i])[dM](ys[i]);
|
||||
}
|
||||
dT = +new Date() - start;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************//
|
||||
//**************************** END TIMING ****************************//
|
||||
//********************************************************************//
|
||||
|
||||
|
||||
// CHECK FOR MISMATCHES
|
||||
|
||||
|
||||
for (i = 0; i < cycleReps; i++) {
|
||||
dR = dRs[i].toString();
|
||||
|
||||
// Remove any trailing zeros from BigDecimal result
|
||||
if (isGWT) {
|
||||
bdR = bdM == 'compareTo' || isIntOnly
|
||||
? bdRs[i].toString()
|
||||
: bdRs[i].stripTrailingZeros().toPlainString();
|
||||
} else {
|
||||
|
||||
// No toPlainString() or stripTrailingZeros() in ICU4J
|
||||
bdR = bdRs[i].toString();
|
||||
|
||||
if (bdR.indexOf('.') != -1) {
|
||||
bdR = bdR.replace(/\.?0+$/, '');
|
||||
}
|
||||
}
|
||||
|
||||
if (bdR !== dR) {
|
||||
|
||||
$RESULTS.innerHTML =
|
||||
'<span class="red">Breaking on first mismatch:</span>' +
|
||||
'<br><br>' +xs[i] + '<br>' + dM + '<br>' + ys[i] +
|
||||
'<br><br>BigDecimal<br>' + bdR + '<br>' + dR + '<br>Decimal';
|
||||
|
||||
if (bdM == 'divide') {
|
||||
$RESULTS.innerHTML += '<br><br>Decimal places: ' +
|
||||
precision + '<br>Rounding mode: ' + rounding;
|
||||
}
|
||||
|
||||
return;
|
||||
} else if (showAll) {
|
||||
$RESULTS.innerHTML = xs[i] + '<br>' + dM + '<br>' + ys[i] +
|
||||
'<br><br>BigDecimal<br>' + bdR + '<br>' + dR + '<br>Decimal';
|
||||
}
|
||||
}
|
||||
|
||||
bdTotal += bdT;
|
||||
dTotal += dT;
|
||||
|
||||
updateCounter();
|
||||
};
|
||||
|
||||
|
||||
// EVENT HANDLERS
|
||||
|
||||
|
||||
document.onkeyup = function (evt) {
|
||||
evt = evt || window.event;
|
||||
|
||||
if ((evt.keyCode || evt.which) == SPACE_BAR) {
|
||||
up = true;
|
||||
}
|
||||
};
|
||||
|
||||
document.onkeydown = function (evt) {
|
||||
evt = evt || window.event;
|
||||
|
||||
if (up && (evt.keyCode || evt.which) == SPACE_BAR) {
|
||||
pause = !pause;
|
||||
up = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Decimal methods' radio buttons' event handlers
|
||||
for (i = 0; i < 9; i++) {
|
||||
$INPUTS[i].checked = false;
|
||||
$INPUTS[i].disabled = false;
|
||||
|
||||
$INPUTS[i].onclick = function () {
|
||||
clear();
|
||||
lastRounding = $R.options.selectedIndex;
|
||||
dM = dMs[this.id];
|
||||
$BD.innerHTML = bdM = bdMs[this.id];
|
||||
};
|
||||
}
|
||||
|
||||
$INPUTS[1].onclick = function () {
|
||||
clear();
|
||||
$R.options.selectedIndex = lastRounding;
|
||||
dM = dMs[this.id];
|
||||
$BD.innerHTML = bdM = bdMs[this.id];
|
||||
};
|
||||
|
||||
// Show/hide BigInteger and disable/re-enable division accordingly as BigInteger
|
||||
// throws an exception if division gives "no exact representable decimal result"
|
||||
$INT.onclick = function () {
|
||||
|
||||
if (this.checked && $GWT.checked) {
|
||||
|
||||
if ($INPUTS[1].checked) {
|
||||
$INPUTS[1].checked = false;
|
||||
$INPUTS[0].checked = true;
|
||||
$BD.innerHTML = bdMs[$INPUTS[0].id];
|
||||
}
|
||||
$INPUTS[1].disabled = true;
|
||||
$BIGINT.style.display = 'inline';
|
||||
} else {
|
||||
$INPUTS[1].disabled = false;
|
||||
$BIGINT.style.display = 'none';
|
||||
}
|
||||
};
|
||||
|
||||
$ICU4J.onclick = function () {
|
||||
$INPUTS[1].disabled = false;
|
||||
$BIGINT.style.display = 'none';
|
||||
};
|
||||
|
||||
$GWT.onclick = function () {
|
||||
|
||||
if ($INT.checked) {
|
||||
|
||||
if ($INPUTS[1].checked) {
|
||||
$INPUTS[1].checked = false;
|
||||
$INPUTS[0].checked = true;
|
||||
$BD.innerHTML = bdMs[$INPUTS[0].id];
|
||||
}
|
||||
$INPUTS[1].disabled = true;
|
||||
$BIGINT.style.display = 'inline';
|
||||
}
|
||||
};
|
||||
|
||||
Decimal.config({
|
||||
precision: 20,
|
||||
rounding: 4,
|
||||
errors: false,
|
||||
minE: -9e15,
|
||||
maxE: 9e15,
|
||||
toExpNeg: -9e15,
|
||||
toExpPos: 9e15
|
||||
});
|
||||
|
||||
// Set defaults
|
||||
$MAX.checked = $INPUTS[0].checked = $GWT.checked = true;
|
||||
$SHOW.checked = $INT.checked = false;
|
||||
$REPS.value = DEFAULT_REPS;
|
||||
$DIGITS.value = DEFAULT_DIGITS;
|
||||
$SD.value = DEFAULT_PRECISION;
|
||||
$R.option = DEFAULT_rounding;
|
||||
|
||||
BigDecimal_GWT = BigDecimal;
|
||||
MathContext_GWT = MathContext;
|
||||
//if ( !MathContext ) throw 'No MathContext!';
|
||||
BigDecimal = MathContext = null;
|
||||
|
||||
// Load ICU4J BigDecimal
|
||||
script = document.createElement("script");
|
||||
script.src = ICU4J_URL;
|
||||
script.onload = script.onreadystatechange = function () {
|
||||
|
||||
if (!script.readyState || /loaded|complete/.test(script.readyState)) {
|
||||
script = null;
|
||||
BigDecimal_ICU4J = BigDecimal;
|
||||
MathContext_ICU4J = MathContext;
|
||||
BigDecimal = MathContext = null;
|
||||
$START.onmousedown = begin;
|
||||
}
|
||||
};
|
||||
document.getElementsByTagName("head")[0].appendChild(script);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
NOTES:
|
||||
|
||||
ICU4J
|
||||
=====
|
||||
IBM java package: com.ibm.icu.math.
|
||||
pow's argument must be a BigDecimal.
|
||||
This javascript version is used by the gwt_math project.
|
||||
Among other differences, doesn't have .toPlainString() or .stripTrailingZeros().
|
||||
Exports BigDecimal only.
|
||||
Much faster than gwt on Firefox, on Chrome it varies with the method.
|
||||
|
||||
GWT
|
||||
===
|
||||
Java standard class library: java.math.BigDecimal
|
||||
|
||||
Exports:
|
||||
RoundingMode
|
||||
MathContext
|
||||
BigDecimal
|
||||
BigInteger
|
||||
|
||||
BigDecimal properties:
|
||||
ROUND_CEILING
|
||||
ROUND_DOWN
|
||||
ROUND_FLOOR
|
||||
ROUND_HALF_DOWN
|
||||
ROUND_HALF_EVEN
|
||||
ROUND_HALF_UP
|
||||
ROUND_UNNECESSARY
|
||||
ROUND_UP
|
||||
__init__
|
||||
valueOf
|
||||
log
|
||||
logObj
|
||||
ONE
|
||||
TEN
|
||||
ZERO
|
||||
|
||||
BigDecimal instance properties/methods:
|
||||
( for (var i in new BigDecimal('1').__gwt_instance.__gwtex_wrap) {...} )
|
||||
|
||||
byteValueExact
|
||||
compareTo
|
||||
doubleValue
|
||||
equals
|
||||
floatValue
|
||||
hashCode
|
||||
intValue
|
||||
intValueExact
|
||||
max
|
||||
min
|
||||
movePointLeft
|
||||
movePointRight
|
||||
precision
|
||||
round
|
||||
scale
|
||||
scaleByPowerOfTen
|
||||
shortValueExact
|
||||
signum
|
||||
stripTrailingZeros
|
||||
toBigInteger
|
||||
toBigIntegerExact
|
||||
toEngineeringString
|
||||
toPlainString
|
||||
toString
|
||||
ulp
|
||||
unscaledValue
|
||||
longValue
|
||||
longValueExact
|
||||
abs
|
||||
add
|
||||
divide
|
||||
divideToIntegralValue
|
||||
multiply
|
||||
negate
|
||||
plus
|
||||
pow
|
||||
remainder
|
||||
setScale
|
||||
subtract
|
||||
divideAndRemainder
|
||||
|
||||
*/
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
205
test/perf/lib/bigdecimal_GWT/LICENCE.txt
Normal file
205
test/perf/lib/bigdecimal_GWT/LICENCE.txt
Normal file
@@ -0,0 +1,205 @@
|
||||
https://github.com/iriscouch/bigdecimal.js
|
||||
|
||||
BigDecimal for Javascript is licensed under the Apache License, version 2.0:
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
592
test/perf/lib/bigdecimal_GWT/bigdecimal.js
Normal file
592
test/perf/lib/bigdecimal_GWT/bigdecimal.js
Normal file
File diff suppressed because one or more lines are too long
5724
test/perf/lib/bigdecimal_ICU4J/BigDecimal-all-last.js
Normal file
5724
test/perf/lib/bigdecimal_ICU4J/BigDecimal-all-last.js
Normal file
File diff suppressed because it is too large
Load Diff
61
test/perf/lib/bigdecimal_ICU4J/BigDecimal-all-last.min.js
vendored
Normal file
61
test/perf/lib/bigdecimal_ICU4J/BigDecimal-all-last.min.js
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (c) 2012 Daniel Trebbien and other contributors
|
||||
Portions Copyright (c) 2003 STZ-IDA and PTV AG, Karlsruhe, Germany
|
||||
Portions Copyright (c) 1995-2001 International Business Machines Corporation and others
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder.
|
||||
*/
|
||||
(function(){var m,k=function(){this.form=this.digits=0;this.lostDigits=!1;this.roundingMode=0;var a=this.DEFAULT_FORM,b=this.DEFAULT_LOSTDIGITS,c=this.DEFAULT_ROUNDINGMODE;if(4==k.arguments.length)a=k.arguments[1],b=k.arguments[2],c=k.arguments[3];else if(3==k.arguments.length)a=k.arguments[1],b=k.arguments[2];else if(2==k.arguments.length)a=k.arguments[1];else if(1!=k.arguments.length)throw"MathContext(): "+k.arguments.length+" arguments given; expected 1 to 4";var d=k.arguments[0];if(d!=this.DEFAULT_DIGITS){if(d<
|
||||
this.MIN_DIGITS)throw"MathContext(): Digits too small: "+d;if(d>this.MAX_DIGITS)throw"MathContext(): Digits too large: "+d;}if(a!=this.SCIENTIFIC&&a!=this.ENGINEERING&&a!=this.PLAIN)throw"MathContext() Bad form value: "+a;if(!this.isValidRound(c))throw"MathContext(): Bad roundingMode value: "+c;this.digits=d;this.form=a;this.lostDigits=b;this.roundingMode=c};k.prototype.getDigits=function(){return this.digits};k.prototype.getForm=function(){return this.form};k.prototype.getLostDigits=function(){return this.lostDigits};
|
||||
k.prototype.getRoundingMode=function(){return this.roundingMode};k.prototype.toString=function(){var a=null,b=0,c=null,a=this.form==this.SCIENTIFIC?"SCIENTIFIC":this.form==this.ENGINEERING?"ENGINEERING":"PLAIN",d=this.ROUNDS.length,b=0;a:for(;0<d;d--,b++)if(this.roundingMode==this.ROUNDS[b]){c=this.ROUNDWORDS[b];break a}return"digits="+this.digits+" form="+a+" lostDigits="+(this.lostDigits?"1":"0")+" roundingMode="+c};k.prototype.isValidRound=function(a){var b=0,c=this.ROUNDS.length,b=0;for(;0<c;c--,
|
||||
b++)if(a==this.ROUNDS[b])return!0;return!1};k.PLAIN=k.prototype.PLAIN=0;k.SCIENTIFIC=k.prototype.SCIENTIFIC=1;k.ENGINEERING=k.prototype.ENGINEERING=2;k.ROUND_CEILING=k.prototype.ROUND_CEILING=2;k.ROUND_DOWN=k.prototype.ROUND_DOWN=1;k.ROUND_FLOOR=k.prototype.ROUND_FLOOR=3;k.ROUND_HALF_DOWN=k.prototype.ROUND_HALF_DOWN=5;k.ROUND_HALF_EVEN=k.prototype.ROUND_HALF_EVEN=6;k.ROUND_HALF_UP=k.prototype.ROUND_HALF_UP=4;k.ROUND_UNNECESSARY=k.prototype.ROUND_UNNECESSARY=7;k.ROUND_UP=k.prototype.ROUND_UP=0;k.prototype.DEFAULT_FORM=
|
||||
k.prototype.SCIENTIFIC;k.prototype.DEFAULT_DIGITS=9;k.prototype.DEFAULT_LOSTDIGITS=!1;k.prototype.DEFAULT_ROUNDINGMODE=k.prototype.ROUND_HALF_UP;k.prototype.MIN_DIGITS=0;k.prototype.MAX_DIGITS=999999999;k.prototype.ROUNDS=[k.prototype.ROUND_HALF_UP,k.prototype.ROUND_UNNECESSARY,k.prototype.ROUND_CEILING,k.prototype.ROUND_DOWN,k.prototype.ROUND_FLOOR,k.prototype.ROUND_HALF_DOWN,k.prototype.ROUND_HALF_EVEN,k.prototype.ROUND_UP];k.prototype.ROUNDWORDS="ROUND_HALF_UP ROUND_UNNECESSARY ROUND_CEILING ROUND_DOWN ROUND_FLOOR ROUND_HALF_DOWN ROUND_HALF_EVEN ROUND_UP".split(" ");
|
||||
k.prototype.DEFAULT=new k(k.prototype.DEFAULT_DIGITS,k.prototype.DEFAULT_FORM,k.prototype.DEFAULT_LOSTDIGITS,k.prototype.DEFAULT_ROUNDINGMODE);m=k;var v,G=function(a,b){return(a-a%b)/b},K=function(a){var b=Array(a),c;for(c=0;c<a;++c)b[c]=0;return b},h=function(){this.ind=0;this.form=m.prototype.PLAIN;this.mant=null;this.exp=0;if(0!=h.arguments.length){var a,b,c;1==h.arguments.length?(a=h.arguments[0],b=0,c=a.length):(a=h.arguments[0],b=h.arguments[1],c=h.arguments[2]);"string"==typeof a&&(a=a.split(""));
|
||||
var d,e,i,f,g,j=0,l=0;e=!1;var k=l=l=j=0,q=0;f=0;0>=c&&this.bad("BigDecimal(): ",a);this.ind=this.ispos;"-"==a[0]?(c--,0==c&&this.bad("BigDecimal(): ",a),this.ind=this.isneg,b++):"+"==a[0]&&(c--,0==c&&this.bad("BigDecimal(): ",a),b++);e=d=!1;i=0;g=f=-1;k=c;j=b;a:for(;0<k;k--,j++){l=a[j];if("0"<=l&&"9">=l){g=j;i++;continue a}if("."==l){0<=f&&this.bad("BigDecimal(): ",a);f=j-b;continue a}if("e"!=l&&"E"!=l){("0">l||"9"<l)&&this.bad("BigDecimal(): ",a);d=!0;g=j;i++;continue a}j-b>c-2&&this.bad("BigDecimal(): ",
|
||||
a);e=!1;"-"==a[j+1]?(e=!0,j+=2):j="+"==a[j+1]?j+2:j+1;l=c-(j-b);(0==l||9<l)&&this.bad("BigDecimal(): ",a);c=l;l=j;for(;0<c;c--,l++)k=a[l],"0">k&&this.bad("BigDecimal(): ",a),"9"<k?this.bad("BigDecimal(): ",a):q=k-0,this.exp=10*this.exp+q;e&&(this.exp=-this.exp);e=!0;break a}0==i&&this.bad("BigDecimal(): ",a);0<=f&&(this.exp=this.exp+f-i);q=g-1;j=b;a:for(;j<=q;j++)if(l=a[j],"0"==l)b++,f--,i--;else if("."==l)b++,f--;else break a;this.mant=Array(i);l=b;if(d){b=i;j=0;for(;0<b;b--,j++)j==f&&l++,k=a[l],
|
||||
"9">=k?this.mant[j]=k-0:this.bad("BigDecimal(): ",a),l++}else{b=i;j=0;for(;0<b;b--,j++)j==f&&l++,this.mant[j]=a[l]-0,l++}0==this.mant[0]?(this.ind=this.iszero,0<this.exp&&(this.exp=0),e&&(this.mant=this.ZERO.mant,this.exp=0)):e&&(this.form=m.prototype.SCIENTIFIC,f=this.exp+this.mant.length-1,(f<this.MinExp||f>this.MaxExp)&&this.bad("BigDecimal(): ",a))}},H=function(){var a;if(1==H.arguments.length)a=H.arguments[0];else if(0==H.arguments.length)a=this.plainMC;else throw"abs(): "+H.arguments.length+
|
||||
" arguments given; expected 0 or 1";return this.ind==this.isneg?this.negate(a):this.plus(a)},w=function(){var a;if(2==w.arguments.length)a=w.arguments[1];else if(1==w.arguments.length)a=this.plainMC;else throw"add(): "+w.arguments.length+" arguments given; expected 1 or 2";var b=w.arguments[0],c,d,e,i,f,g,j,l=0;d=l=0;var l=null,k=l=0,q=0,t=0,s=0,n=0;a.lostDigits&&this.checkdigits(b,a.digits);c=this;if(0==c.ind&&a.form!=m.prototype.PLAIN)return b.plus(a);if(0==b.ind&&a.form!=m.prototype.PLAIN)return c.plus(a);
|
||||
d=a.digits;0<d&&(c.mant.length>d&&(c=this.clone(c).round(a)),b.mant.length>d&&(b=this.clone(b).round(a)));e=new h;i=c.mant;f=c.mant.length;g=b.mant;j=b.mant.length;if(c.exp==b.exp)e.exp=c.exp;else if(c.exp>b.exp){l=f+c.exp-b.exp;if(l>=j+d+1&&0<d)return e.mant=i,e.exp=c.exp,e.ind=c.ind,f<d&&(e.mant=this.extend(c.mant,d),e.exp-=d-f),e.finish(a,!1);e.exp=b.exp;l>d+1&&0<d&&(l=l-d-1,j-=l,e.exp+=l,l=d+1);l>f&&(f=l)}else{l=j+b.exp-c.exp;if(l>=f+d+1&&0<d)return e.mant=g,e.exp=b.exp,e.ind=b.ind,j<d&&(e.mant=
|
||||
this.extend(b.mant,d),e.exp-=d-j),e.finish(a,!1);e.exp=c.exp;l>d+1&&0<d&&(l=l-d-1,f-=l,e.exp+=l,l=d+1);l>j&&(j=l)}e.ind=c.ind==this.iszero?this.ispos:c.ind;if((c.ind==this.isneg?1:0)==(b.ind==this.isneg?1:0))d=1;else{do{d=-1;do if(b.ind!=this.iszero)if(f<j||c.ind==this.iszero)l=i,i=g,g=l,l=f,f=j,j=l,e.ind=-e.ind;else if(!(f>j)){k=l=0;q=i.length-1;t=g.length-1;c:for(;;){if(l<=q)s=i[l];else{if(k>t){if(a.form!=m.prototype.PLAIN)return this.ZERO;break c}s=0}n=k<=t?g[k]:0;if(s!=n){s<n&&(l=i,i=g,g=l,l=
|
||||
f,f=j,j=l,e.ind=-e.ind);break c}l++;k++}}while(0)}while(0)}e.mant=this.byteaddsub(i,f,g,j,d,!1);return e.finish(a,!1)},x=function(){var a;if(2==x.arguments.length)a=x.arguments[1];else if(1==x.arguments.length)a=this.plainMC;else throw"compareTo(): "+x.arguments.length+" arguments given; expected 1 or 2";var b=x.arguments[0],c=0,c=0;a.lostDigits&&this.checkdigits(b,a.digits);if(this.ind==b.ind&&this.exp==b.exp){c=this.mant.length;if(c<b.mant.length)return-this.ind;if(c>b.mant.length)return this.ind;
|
||||
if(c<=a.digits||0==a.digits){a=c;c=0;for(;0<a;a--,c++){if(this.mant[c]<b.mant[c])return-this.ind;if(this.mant[c]>b.mant[c])return this.ind}return 0}}else{if(this.ind<b.ind)return-1;if(this.ind>b.ind)return 1}b=this.clone(b);b.ind=-b.ind;return this.add(b,a).ind},p=function(){var a,b=-1;if(2==p.arguments.length)a="number"==typeof p.arguments[1]?new m(0,m.prototype.PLAIN,!1,p.arguments[1]):p.arguments[1];else if(3==p.arguments.length){b=p.arguments[1];if(0>b)throw"divide(): Negative scale: "+b;a=new m(0,
|
||||
m.prototype.PLAIN,!1,p.arguments[2])}else if(1==p.arguments.length)a=this.plainMC;else throw"divide(): "+p.arguments.length+" arguments given; expected between 1 and 3";return this.dodivide("D",p.arguments[0],a,b)},y=function(){var a;if(2==y.arguments.length)a=y.arguments[1];else if(1==y.arguments.length)a=this.plainMC;else throw"divideInteger(): "+y.arguments.length+" arguments given; expected 1 or 2";return this.dodivide("I",y.arguments[0],a,0)},z=function(){var a;if(2==z.arguments.length)a=z.arguments[1];
|
||||
else if(1==z.arguments.length)a=this.plainMC;else throw"max(): "+z.arguments.length+" arguments given; expected 1 or 2";var b=z.arguments[0];return 0<=this.compareTo(b,a)?this.plus(a):b.plus(a)},A=function(){var a;if(2==A.arguments.length)a=A.arguments[1];else if(1==A.arguments.length)a=this.plainMC;else throw"min(): "+A.arguments.length+" arguments given; expected 1 or 2";var b=A.arguments[0];return 0>=this.compareTo(b,a)?this.plus(a):b.plus(a)},B=function(){var a;if(2==B.arguments.length)a=B.arguments[1];
|
||||
else if(1==B.arguments.length)a=this.plainMC;else throw"multiply(): "+B.arguments.length+" arguments given; expected 1 or 2";var b=B.arguments[0],c,d,e,i=e=null,f,g=0,j,l=0,k=0;a.lostDigits&&this.checkdigits(b,a.digits);c=this;d=0;e=a.digits;0<e?(c.mant.length>e&&(c=this.clone(c).round(a)),b.mant.length>e&&(b=this.clone(b).round(a))):(0<c.exp&&(d+=c.exp),0<b.exp&&(d+=b.exp));c.mant.length<b.mant.length?(e=c.mant,i=b.mant):(e=b.mant,i=c.mant);f=e.length+i.length-1;g=9<e[0]*i[0]?f+1:f;j=new h;var g=
|
||||
this.createArrayWithZeros(g),m=e.length,l=0;for(;0<m;m--,l++)k=e[l],0!=k&&(g=this.byteaddsub(g,g.length,i,f,k,!0)),f--;j.ind=c.ind*b.ind;j.exp=c.exp+b.exp-d;j.mant=0==d?g:this.extend(g,g.length+d);return j.finish(a,!1)},I=function(){var a;if(1==I.arguments.length)a=I.arguments[0];else if(0==I.arguments.length)a=this.plainMC;else throw"negate(): "+I.arguments.length+" arguments given; expected 0 or 1";var b;a.lostDigits&&this.checkdigits(null,a.digits);b=this.clone(this);b.ind=-b.ind;return b.finish(a,
|
||||
!1)},J=function(){var a;if(1==J.arguments.length)a=J.arguments[0];else if(0==J.arguments.length)a=this.plainMC;else throw"plus(): "+J.arguments.length+" arguments given; expected 0 or 1";a.lostDigits&&this.checkdigits(null,a.digits);return a.form==m.prototype.PLAIN&&this.form==m.prototype.PLAIN&&(this.mant.length<=a.digits||0==a.digits)?this:this.clone(this).finish(a,!1)},C=function(){var a;if(2==C.arguments.length)a=C.arguments[1];else if(1==C.arguments.length)a=this.plainMC;else throw"pow(): "+
|
||||
C.arguments.length+" arguments given; expected 1 or 2";var b=C.arguments[0],c,d,e,i=e=0,f,g=0;a.lostDigits&&this.checkdigits(b,a.digits);c=b.intcheck(this.MinArg,this.MaxArg);d=this;e=a.digits;if(0==e){if(b.ind==this.isneg)throw"pow(): Negative power: "+b.toString();e=0}else{if(b.mant.length+b.exp>e)throw"pow(): Too many digits: "+b.toString();d.mant.length>e&&(d=this.clone(d).round(a));i=b.mant.length+b.exp;e=e+i+1}e=new m(e,a.form,!1,a.roundingMode);i=this.ONE;if(0==c)return i;0>c&&(c=-c);f=!1;
|
||||
g=1;a:for(;;g++){c<<=1;0>c&&(f=!0,i=i.multiply(d,e));if(31==g)break a;if(!f)continue a;i=i.multiply(i,e)}0>b.ind&&(i=this.ONE.divide(i,e));return i.finish(a,!0)},D=function(){var a;if(2==D.arguments.length)a=D.arguments[1];else if(1==D.arguments.length)a=this.plainMC;else throw"remainder(): "+D.arguments.length+" arguments given; expected 1 or 2";return this.dodivide("R",D.arguments[0],a,-1)},E=function(){var a;if(2==E.arguments.length)a=E.arguments[1];else if(1==E.arguments.length)a=this.plainMC;
|
||||
else throw"subtract(): "+E.arguments.length+" arguments given; expected 1 or 2";var b=E.arguments[0];a.lostDigits&&this.checkdigits(b,a.digits);b=this.clone(b);b.ind=-b.ind;return this.add(b,a)},r=function(){var a,b,c,d;if(6==r.arguments.length)a=r.arguments[2],b=r.arguments[3],c=r.arguments[4],d=r.arguments[5];else if(2==r.arguments.length)b=a=-1,c=m.prototype.SCIENTIFIC,d=this.ROUND_HALF_UP;else throw"format(): "+r.arguments.length+" arguments given; expected 2 or 6";var e=r.arguments[0],i=r.arguments[1],
|
||||
f,g=0,g=g=0,j=null,l=j=g=0;f=0;g=null;l=j=0;(-1>e||0==e)&&this.badarg("format",1,e);-1>i&&this.badarg("format",2,i);(-1>a||0==a)&&this.badarg("format",3,a);-1>b&&this.badarg("format",4,b);c!=m.prototype.SCIENTIFIC&&c!=m.prototype.ENGINEERING&&(-1==c?c=m.prototype.SCIENTIFIC:this.badarg("format",5,c));if(d!=this.ROUND_HALF_UP)try{-1==d?d=this.ROUND_HALF_UP:new m(9,m.prototype.SCIENTIFIC,!1,d)}catch(h){this.badarg("format",6,d)}f=this.clone(this);-1==b?f.form=m.prototype.PLAIN:f.ind==this.iszero?f.form=
|
||||
m.prototype.PLAIN:(g=f.exp+f.mant.length,f.form=g>b?c:-5>g?c:m.prototype.PLAIN);if(0<=i)a:for(;;){f.form==m.prototype.PLAIN?g=-f.exp:f.form==m.prototype.SCIENTIFIC?g=f.mant.length-1:(g=(f.exp+f.mant.length-1)%3,0>g&&(g=3+g),g++,g=g>=f.mant.length?0:f.mant.length-g);if(g==i)break a;if(g<i){j=this.extend(f.mant,f.mant.length+i-g);f.mant=j;f.exp-=i-g;if(f.exp<this.MinExp)throw"format(): Exponent Overflow: "+f.exp;break a}g-=i;if(g>f.mant.length){f.mant=this.ZERO.mant;f.ind=this.iszero;f.exp=0;continue a}j=
|
||||
f.mant.length-g;l=f.exp;f.round(j,d);if(f.exp-l==g)break a}b=f.layout();if(0<e){c=b.length;f=0;a:for(;0<c;c--,f++){if("."==b[f])break a;if("E"==b[f])break a}f>e&&this.badarg("format",1,e);if(f<e){g=Array(b.length+e-f);e-=f;j=0;for(;0<e;e--,j++)g[j]=" ";this.arraycopy(b,0,g,j,b.length);b=g}}if(0<a){e=b.length-1;f=b.length-1;a:for(;0<e;e--,f--)if("E"==b[f])break a;if(0==f){g=Array(b.length+a+2);this.arraycopy(b,0,g,0,b.length);a+=2;j=b.length;for(;0<a;a--,j++)g[j]=" ";b=g}else if(l=b.length-f-2,l>a&&
|
||||
this.badarg("format",3,a),l<a){g=Array(b.length+a-l);this.arraycopy(b,0,g,0,f+2);a-=l;j=f+2;for(;0<a;a--,j++)g[j]="0";this.arraycopy(b,f+2,g,j,l);b=g}}return b.join("")},F=function(){var a;if(2==F.arguments.length)a=F.arguments[1];else if(1==F.arguments.length)a=this.ROUND_UNNECESSARY;else throw"setScale(): "+F.arguments.length+" given; expected 1 or 2";var b=F.arguments[0],c,d;c=c=0;c=this.scale();if(c==b&&this.form==m.prototype.PLAIN)return this;d=this.clone(this);if(c<=b)c=0==c?d.exp+b:b-c,d.mant=
|
||||
this.extend(d.mant,d.mant.length+c),d.exp=-b;else{if(0>b)throw"setScale(): Negative scale: "+b;c=d.mant.length-(c-b);d=d.round(c,a);d.exp!=-b&&(d.mant=this.extend(d.mant,d.mant.length+1),d.exp-=1)}d.form=m.prototype.PLAIN;return d};v=function(){var a,b=0,c=0;a=Array(190);b=0;a:for(;189>=b;b++){c=b-90;if(0<=c){a[b]=c%10;h.prototype.bytecar[b]=G(c,10);continue a}c+=100;a[b]=c%10;h.prototype.bytecar[b]=G(c,10)-10}return a};var u=function(){var a,b;if(2==u.arguments.length)a=u.arguments[0],b=u.arguments[1];
|
||||
else if(1==u.arguments.length)b=u.arguments[0],a=b.digits,b=b.roundingMode;else throw"round(): "+u.arguments.length+" arguments given; expected 1 or 2";var c,d,e=!1,i=0,f;c=null;c=this.mant.length-a;if(0>=c)return this;this.exp+=c;c=this.ind;d=this.mant;0<a?(this.mant=Array(a),this.arraycopy(d,0,this.mant,0,a),e=!0,i=d[a]):(this.mant=this.ZERO.mant,this.ind=this.iszero,e=!1,i=0==a?d[0]:0);f=0;if(b==this.ROUND_HALF_UP)5<=i&&(f=c);else if(b==this.ROUND_UNNECESSARY){if(!this.allzero(d,a))throw"round(): Rounding necessary";
|
||||
}else if(b==this.ROUND_HALF_DOWN)5<i?f=c:5==i&&(this.allzero(d,a+1)||(f=c));else if(b==this.ROUND_HALF_EVEN)5<i?f=c:5==i&&(this.allzero(d,a+1)?1==this.mant[this.mant.length-1]%2&&(f=c):f=c);else if(b!=this.ROUND_DOWN)if(b==this.ROUND_UP)this.allzero(d,a)||(f=c);else if(b==this.ROUND_CEILING)0<c&&(this.allzero(d,a)||(f=c));else if(b==this.ROUND_FLOOR)0>c&&(this.allzero(d,a)||(f=c));else throw"round(): Bad round value: "+b;0!=f&&(this.ind==this.iszero?(this.mant=this.ONE.mant,this.ind=f):(this.ind==
|
||||
this.isneg&&(f=-f),c=this.byteaddsub(this.mant,this.mant.length,this.ONE.mant,1,f,e),c.length>this.mant.length?(this.exp++,this.arraycopy(c,0,this.mant,0,this.mant.length)):this.mant=c));if(this.exp>this.MaxExp)throw"round(): Exponent Overflow: "+this.exp;return this};h.prototype.div=G;h.prototype.arraycopy=function(a,b,c,d,e){var i;if(d>b)for(i=e-1;0<=i;--i)c[i+d]=a[i+b];else for(i=0;i<e;++i)c[i+d]=a[i+b]};h.prototype.createArrayWithZeros=K;h.prototype.abs=H;h.prototype.add=w;h.prototype.compareTo=
|
||||
x;h.prototype.divide=p;h.prototype.divideInteger=y;h.prototype.max=z;h.prototype.min=A;h.prototype.multiply=B;h.prototype.negate=I;h.prototype.plus=J;h.prototype.pow=C;h.prototype.remainder=D;h.prototype.subtract=E;h.prototype.equals=function(a){var b=0,c=null,d=null;if(null==a||!(a instanceof h)||this.ind!=a.ind)return!1;if(this.mant.length==a.mant.length&&this.exp==a.exp&&this.form==a.form){c=this.mant.length;b=0;for(;0<c;c--,b++)if(this.mant[b]!=a.mant[b])return!1}else{c=this.layout();d=a.layout();
|
||||
if(c.length!=d.length)return!1;a=c.length;b=0;for(;0<a;a--,b++)if(c[b]!=d[b])return!1}return!0};h.prototype.format=r;h.prototype.intValueExact=function(){var a,b=0,c,d=0;a=0;if(this.ind==this.iszero)return 0;a=this.mant.length-1;if(0>this.exp){a+=this.exp;if(!this.allzero(this.mant,a+1))throw"intValueExact(): Decimal part non-zero: "+this.toString();if(0>a)return 0;b=0}else{if(9<this.exp+a)throw"intValueExact(): Conversion overflow: "+this.toString();b=this.exp}c=0;var e=a+b,d=0;for(;d<=e;d++)c*=
|
||||
10,d<=a&&(c+=this.mant[d]);if(9==a+b&&(a=G(c,1E9),a!=this.mant[0])){if(-2147483648==c&&this.ind==this.isneg&&2==this.mant[0])return c;throw"intValueExact(): Conversion overflow: "+this.toString();}return this.ind==this.ispos?c:-c};h.prototype.movePointLeft=function(a){var b;b=this.clone(this);b.exp-=a;return b.finish(this.plainMC,!1)};h.prototype.movePointRight=function(a){var b;b=this.clone(this);b.exp+=a;return b.finish(this.plainMC,!1)};h.prototype.scale=function(){return 0<=this.exp?0:-this.exp};
|
||||
h.prototype.setScale=F;h.prototype.signum=function(){return this.ind};h.prototype.toString=function(){return this.layout().join("")};h.prototype.layout=function(){var a,b=0,b=null,c=0,d=0;a=0;var d=null,e,b=0;a=Array(this.mant.length);c=this.mant.length;b=0;for(;0<c;c--,b++)a[b]=this.mant[b]+"";if(this.form!=m.prototype.PLAIN){b="";this.ind==this.isneg&&(b+="-");c=this.exp+a.length-1;if(this.form==m.prototype.SCIENTIFIC)b+=a[0],1<a.length&&(b+="."),b+=a.slice(1).join("");else if(d=c%3,0>d&&(d=3+d),
|
||||
c-=d,d++,d>=a.length){b+=a.join("");for(a=d-a.length;0<a;a--)b+="0"}else b+=a.slice(0,d).join(""),b=b+"."+a.slice(d).join("");0!=c&&(0>c?(a="-",c=-c):a="+",b+="E",b+=a,b+=c);return b.split("")}if(0==this.exp){if(0<=this.ind)return a;d=Array(a.length+1);d[0]="-";this.arraycopy(a,0,d,1,a.length);return d}c=this.ind==this.isneg?1:0;e=this.exp+a.length;if(1>e){b=c+2-this.exp;d=Array(b);0!=c&&(d[0]="-");d[c]="0";d[c+1]=".";var i=-e,b=c+2;for(;0<i;i--,b++)d[b]="0";this.arraycopy(a,0,d,c+2-e,a.length);return d}if(e>
|
||||
a.length){d=Array(c+e);0!=c&&(d[0]="-");this.arraycopy(a,0,d,c,a.length);e-=a.length;b=c+a.length;for(;0<e;e--,b++)d[b]="0";return d}b=c+1+a.length;d=Array(b);0!=c&&(d[0]="-");this.arraycopy(a,0,d,c,e);d[c+e]=".";this.arraycopy(a,e,d,c+e+1,a.length-e);return d};h.prototype.intcheck=function(a,b){var c;c=this.intValueExact();if(c<a||c>b)throw"intcheck(): Conversion overflow: "+c;return c};h.prototype.dodivide=function(a,b,c,d){var e,i,f,g,j,l,k,q,t,s=0,n=0,p=0;i=i=n=n=n=0;e=null;e=e=0;e=null;c.lostDigits&&
|
||||
this.checkdigits(b,c.digits);e=this;if(0==b.ind)throw"dodivide(): Divide by 0";if(0==e.ind)return c.form!=m.prototype.PLAIN?this.ZERO:-1==d?e:e.setScale(d);i=c.digits;0<i?(e.mant.length>i&&(e=this.clone(e).round(c)),b.mant.length>i&&(b=this.clone(b).round(c))):(-1==d&&(d=e.scale()),i=e.mant.length,d!=-e.exp&&(i=i+d+e.exp),i=i-(b.mant.length-1)-b.exp,i<e.mant.length&&(i=e.mant.length),i<b.mant.length&&(i=b.mant.length));f=e.exp-b.exp+e.mant.length-b.mant.length;if(0>f&&"D"!=a)return"I"==a?this.ZERO:
|
||||
this.clone(e).finish(c,!1);g=new h;g.ind=e.ind*b.ind;g.exp=f;g.mant=this.createArrayWithZeros(i+1);j=i+i+1;f=this.extend(e.mant,j);l=j;k=b.mant;q=j;t=10*k[0]+1;1<k.length&&(t+=k[1]);j=0;a:for(;;){s=0;b:for(;;){if(l<q)break b;if(l==q){c:do{var r=l,n=0;for(;0<r;r--,n++){p=n<k.length?k[n]:0;if(f[n]<p)break b;if(f[n]>p)break c}s++;g.mant[j]=s;j++;f[0]=0;break a}while(0);n=f[0]}else n=10*f[0],1<l&&(n+=f[1]);n=G(10*n,t);0==n&&(n=1);s+=n;f=this.byteaddsub(f,l,k,q,-n,!0);if(0!=f[0])continue b;p=l-2;n=0;c:for(;n<=
|
||||
p;n++){if(0!=f[n])break c;l--}if(0==n)continue b;this.arraycopy(f,n,f,0,l)}if(0!=j||0!=s){g.mant[j]=s;j++;if(j==i+1)break a;if(0==f[0])break a}if(0<=d&&-g.exp>d)break a;if("D"!=a&&0>=g.exp)break a;g.exp-=1;q--}0==j&&(j=1);if("I"==a||"R"==a){if(j+g.exp>i)throw"dodivide(): Integer overflow";if("R"==a){do{if(0==g.mant[0])return this.clone(e).finish(c,!1);if(0==f[0])return this.ZERO;g.ind=e.ind;i=i+i+1-e.mant.length;g.exp=g.exp-i+e.exp;i=l;n=i-1;b:for(;1<=n&&g.exp<e.exp&&g.exp<b.exp;n--){if(0!=f[n])break b;
|
||||
i--;g.exp+=1}i<f.length&&(e=Array(i),this.arraycopy(f,0,e,0,i),f=e);g.mant=f;return g.finish(c,!1)}while(0)}}else 0!=f[0]&&(e=g.mant[j-1],0==e%5&&(g.mant[j-1]=e+1));if(0<=d)return j!=g.mant.length&&(g.exp-=g.mant.length-j),e=g.mant.length-(-g.exp-d),g.round(e,c.roundingMode),g.exp!=-d&&(g.mant=this.extend(g.mant,g.mant.length+1),g.exp-=1),g.finish(c,!0);if(j==g.mant.length)g.round(c);else{if(0==g.mant[0])return this.ZERO;e=Array(j);this.arraycopy(g.mant,0,e,0,j);g.mant=e}return g.finish(c,!0)};h.prototype.bad=
|
||||
function(a,b){throw a+"Not a number: "+b;};h.prototype.badarg=function(a,b,c){throw"Bad argument "+b+" to "+a+": "+c;};h.prototype.extend=function(a,b){var c;if(a.length==b)return a;c=K(b);this.arraycopy(a,0,c,0,a.length);return c};h.prototype.byteaddsub=function(a,b,c,d,e,i){var f,g,j,h,k,m,p=0;f=m=0;f=a.length;g=c.length;b-=1;h=j=d-1;h<b&&(h=b);d=null;i&&h+1==f&&(d=a);null==d&&(d=this.createArrayWithZeros(h+1));k=!1;1==e?k=!0:-1==e&&(k=!0);m=0;p=h;a:for(;0<=p;p--){0<=b&&(b<f&&(m+=a[b]),b--);0<=
|
||||
j&&(j<g&&(m=k?0<e?m+c[j]:m-c[j]:m+c[j]*e),j--);if(10>m&&0<=m){do{d[p]=m;m=0;continue a}while(0)}m+=90;d[p]=this.bytedig[m];m=this.bytecar[m]}if(0==m)return d;c=null;i&&h+2==a.length&&(c=a);null==c&&(c=Array(h+2));c[0]=m;a=h+1;f=0;for(;0<a;a--,f++)c[f+1]=d[f];return c};h.prototype.diginit=v;h.prototype.clone=function(a){var b;b=new h;b.ind=a.ind;b.exp=a.exp;b.form=a.form;b.mant=a.mant;return b};h.prototype.checkdigits=function(a,b){if(0!=b){if(this.mant.length>b&&!this.allzero(this.mant,b))throw"Too many digits: "+
|
||||
this.toString();if(null!=a&&a.mant.length>b&&!this.allzero(a.mant,b))throw"Too many digits: "+a.toString();}};h.prototype.round=u;h.prototype.allzero=function(a,b){var c=0;0>b&&(b=0);var d=a.length-1,c=b;for(;c<=d;c++)if(0!=a[c])return!1;return!0};h.prototype.finish=function(a,b){var c=0,d=0,e=null,c=d=0;0!=a.digits&&this.mant.length>a.digits&&this.round(a);if(b&&a.form!=m.prototype.PLAIN){c=this.mant.length;d=c-1;a:for(;1<=d;d--){if(0!=this.mant[d])break a;c--;this.exp++}c<this.mant.length&&(e=Array(c),
|
||||
this.arraycopy(this.mant,0,e,0,c),this.mant=e)}this.form=m.prototype.PLAIN;c=this.mant.length;d=0;for(;0<c;c--,d++)if(0!=this.mant[d]){0<d&&(e=Array(this.mant.length-d),this.arraycopy(this.mant,d,e,0,this.mant.length-d),this.mant=e);d=this.exp+this.mant.length;if(0<d){if(d>a.digits&&0!=a.digits&&(this.form=a.form),d-1<=this.MaxExp)return this}else-5>d&&(this.form=a.form);d--;if(d<this.MinExp||d>this.MaxExp){b:do{if(this.form==m.prototype.ENGINEERING&&(c=d%3,0>c&&(c=3+c),d-=c,d>=this.MinExp&&d<=this.MaxExp))break b;
|
||||
throw"finish(): Exponent Overflow: "+d;}while(0)}return this}this.ind=this.iszero;if(a.form!=m.prototype.PLAIN)this.exp=0;else if(0<this.exp)this.exp=0;else if(this.exp<this.MinExp)throw"finish(): Exponent Overflow: "+this.exp;this.mant=this.ZERO.mant;return this};h.prototype.isGreaterThan=function(a){return 0<this.compareTo(a)};h.prototype.isLessThan=function(a){return 0>this.compareTo(a)};h.prototype.isGreaterThanOrEqualTo=function(a){return 0<=this.compareTo(a)};h.prototype.isLessThanOrEqualTo=
|
||||
function(a){return 0>=this.compareTo(a)};h.prototype.isPositive=function(){return 0<this.compareTo(h.prototype.ZERO)};h.prototype.isNegative=function(){return 0>this.compareTo(h.prototype.ZERO)};h.prototype.isZero=function(){return this.equals(h.prototype.ZERO)};h.ROUND_CEILING=h.prototype.ROUND_CEILING=m.prototype.ROUND_CEILING;h.ROUND_DOWN=h.prototype.ROUND_DOWN=m.prototype.ROUND_DOWN;h.ROUND_FLOOR=h.prototype.ROUND_FLOOR=m.prototype.ROUND_FLOOR;h.ROUND_HALF_DOWN=h.prototype.ROUND_HALF_DOWN=m.prototype.ROUND_HALF_DOWN;
|
||||
h.ROUND_HALF_EVEN=h.prototype.ROUND_HALF_EVEN=m.prototype.ROUND_HALF_EVEN;h.ROUND_HALF_UP=h.prototype.ROUND_HALF_UP=m.prototype.ROUND_HALF_UP;h.ROUND_UNNECESSARY=h.prototype.ROUND_UNNECESSARY=m.prototype.ROUND_UNNECESSARY;h.ROUND_UP=h.prototype.ROUND_UP=m.prototype.ROUND_UP;h.prototype.ispos=1;h.prototype.iszero=0;h.prototype.isneg=-1;h.prototype.MinExp=-999999999;h.prototype.MaxExp=999999999;h.prototype.MinArg=-999999999;h.prototype.MaxArg=999999999;h.prototype.plainMC=new m(0,m.prototype.PLAIN);
|
||||
h.prototype.bytecar=Array(190);h.prototype.bytedig=v();h.ZERO=h.prototype.ZERO=new h("0");h.ONE=h.prototype.ONE=new h("1");h.TEN=h.prototype.TEN=new h("10");v=h;"function"===typeof define&&null!=define.amd?define({BigDecimal:v,MathContext:m}):"object"===typeof this&&(this.BigDecimal=v,this.MathContext=m)}).call(this);
|
||||
30
test/perf/lib/bigdecimal_ICU4J/LICENCE.txt
Normal file
30
test/perf/lib/bigdecimal_ICU4J/LICENCE.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
Copyright (c) 2012 Daniel Trebbien and other contributors
|
||||
Portions Copyright (c) 2003 STZ-IDA and PTV AG, Karlsruhe, Germany
|
||||
Portions Copyright (c) 1995-2001 International Business Machines Corporation and others
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder.
|
||||
|
||||
|
||||
|
||||
ICU4J license - ICU4J 1.3.1 and later
|
||||
COPYRIGHT AND PERMISSION NOTICE
|
||||
|
||||
Copyright (c) 1995-2001 International Business Machines Corporation and others
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
All trademarks and registered trademarks mentioned herein are the property of their respective owners.
|
||||
Reference in New Issue
Block a user