diff --git a/README.md b/README.md index b538c804..37258f1d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ -# Status $25,000 Global Hackathon +# DApp for Status.im -Extend Status with commands, create decentralized chatbots or mobile-ready your web DApp to win prizes. +Hackathon GitHub Issue: https://github.com/status-im/hackathon/issues/193 -http://hackathon.status.im +``` +{"whisper-identity": "193-ethcro", + "name": "#193 Ethcro", + "dapp-url": "https://d1p4nhcaryds24.cloudfront.net"} -http://docs.status.im +``` + +[*Note:* Put your full project description in your GitHub Issue RSVP. You may copy it below here, but we will review it on the GitHub Issue. ⚠️] diff --git a/app.css b/app.css new file mode 100644 index 00000000..827c57ab --- /dev/null +++ b/app.css @@ -0,0 +1,60 @@ +.list-block{} +.navbar-fixed .page>.searchbar, .navbar-fixed>.searchbar, .navbar-through .page>.searchbar, .navbar-through>.searchbar{top:0px} +body > div > div > div > div > div.page-content > div{margin-top:0px;} + +#arbitrate{display:none} +.avatar{float:left} +.card-header{word-break:break-word;} +#contract_info + { + background-image:url('https://superdevresources.com/wp-content/uploads/2014/08/12-paper-textures.jpg'); + background-size: cover; + background-position: center; + word-wrap:break-word; + } +#contract_header{background:lightblue} +.dispute + { + display:none; + background-image:url('http://fc02.deviantart.net/fs71/f/2013/198/b/1/__f_o_g_____custom_box_background___by_cre8art4life-d6dv82f.png'); + } +.complete + { + background-image:url('https://superdevresources.com/wp-content/uploads/2014/08/12-paper-textures.jpg'); + } +#winner_text{ +font-family: fantasy; + font-style: italic; + font-variant: small-caps; + font-weight: 300; + } +.gold_star{ + color:gold; + -webkit-transition:color 2s linear !important; + transition:color 2s linear !important; + } + +.material-icons{font-size:2em;} +.pic_ruling{display:block;margin:auto;} +.ruling + { + white-space:pre-line; + width:100%; + } +.selected + { + border: .5vw solid #468ddf; + border-radius: 100%; + } +.unselected + { + border:.5vw solid red; + border-radius: 100%; + } +.green{color:green} +.red{color:red} +.grey{color:lightgrey} +a.red{color:red !important} +a.blue{color:blue !important} +a.green{color:green !important} + diff --git a/app.js b/app.js new file mode 100644 index 00000000..c42bc50d --- /dev/null +++ b/app.js @@ -0,0 +1,7 @@ +function onContentLoaded() { + var accountSpan = document.getElementById("account"); + accountSpan.innerHTML = + + (typeof web3 === "undefined" ? "undefined" : web3.eth.accounts[0]); +} +document.addEventListener("DOMContentLoaded", onContentLoaded); \ No newline at end of file diff --git a/arbiter.html b/arbiter.html new file mode 100644 index 00000000..a3647322 --- /dev/null +++ b/arbiter.html @@ -0,0 +1,57 @@ +
A JavaScript library for arbitrary-precision arithmetic.
+ + ++ See the README on GitHub for a + quick-start introduction. +
+
+ In all examples below, var and semicolons are not shown, and if a commented-out
+ value is in quotes it means toString has been called on the preceding expression.
+
BigNumber(value [, base]) ⇒ BigNumber
+ value0, ±Infinity and
+ NaN.
+ 15 significant digits are
+ considered invalid (if ERRORS is true) as calling
+ toString or valueOf on
+ such numbers may not result in the intended value.
+ console.log( 823456789123456.3 ); // 823456789123456.2+
'0xff', are valid, as are
+ string values with the octal and binary prefixs '0o' and '0b'.
+ String values in octal literal form without the prefix will be interpreted as
+ decimals, e.g. '011' is interpreted as 11, not 9.
+ 10 to 36, lower and/or upper case letters can be
+ used to represent values from 10 to 35.
+ a-z represents values from 10 to
+ 35, A-Z from 36 to 61, and
+ $ and _ represent 62 and 63 respectively
+ (this can be changed by editing the ALPHABET variable near the top of the
+ source file).
+ base2 to 64 inclusive
+ value.base is omitted, or is null or undefined, base
+ 10 is assumed.
+ Returns a new instance of a BigNumber object.
+
+ If a base is specified, the value is rounded according to
+ the current DECIMAL_PLACES and
+ ROUNDING_MODE configuration.
+
+ See Errors for the treatment of an invalid value or
+ base.
+
+x = new BigNumber(9) // '9'
+y = new BigNumber(x) // '9'
+
+// 'new' is optional if ERRORS is false
+BigNumber(435.345) // '435.345'
+
+new BigNumber('5032485723458348569331745.33434346346912144534543')
+new BigNumber('4.321e+4') // '43210'
+new BigNumber('-735.0918e-430') // '-7.350918e-428'
+new BigNumber(Infinity) // 'Infinity'
+new BigNumber(NaN) // 'NaN'
+new BigNumber('.5') // '0.5'
+new BigNumber('+2') // '2'
+new BigNumber(-10110100.1, 2) // '-180.5'
+new BigNumber(-0b10110100.1) // '-180.5'
+new BigNumber('123412421.234324', 5) // '607236.557696'
+new BigNumber('ff.8', 16) // '255.5'
+new BigNumber('0xff.8') // '255.5'
+
+ The following throws 'not a base 2 number' if
+ ERRORS is true, otherwise it returns a BigNumber with value
+ NaN.
+
new BigNumber(9, 2)+
+ The following throws 'number type has more than 15 significant digits' if
+ ERRORS is true, otherwise it returns a BigNumber with value
+ 96517860459076820.
+
new BigNumber(96517860459076817.4395)+
+ The following throws 'not a number' if ERRORS
+ is true, otherwise it returns a BigNumber with value NaN.
+
new BigNumber('blurgh')
+ + A value is only rounded by the constructor if a base is specified. +
+BigNumber.config({ DECIMAL_PLACES: 5 })
+new BigNumber(1.23456789) // '1.23456789'
+new BigNumber(1.23456789, 10) // '1.23457'
+
+
+
+ The static methods of a BigNumber constructor.
+ + + + +.another([obj]) ⇒ BigNumber constructor
+ obj: object
+ Returns a new independent BigNumber constructor with configuration as described by
+ obj (see config), or with the default
+ configuration if obj is null or undefined.
+
BigNumber.config({ DECIMAL_PLACES: 5 })
+BN = BigNumber.another({ DECIMAL_PLACES: 9 })
+
+x = new BigNumber(1)
+y = new BN(1)
+
+x.div(3) // 0.33333
+y.div(3) // 0.333333333
+
+// BN = BigNumber.another({ DECIMAL_PLACES: 9 }) is equivalent to:
+BN = BigNumber.another()
+BN.config({ DECIMAL_PLACES: 9 })
+
+
+
+ set([obj]) ⇒ object
+ obj: object: an object that contains some or all of the following
+ properties.
+
Configures the settings for this particular BigNumber constructor.
+Note: the configuration can also be supplied as an argument list, see below.
+DECIMAL_PLACES0 to 1e+9 inclusive20
+ BigNumber.config({ DECIMAL_PLACES: 5 })
+BigNumber.set({ DECIMAL_PLACES: 5 }) // equivalent
+BigNumber.config(5) // equivalent
+ ROUNDING_MODE0 to 8 inclusive4 (ROUND_HALF_UP)
+ round,
+ toExponential,
+ toFixed,
+ toFormat and
+ toPrecision.
+ BigNumber.config({ ROUNDING_MODE: 0 })
+BigNumber.config(null, BigNumber.ROUND_UP) // equivalent
+ EXPONENTIAL_AT0 to 1e+9 inclusive, or
+ -1e+9 to 0 inclusive, integer
+ 0 to 1e+9 inclusive ][-7, 20]
+ toString returns exponential notation.
+ [-7, 20].
+ BigNumber.config({ EXPONENTIAL_AT: 2 })
+new BigNumber(12.3) // '12.3' e is only 1
+new BigNumber(123) // '1.23e+2'
+new BigNumber(0.123) // '0.123' e is only -1
+new BigNumber(0.0123) // '1.23e-2'
+
+BigNumber.config({ EXPONENTIAL_AT: [-7, 20] })
+new BigNumber(123456789) // '123456789' e is only 8
+new BigNumber(0.000000123) // '1.23e-7'
+
+// Almost never return exponential notation:
+BigNumber.config({ EXPONENTIAL_AT: 1e+9 })
+
+// Always return exponential notation:
+BigNumber.config({ EXPONENTIAL_AT: 0 })
+ EXPONENTIAL_AT, the toFixed method
+ will always return a value in normal notation and the toExponential method
+ will always return a value in exponential form.
+ toString with a base argument, e.g. toString(10), will
+ also always return normal notation.
+ RANGE1 to 1e+9 inclusive, or
+ -1e+9 to -1 inclusive, integer
+ 1 to 1e+9 inclusive ][-1e+9, 1e+9]
+ Infinity and underflow to
+ zero occurs.
+ Infinity and those with a
+ negative exponent of greater magnitude become zero.
+ Infinity, use [-324, 308].
+ BigNumber.config({ RANGE: 500 })
+BigNumber.config().RANGE // [ -500, 500 ]
+new BigNumber('9.999e499') // '9.999e+499'
+new BigNumber('1e500') // 'Infinity'
+new BigNumber('1e-499') // '1e-499'
+new BigNumber('1e-500') // '0'
+
+BigNumber.config({ RANGE: [-3, 4] })
+new BigNumber(99999) // '99999' e is only 4
+new BigNumber(100000) // 'Infinity' e is 5
+new BigNumber(0.001) // '0.01' e is only -3
+new BigNumber(0.0001) // '0' e is -4
+ 9.999...e+1000000000.1e-1000000000.
+ ERRORStrue, false, 0 or
+ 1.true
+ ERRORS is false, no errors will be thrown.
+ BigNumber.config({ ERRORS: false })CRYPTOtrue, false, 0 or
+ 1.false
+ CRYPTO is set to true then the
+ random method will generate random digits using
+ crypto.getRandomValues in browsers that support it, or
+ crypto.randomBytes if using a version of Node.js that supports it.
+ CRYPTO to true will fail, and if ERRORS
+ is true an exception will be thrown.
+ CRYPTO is false then the source of randomness used will be
+ Math.random (which is assumed to generate at least 30 bits of
+ randomness).
+ random.BigNumber.config({ CRYPTO: true })
+BigNumber.config().CRYPTO // true
+BigNumber.random() // 0.54340758610486147524
+ MODULO_MODE0 to 9 inclusive1 (ROUND_DOWN)
+ a mod n.q = a / n, is calculated according to the
+ ROUNDING_MODE that corresponds to the chosen
+ MODULO_MODE.
+ r, is calculated as: r = a - n * q.| Property | Value | Description |
|---|---|---|
| ROUND_UP | 0 | ++ The remainder is positive if the dividend is negative, otherwise it is negative. + | +
| ROUND_DOWN | 1 | +
+ The remainder has the same sign as the dividend. + This uses 'truncating division' and matches the behaviour of JavaScript's + remainder operator %.
+ |
+
| ROUND_FLOOR | 3 | +
+ The remainder has the same sign as the divisor. + This matches Python's % operator.
+ |
+
| ROUND_HALF_EVEN | 6 | +The IEEE 754 remainder function. | +
| EUCLID | 9 | +
+ The remainder is always positive. Euclidian division: + q = sign(n) * floor(a / abs(n))
+ |
+
modulo.BigNumber.config({ MODULO_MODE: BigNumber.EUCLID })
+BigNumber.config({ MODULO_MODE: 9 }) // equivalent
+ POW_PRECISION0 to 1e+9 inclusive.0
+ 0, the number of signifcant digits will not be limited.toPower.BigNumber.config({ POW_PRECISION: 100 })FORMATFORMAT object configures the format of the string returned by the
+ toFormat method.
+ FORMAT object that are
+ recognised, and their default values.
+ FORMAT object will not be checked for validity. The existing
+ FORMAT object will simply be replaced by the object that is passed in.
+ Note that all the properties shown below do not have to be included.
+ toFormat for examples of usage.
+BigNumber.config({
+ FORMAT: {
+ // the decimal separator
+ decimalSeparator: '.',
+ // the grouping separator of the integer part
+ groupSeparator: ',',
+ // the primary grouping size of the integer part
+ groupSize: 3,
+ // the secondary grouping size of the integer part
+ secondaryGroupSize: 0,
+ // the grouping separator of the fraction part
+ fractionGroupSeparator: ' ',
+ // the grouping size of the fraction part
+ fractionGroupSize: 0
+ }
+});
+ Returns an object with the above properties and their current values.
+
+ If the value to be assigned to any of the above properties is null or
+ undefined it is ignored.
+
See Errors for the treatment of invalid values.
+
+BigNumber.config({
+ DECIMAL_PLACES: 40,
+ ROUNDING_MODE: BigNumber.ROUND_HALF_CEIL,
+ EXPONENTIAL_AT: [-10, 20],
+ RANGE: [-500, 500],
+ ERRORS: true,
+ CRYPTO: true,
+ MODULO_MODE: BigNumber.ROUND_FLOOR,
+ POW_PRECISION: 80,
+ FORMAT: {
+ groupSize: 3,
+ groupSeparator: ' ',
+ decimalSeparator: ','
+ }
+});
+
+// Alternatively but equivalently (excluding FORMAT):
+BigNumber.config( 40, 7, [-10, 20], 500, 1, 1, 3, 80 )
+
+obj = BigNumber.config();
+obj.ERRORS // true
+obj.RANGE // [-500, 500]
+
+
+
+ .max([arg1 [, arg2, ...]]) ⇒ BigNumber
+
+ arg1, arg2, ...: number|string|BigNumber
+ See BigNumber for further parameter details.
+
+ Returns a BigNumber whose value is the maximum of arg1,
+ arg2,... .
+
The argument to this method can also be an array of values.
+The return value is always exact and unrounded.
+x = new BigNumber('3257869345.0378653')
+BigNumber.max(4e9, x, '123456789.9') // '4000000000'
+
+arr = [12, '13', new BigNumber(14)]
+BigNumber.max(arr) // '14'
+
+
+
+ .min([arg1 [, arg2, ...]]) ⇒ BigNumber
+
+ arg1, arg2, ...: number|string|BigNumber
+ See BigNumber for further parameter details.
+
+ Returns a BigNumber whose value is the minimum of arg1,
+ arg2,... .
+
The argument to this method can also be an array of values.
+The return value is always exact and unrounded.
+x = new BigNumber('3257869345.0378653')
+BigNumber.min(4e9, x, '123456789.9') // '123456789.9'
+
+arr = [2, new BigNumber(-14), '-15.9999', -12]
+BigNumber.min(arr) // '-15.9999'
+
+
+
+ .random([dp]) ⇒ BigNumber
+ dp: number: integer, 0 to 1e+9 inclusive
+ Returns a new BigNumber with a pseudo-random value equal to or greater than 0 and
+ less than 1.
+
+ The return value will have dp decimal places (or less if trailing zeros are
+ produced).
+ If dp is omitted then the number of decimal places will default to the current
+ DECIMAL_PLACES setting.
+
+ Depending on the value of this BigNumber constructor's
+ CRYPTO setting and the support for the
+ crypto object in the host environment, the random digits of the return value are
+ generated by either Math.random (fastest), crypto.getRandomValues
+ (Web Cryptography API in recent browsers) or crypto.randomBytes (Node.js).
+
+ If CRYPTO is true, i.e. one of the
+ crypto methods is to be used, the value of a returned BigNumber should be
+ cryptographically-secure and statistically indistinguishable from a random value.
+
BigNumber.config({ DECIMAL_PLACES: 10 })
+BigNumber.random() // '0.4117936847'
+BigNumber.random(20) // '0.78193327636914089009'
+
+
+
+
+ The library's enumerated rounding modes are stored as properties of the constructor.
+ (They are not referenced internally by the library itself.)
+
+ Rounding modes 0 to 6 (inclusive) are the same as those of Java's
+ BigDecimal class.
+
| Property | +Value | +Description | +
|---|---|---|
| ROUND_UP | +0 | +Rounds away from zero | +
| ROUND_DOWN | +1 | +Rounds towards zero | +
| ROUND_CEIL | +2 | +Rounds towards Infinity |
+
| ROUND_FLOOR | +3 | +Rounds towards -Infinity |
+
| ROUND_HALF_UP | +4 | +
+ Rounds towards nearest neighbour. + If equidistant, rounds away from zero + |
+
| ROUND_HALF_DOWN | +5 | +
+ Rounds towards nearest neighbour. + If equidistant, rounds towards zero + |
+
| ROUND_HALF_EVEN | +6 | +
+ Rounds towards nearest neighbour. + If equidistant, rounds towards even neighbour + |
+
| ROUND_HALF_CEIL | +7 | +
+ Rounds towards nearest neighbour. + If equidistant, rounds towards Infinity
+ |
+
| ROUND_HALF_FLOOR | +8 | +
+ Rounds towards nearest neighbour. + If equidistant, rounds towards -Infinity
+ |
+
+BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_CEIL })
+BigNumber.config({ ROUNDING_MODE: 2 }) // equivalent
+
+
+ The methods inherited by a BigNumber instance from its constructor's prototype object.
+A BigNumber is immutable in the sense that it is not changed by its methods.
+
+ The treatment of ±0, ±Infinity and NaN is
+ consistent with how JavaScript treats these values.
+
+ Many method names have a shorter alias.
+ (Internally, the library always uses the shorter method names.)
+
.abs() ⇒ BigNumber+ Returns a BigNumber whose value is the absolute value, i.e. the magnitude, of the value of + this BigNumber. +
+The return value is always exact and unrounded.
++x = new BigNumber(-0.8) +y = x.absoluteValue() // '0.8' +z = y.abs() // '0.8'+ + + +
.ceil() ⇒ BigNumber
+ Returns a BigNumber whose value is the value of this BigNumber rounded to
+ a whole number in the direction of positive Infinity.
+
+x = new BigNumber(1.3) +x.ceil() // '2' +y = new BigNumber(-1.8) +y.ceil() // '-1'+ + + +
.cmp(n [, base]) ⇒ number
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
| Returns | |
|---|---|
1 |
+ If the value of this BigNumber is greater than the value of n |
+
-1 |
+ If the value of this BigNumber is less than the value of n |
+
0 |
+ If this BigNumber and n have the same value |
+
null |
+ If the value of either this BigNumber or n is NaN |
+
+x = new BigNumber(Infinity)
+y = new BigNumber(5)
+x.comparedTo(y) // 1
+x.comparedTo(x.minus(1)) // 0
+y.cmp(NaN) // null
+y.cmp('110', 2) // -1
+
+
+
+ .dp() ⇒ number
+ Return the number of decimal places of the value of this BigNumber, or null if
+ the value of this BigNumber is ±Infinity or NaN.
+
+x = new BigNumber(123.45)
+x.decimalPlaces() // 2
+y = new BigNumber('9.9e-101')
+y.dp() // 102
+
+
+
+ .div(n [, base]) ⇒ BigNumber
+
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
+ Returns a BigNumber whose value is the value of this BigNumber divided by
+ n, rounded according to the current
+ DECIMAL_PLACES and
+ ROUNDING_MODE configuration.
+
+x = new BigNumber(355) +y = new BigNumber(113) +x.dividedBy(y) // '3.14159292035398230088' +x.div(5) // '71' +x.div(47, 16) // '5'+ + + +
.divToInt(n [, base]) ⇒
+ BigNumber
+
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
+ Return a BigNumber whose value is the integer part of dividing the value of this BigNumber by
+ n.
+
+x = new BigNumber(5)
+y = new BigNumber(3)
+x.dividedToIntegerBy(y) // '1'
+x.divToInt(0.7) // '7'
+x.divToInt('0.f', 16) // '5'
+
+
+
+ .eq(n [, base]) ⇒ boolean
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
+ Returns true if the value of this BigNumber equals the value of n,
+ otherwise returns false.
+ As with JavaScript, NaN does not equal NaN.
+
Note: This method uses the comparedTo method internally.
+0 === 1e-324 // true
+x = new BigNumber(0)
+x.equals('1e-324') // false
+BigNumber(-0).eq(x) // true ( -0 === 0 )
+BigNumber(255).eq('ff', 16) // true
+
+y = new BigNumber(NaN)
+y.equals(NaN) // false
+
+
+
+ .floor() ⇒ BigNumber
+ Returns a BigNumber whose value is the value of this BigNumber rounded to a whole number in
+ the direction of negative Infinity.
+
+x = new BigNumber(1.8) +x.floor() // '1' +y = new BigNumber(-1.3) +y.floor() // '-2'+ + + +
.gt(n [, base]) ⇒ boolean
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
+ Returns true if the value of this BigNumber is greater than the value of
+ n, otherwise returns false.
+
Note: This method uses the comparedTo method internally.
+0.1 > (0.3 - 0.2) // true +x = new BigNumber(0.1) +x.greaterThan(BigNumber(0.3).minus(0.2)) // false +BigNumber(0).gt(x) // false +BigNumber(11, 3).gt(11.1, 2) // true+ + + +
.gte(n [, base]) ⇒ boolean
+
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
+ Returns true if the value of this BigNumber is greater than or equal to the value
+ of n, otherwise returns false.
+
Note: This method uses the comparedTo method internally.
+(0.3 - 0.2) >= 0.1 // false
+x = new BigNumber(0.3).minus(0.2)
+x.greaterThanOrEqualTo(0.1) // true
+BigNumber(1).gte(x) // true
+BigNumber(10, 18).gte('i', 36) // true
+
+
+
+ .isFinite() ⇒ boolean
+ Returns true if the value of this BigNumber is a finite number, otherwise
+ returns false.
+
+ The only possible non-finite values of a BigNumber are NaN, Infinity
+ and -Infinity.
+
+x = new BigNumber(1) +x.isFinite() // true +y = new BigNumber(Infinity) +y.isFinite() // false+
+ Note: The native method isFinite() can be used if
+ n <= Number.MAX_VALUE.
+
.isInt() ⇒ boolean
+ Returns true if the value of this BigNumber is a whole number, otherwise returns
+ false.
+
+x = new BigNumber(1) +x.isInteger() // true +y = new BigNumber(123.456) +y.isInt() // false+ + + +
.isNaN() ⇒ boolean
+ Returns true if the value of this BigNumber is NaN, otherwise
+ returns false.
+
+x = new BigNumber(NaN)
+x.isNaN() // true
+y = new BigNumber('Infinity')
+y.isNaN() // false
+ Note: The native method isNaN() can also be used.
.isNeg() ⇒ boolean
+ Returns true if the value of this BigNumber is negative, otherwise returns
+ false.
+
+x = new BigNumber(-0) +x.isNegative() // true +y = new BigNumber(2) +y.isNeg() // false+
Note: n < 0 can be used if n <= -Number.MIN_VALUE.
.isZero() ⇒ boolean
+ Returns true if the value of this BigNumber is zero or minus zero, otherwise
+ returns false.
+
+x = new BigNumber(-0) +x.isZero() && x.isNeg() // true +y = new BigNumber(Infinity) +y.isZero() // false+
Note: n == 0 can be used if n >= Number.MIN_VALUE.
.lt(n [, base]) ⇒ boolean
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
+ Returns true if the value of this BigNumber is less than the value of
+ n, otherwise returns false.
+
Note: This method uses the comparedTo method internally.
+(0.3 - 0.2) < 0.1 // true +x = new BigNumber(0.3).minus(0.2) +x.lessThan(0.1) // false +BigNumber(0).lt(x) // true +BigNumber(11.1, 2).lt(11, 3) // true+ + + +
.lte(n [, base]) ⇒ boolean
+
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
+ Returns true if the value of this BigNumber is less than or equal to the value of
+ n, otherwise returns false.
+
Note: This method uses the comparedTo method internally.
+0.1 <= (0.3 - 0.2) // false
+x = new BigNumber(0.1)
+x.lessThanOrEqualTo(BigNumber(0.3).minus(0.2)) // true
+BigNumber(-1).lte(x) // true
+BigNumber(10, 18).lte('i', 36) // true
+
+
+
+ .minus(n [, base]) ⇒ BigNumber
+
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
Returns a BigNumber whose value is the value of this BigNumber minus n.
The return value is always exact and unrounded.
++0.3 - 0.1 // 0.19999999999999998 +x = new BigNumber(0.3) +x.minus(0.1) // '0.2' +x.minus(0.6, 20) // '0'+ + + +
.mod(n [, base]) ⇒ BigNumber
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
+ Returns a BigNumber whose value is the value of this BigNumber modulo n, i.e.
+ the integer remainder of dividing this BigNumber by n.
+
+ The value returned, and in particular its sign, is dependent on the value of the
+ MODULO_MODE setting of this BigNumber constructor.
+ If it is 1 (default value), the result will have the same sign as this BigNumber,
+ and it will match that of Javascript's % operator (within the limits of double
+ precision) and BigDecimal's remainder method.
+
The return value is always exact and unrounded.
+
+ See MODULO_MODE for a description of the other
+ modulo modes.
+
+1 % 0.9 // 0.09999999999999998
+x = new BigNumber(1)
+x.modulo(0.9) // '0.1'
+y = new BigNumber(33)
+y.mod('a', 33) // '3'
+
+
+
+ .neg() ⇒ BigNumber
+ Returns a BigNumber whose value is the value of this BigNumber negated, i.e. multiplied by
+ -1.
+
+x = new BigNumber(1.8) +x.negated() // '-1.8' +y = new BigNumber(-1.3) +y.neg() // '1.3'+ + + +
.plus(n [, base]) ⇒ BigNumber
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
Returns a BigNumber whose value is the value of this BigNumber plus n.
The return value is always exact and unrounded.
+
+0.1 + 0.2 // 0.30000000000000004
+x = new BigNumber(0.1)
+y = x.plus(0.2) // '0.3'
+BigNumber(0.7).plus(x).plus(y) // '1'
+x.plus('0.1', 8) // '0.225'
+
+
+
+ .sd([z]) ⇒ number
+ z: boolean|number: true, false, 0
+ or 1
+
Returns the number of significant digits of the value of this BigNumber.
+
+ If z is true or 1 then any trailing zeros of the
+ integer part of a number are counted as significant digits, otherwise they are not.
+
+x = new BigNumber(1.234) +x.precision() // 4 +y = new BigNumber(987000) +y.sd() // 3 +y.sd(true) // 6+ + + +
.round([dp [, rm]]) ⇒ BigNumber
+ dp: number: integer, 0 to 1e+9 inclusive
+ rm: number: integer, 0 to 8 inclusive
+
+ Returns a BigNumber whose value is the value of this BigNumber rounded by rounding mode
+ rm to a maximum of dp decimal places.
+
+ if dp is omitted, or is null or undefined, the
+ return value is n rounded to a whole number.
+ if rm is omitted, or is null or undefined,
+ ROUNDING_MODE is used.
+
+ See Errors for the treatment of other non-integer or out of range
+ dp or rm values.
+
+x = 1234.56 +Math.round(x) // 1235 + +y = new BigNumber(x) +y.round() // '1235' +y.round(1) // '1234.6' +y.round(2) // '1234.56' +y.round(10) // '1234.56' +y.round(0, 1) // '1234' +y.round(0, 6) // '1235' +y.round(1, 1) // '1234.5' +y.round(1, BigNumber.ROUND_HALF_EVEN) // '1234.6' +y // '1234.56'+ + + +
.shift(n) ⇒ BigNumber
+ n: number: integer,
+ -9007199254740991 to 9007199254740991 inclusive
+
+ Returns a BigNumber whose value is the value of this BigNumber shifted n places.
+
+ The shift is of the decimal point, i.e. of powers of ten, and is to the left if n
+ is negative or to the right if n is positive.
+
The return value is always exact and unrounded.
++x = new BigNumber(1.23) +x.shift(3) // '1230' +x.shift(-3) // '0.00123'+ + + +
.sqrt() ⇒ BigNumber
+ Returns a BigNumber whose value is the square root of the value of this BigNumber,
+ rounded according to the current
+ DECIMAL_PLACES and
+ ROUNDING_MODE configuration.
+
+ The return value will be correctly rounded, i.e. rounded as if the result was first calculated + to an infinite number of correct digits before rounding. +
++x = new BigNumber(16) +x.squareRoot() // '4' +y = new BigNumber(3) +y.sqrt() // '1.73205080756887729353'+ + + +
.times(n [, base]) ⇒ BigNumber
+ n: number|string|BigNumber
+ base: number
+ See BigNumber for further parameter details.
+
Returns a BigNumber whose value is the value of this BigNumber times n.
The return value is always exact and unrounded.
+
+0.6 * 3 // 1.7999999999999998
+x = new BigNumber(0.6)
+y = x.times(3) // '1.8'
+BigNumber('7e+500').times(y) // '1.26e+501'
+x.times('-a', 16) // '-6'
+
+
+
+ .toDigits([sd [, rm]]) ⇒ BigNumber
+
+ sd: number: integer, 1 to 1e+9 inclusive.
+ rm: number: integer, 0 to 8 inclusive.
+
+ Returns a BigNumber whose value is the value of this BigNumber rounded to sd
+ significant digits using rounding mode rm.
+
+ If sd is omitted or is null or undefined, the return
+ value will not be rounded.
+ If rm is omitted or is null or undefined,
+ ROUNDING_MODE will be used.
+
+ See Errors for the treatment of other non-integer or out of range
+ sd or rm values.
+
+BigNumber.config({ precision: 5, rounding: 4 })
+x = new BigNumber(9876.54321)
+
+x.toDigits() // '9876.5'
+x.toDigits(6) // '9876.54'
+x.toDigits(6, BigNumber.ROUND_UP) // '9876.55'
+x.toDigits(2) // '9900'
+x.toDigits(2, 1) // '9800'
+x // '9876.54321'
+
+
+
+ .toExponential([dp [, rm]]) ⇒ string
+
+ dp: number: integer, 0 to 1e+9 inclusive
+ rm: number: integer, 0 to 8 inclusive
+
+ Returns a string representing the value of this BigNumber in exponential notation rounded
+ using rounding mode rm to dp decimal places, i.e with one digit
+ before the decimal point and dp digits after it.
+
+ If the value of this BigNumber in exponential notation has fewer than dp fraction
+ digits, the return value will be appended with zeros accordingly.
+
+ If dp is omitted, or is null or undefined, the number
+ of digits after the decimal point defaults to the minimum number of digits necessary to
+ represent the value exactly.
+ If rm is omitted or is null or undefined,
+ ROUNDING_MODE is used.
+
+ See Errors for the treatment of other non-integer or out of range
+ dp or rm values.
+
+x = 45.6 +y = new BigNumber(x) +x.toExponential() // '4.56e+1' +y.toExponential() // '4.56e+1' +x.toExponential(0) // '5e+1' +y.toExponential(0) // '5e+1' +x.toExponential(1) // '4.6e+1' +y.toExponential(1) // '4.6e+1' +y.toExponential(1, 1) // '4.5e+1' (ROUND_DOWN) +x.toExponential(3) // '4.560e+1' +y.toExponential(3) // '4.560e+1'+ + + +
.toFixed([dp [, rm]]) ⇒ string
+
+ dp: number: integer, 0 to 1e+9 inclusive
+ rm: number: integer, 0 to 8 inclusive
+
+ Returns a string representing the value of this BigNumber in normal (fixed-point) notation
+ rounded to dp decimal places using rounding mode rm.
+
+ If the value of this BigNumber in normal notation has fewer than dp fraction
+ digits, the return value will be appended with zeros accordingly.
+
+ Unlike Number.prototype.toFixed, which returns exponential notation if a number
+ is greater or equal to 1021, this method will always return normal
+ notation.
+
+ If dp is omitted or is null or undefined, the return
+ value will be unrounded and in normal notation. This is also unlike
+ Number.prototype.toFixed, which returns the value to zero decimal places.
+ It is useful when fixed-point notation is required and the current
+ EXPONENTIAL_AT setting causes
+ toString to return exponential notation.
+ If rm is omitted or is null or undefined,
+ ROUNDING_MODE is used.
+
+ See Errors for the treatment of other non-integer or out of range
+ dp or rm values.
+
+x = 3.456 +y = new BigNumber(x) +x.toFixed() // '3' +y.toFixed() // '3.456' +y.toFixed(0) // '3' +x.toFixed(2) // '3.46' +y.toFixed(2) // '3.46' +y.toFixed(2, 1) // '3.45' (ROUND_DOWN) +x.toFixed(5) // '3.45600' +y.toFixed(5) // '3.45600'+ + + +
.toFormat([dp [, rm]]) ⇒ string
+
+ dp: number: integer, 0 to 1e+9 inclusive
+ rm: number: integer, 0 to 8 inclusive
+
+
+ Returns a string representing the value of this BigNumber in normal (fixed-point) notation
+ rounded to dp decimal places using rounding mode rm, and formatted
+ according to the properties of the FORMAT object.
+
+ See the examples below for the properties of the
+ FORMAT object, their types and their usage.
+
+ If dp is omitted or is null or undefined, then the
+ return value is not rounded to a fixed number of decimal places.
+ If rm is omitted or is null or undefined,
+ ROUNDING_MODE is used.
+
+ See Errors for the treatment of other non-integer or out of range
+ dp or rm values.
+
+format = {
+ decimalSeparator: '.',
+ groupSeparator: ',',
+ groupSize: 3,
+ secondaryGroupSize: 0,
+ fractionGroupSeparator: ' ',
+ fractionGroupSize: 0
+}
+BigNumber.config({ FORMAT: format })
+
+x = new BigNumber('123456789.123456789')
+x.toFormat() // '123,456,789.123456789'
+x.toFormat(1) // '123,456,789.1'
+
+// If a reference to the object assigned to FORMAT has been retained,
+// the format properties can be changed directly
+format.groupSeparator = ' '
+format.fractionGroupSize = 5
+x.toFormat() // '123 456 789.12345 6789'
+
+BigNumber.config({
+ FORMAT: {
+ decimalSeparator: ',',
+ groupSeparator: '.',
+ groupSize: 3,
+ secondaryGroupSize: 2
+ }
+})
+
+x.toFormat(6) // '12.34.56.789,123'
+
+
+
+ .toFraction([max]) ⇒ [string, string]
+
+ max: number|string|BigNumber: integer >= 1 and <
+ Infinity
+
+ Returns a string array representing the value of this BigNumber as a simple fraction with an
+ integer numerator and an integer denominator. The denominator will be a positive non-zero
+ value less than or equal to max.
+
+ If a maximum denominator, max, is not specified, or is null or
+ undefined, the denominator will be the lowest value necessary to represent the
+ number exactly.
+
+ See Errors for the treatment of other non-integer or out of range
+ max values.
+
+x = new BigNumber(1.75)
+x.toFraction() // '7, 4'
+
+pi = new BigNumber('3.14159265358')
+pi.toFraction() // '157079632679,50000000000'
+pi.toFraction(100000) // '312689, 99532'
+pi.toFraction(10000) // '355, 113'
+pi.toFraction(100) // '311, 99'
+pi.toFraction(10) // '22, 7'
+pi.toFraction(1) // '3, 1'
+
+
+
+ .toJSON() ⇒ stringAs valueOf.
+x = new BigNumber('177.7e+457')
+y = new BigNumber(235.4325)
+z = new BigNumber('0.0098074')
+
+// Serialize an array of three BigNumbers
+str = JSON.stringify( [x, y, z] )
+// "["1.777e+459","235.4325","0.0098074"]"
+
+// Return an array of three BigNumbers
+JSON.parse(str, function (key, val) {
+ return key === '' ? val : new BigNumber(val)
+})
+
+
+
+ .toNumber() ⇒ numberReturns the value of this BigNumber as a JavaScript number primitive.
++ Type coercion with, for example, the unary plus operator will also work, except that a + BigNumber with the value minus zero will be converted to positive zero. +
+
+x = new BigNumber(456.789)
+x.toNumber() // 456.789
++x // 456.789
+
+y = new BigNumber('45987349857634085409857349856430985')
+y.toNumber() // 4.598734985763409e+34
+
+z = new BigNumber(-0)
+1 / +z // Infinity
+1 / z.toNumber() // -Infinity
+
+
+
+ .pow(n [, m]) ⇒ BigNumber
+ n: number: integer,
+ -9007199254740991 to 9007199254740991 inclusive
+ m: number|string|BigNumber
+
+ Returns a BigNumber whose value is the value of this BigNumber raised to the power
+ n, and optionally modulo a modulus m.
+
+ If n is negative the result is rounded according to the current
+ DECIMAL_PLACES and
+ ROUNDING_MODE configuration.
+
+ If n is not an integer or is out of range:
+
+ If ERRORS is true a BigNumber Error is thrown,
+ else if n is greater than 9007199254740991, it is interpreted as
+ Infinity;
+ else if n is less than -9007199254740991, it is interpreted as
+ -Infinity;
+ else if n is otherwise a number, it is truncated to an integer;
+ else it is interpreted as NaN.
+
+ As the number of digits of the result of the power operation can grow so large so quickly,
+ e.g. 123.45610000 has over 50000 digits, the number of significant
+ digits calculated is limited to the value of the
+ POW_PRECISION setting (unless a modulus
+ m is specified).
+
+ By default POW_PRECISION is set to 0.
+ This means that an unlimited number of significant digits will be calculated, and that the
+ method's performance will decrease dramatically for larger exponents.
+
+ Negative exponents will be calculated to the number of decimal places specified by
+ DECIMAL_PLACES (but not to more than
+ POW_PRECISION significant digits).
+
+ If m is specified and the value of m, n and this
+ BigNumber are positive integers, then a fast modular exponentiation algorithm is used,
+ otherwise if any of the values is not a positive integer the operation will simply be
+ performed as x.toPower(n).modulo(m) with a
+ POW_PRECISION of 0.
+
+Math.pow(0.7, 2) // 0.48999999999999994 +x = new BigNumber(0.7) +x.toPower(2) // '0.49' +BigNumber(3).pow(-2) // '0.11111111111111111111'+ + + +
.toPrecision([sd [, rm]]) ⇒ string
+
+ sd: number: integer, 1 to 1e+9 inclusive
+ rm: number: integer, 0 to 8 inclusive
+
+ Returns a string representing the value of this BigNumber rounded to sd
+ significant digits using rounding mode rm.
+
+ If sd is less than the number of digits necessary to represent the integer part
+ of the value in normal (fixed-point) notation, then exponential notation is used.
+
+ If sd is omitted, or is null or undefined, then the
+ return value is the same as n.toString().
+ If rm is omitted or is null or undefined,
+ ROUNDING_MODE is used.
+
+ See Errors for the treatment of other non-integer or out of range
+ sd or rm values.
+
+x = 45.6 +y = new BigNumber(x) +x.toPrecision() // '45.6' +y.toPrecision() // '45.6' +x.toPrecision(1) // '5e+1' +y.toPrecision(1) // '5e+1' +y.toPrecision(2, 0) // '4.6e+1' (ROUND_UP) +y.toPrecision(2, 1) // '4.5e+1' (ROUND_DOWN) +x.toPrecision(5) // '45.600' +y.toPrecision(5) // '45.600'+ + + +
.toString([base]) ⇒ stringbase: number: integer, 2 to 64 inclusive
+ Returns a string representing the value of this BigNumber in the specified base, or base
+ 10 if base is omitted or is null or
+ undefined.
+
+ For bases above 10, values from 10 to 35 are
+ represented by a-z (as with Number.prototype.toString),
+ 36 to 61 by A-Z, and 62 and
+ 63 by $ and _ respectively.
+
+ If a base is specified the value is rounded according to the current
+ DECIMAL_PLACES
+ and ROUNDING_MODE configuration.
+
+ If a base is not specified, and this BigNumber has a positive
+ exponent that is equal to or greater than the positive component of the
+ current EXPONENTIAL_AT setting,
+ or a negative exponent equal to or less than the negative component of the
+ setting, then exponential notation is returned.
+
If base is null or undefined it is ignored.
+ See Errors for the treatment of other non-integer or out of range
+ base values.
+
+x = new BigNumber(750000)
+x.toString() // '750000'
+BigNumber.config({ EXPONENTIAL_AT: 5 })
+x.toString() // '7.5e+5'
+
+y = new BigNumber(362.875)
+y.toString(2) // '101101010.111'
+y.toString(9) // '442.77777777777777777778'
+y.toString(32) // 'ba.s'
+
+BigNumber.config({ DECIMAL_PLACES: 4 });
+z = new BigNumber('1.23456789')
+z.toString() // '1.23456789'
+z.toString(10) // '1.2346'
+
+
+
+ .trunc() ⇒ BigNumber+ Returns a BigNumber whose value is the value of this BigNumber truncated to a whole number. +
++x = new BigNumber(123.456) +x.truncated() // '123' +y = new BigNumber(-12.3) +y.trunc() // '-12'+ + + +
.valueOf() ⇒ string
+ As toString, but does not accept a base argument and includes the minus sign
+ for negative zero.
+
+x = new BigNumber('-0')
+x.toString() // '0'
+x.valueOf() // '-0'
+y = new BigNumber('1.777e+457')
+y.valueOf() // '1.777e+457'
+
+
+
+ The properties of a BigNumber instance:
+| Property | +Description | +Type | +Value | +
|---|---|---|---|
| c | +coefficient* | +number[] |
+ Array of base 1e14 numbers |
+
| e | +exponent | +number | +Integer, -1000000000 to 1000000000 inclusive |
+
| s | +sign | +number | +-1 or 1 |
+
| isBigNumber | +type identifier | +boolean | +true |
+
*significand
+
+ The value of any of the c, e and s properties may also
+ be null.
+
+ From v2.0.0 of this library, the value of the coefficient of a BigNumber is stored in a
+ normalised base 100000000000000 floating point format, as opposed to the base
+ 10 format used in v1.x.x
+
+ This change means the properties of a BigNumber are now best considered to be read-only. + Previously it was acceptable to change the exponent of a BigNumber by writing to its exponent + property directly, but this is no longer recommended as the number of digits in the first + element of the coefficient array is dependent on the exponent, so the coefficient would also + need to be altered. +
++ Note that, as with JavaScript numbers, the original exponent and fractional trailing zeros are + not necessarily preserved. +
+x = new BigNumber(0.123) // '0.123'
+x.toExponential() // '1.23e-1'
+x.c // '1,2,3'
+x.e // -1
+x.s // 1
+
+y = new Number(-123.4567000e+2) // '-12345.67'
+y.toExponential() // '-1.234567e+4'
+z = new BigNumber('-123.4567000e+2') // '-12345.67'
+z.toExponential() // '-1.234567e+4'
+z.c // '1,2,3,4,5,6,7'
+z.e // 4
+z.s // -1
+ Checking if a value is a BigNumber instance:
++x = new BigNumber(3) +x instanceof BigNumber // true +x.isBigNumber // true + +BN = BigNumber.another(); + +y = new BN(3) +y instanceof BigNumber // false +y.isBigNumber // true+ + + + +
+ The table below shows how ±0, NaN and
+ ±Infinity are stored.
+
| + | c | +e | +s | +
|---|---|---|---|
| ±0 | +[0] |
+ 0 |
+ ±1 |
+
| NaN | +null |
+ null |
+ null |
+
| ±Infinity | +null |
+ null |
+ ±1 |
+
+x = new Number(-0) // 0 +1 / x == -Infinity // true + +y = new BigNumber(-0) // '0' +y.c // '0' ( [0].toString() ) +y.e // 0 +y.s // -1+ + + +
+ The errors that are thrown are generic Error objects with name
+ BigNumber Error.
+
+ The table below shows the errors that may be thrown if ERRORS is
+ true, and the action taken if ERRORS is false.
+
| Method(s) | +ERRORS: true Throw BigNumber Error |
+ ERRORS: false Action on invalid argument |
+
|---|---|---|
+
+ BigNumber |
+ number type has more than 15 significant digits |
+ Accept. | +
| not a base... number | +Substitute NaN. |
+ |
| base not an integer | +Truncate to integer. Ignore if not a number. |
+ |
| base out of range | +Ignore. | +|
| not a number* | +Substitute NaN. |
+ |
another |
+ not an object | +Ignore. | +
config |
+ DECIMAL_PLACES not an integer |
+ Truncate to integer. Ignore if not a number. |
+
DECIMAL_PLACES out of range |
+ Ignore. | +|
ROUNDING_MODE not an integer |
+ Truncate to integer. Ignore if not a number. |
+ |
ROUNDING_MODE out of range |
+ Ignore. | +|
EXPONENTIAL_AT not an integeror not [integer, integer] |
+ Truncate to integer(s). Ignore if not number(s). |
+ |
EXPONENTIAL_AT out of rangeor not [negative, positive] |
+ Ignore. | +|
RANGE not an integeror not [integer, integer] |
+ Truncate to integer(s). Ignore if not number(s). |
+ |
RANGE cannot be zero |
+ Ignore. | +|
RANGE out of rangeor not [negative, positive] |
+ Ignore. | +|
ERRORS not a booleanor binary digit |
+ Ignore. | +|
CRYPTO not a booleanor binary digit |
+ Ignore. | +|
CRYPTO crypto unavailable |
+ Ignore. | +|
MODULO_MODE not an integer |
+ Truncate to integer. Ignore if not a number. |
+ |
MODULO_MODE out of range |
+ Ignore. | +|
POW_PRECISION not an integer |
+ Truncate to integer. Ignore if not a number. |
+ |
POW_PRECISION out of range |
+ Ignore. | +|
FORMAT not an object |
+ Ignore. | +|
precision |
+ argument not a boolean or binary digit |
+ Ignore. | +
round |
+ decimal places not an integer | +Truncate to integer. Ignore if not a number. |
+
| decimal places out of range | +Ignore. | +|
| rounding mode not an integer | +Truncate to integer. Ignore if not a number. |
+ |
| rounding mode out of range | +Ignore. | +|
shift |
+ argument not an integer | +Truncate to integer. Ignore if not a number. |
+
| argument out of range | +Substitute ±Infinity.
+ | |
+ toExponential+ toFixed+ toFormat
+ |
+ decimal places not an integer | +Truncate to integer. Ignore if not a number. |
+
| decimal places out of range | +Ignore. | +|
| rounding mode not an integer | +Truncate to integer. Ignore if not a number. |
+ |
| rounding mode out of range | +Ignore. | +|
toFraction |
+ max denominator not an integer | +Truncate to integer. Ignore if not a number. |
+
| max denominator out of range | +Ignore. | +|
+ toDigits+ toPrecision
+ |
+ precision not an integer | +Truncate to integer. Ignore if not a number. |
+
| precision out of range | +Ignore. | +|
| rounding mode not an integer | +Truncate to integer. Ignore if not a number. |
+ |
| rounding mode out of range | +Ignore. | +|
toPower |
+ exponent not an integer | +Truncate to integer. Substitute NaN if not a number. |
+
| exponent out of range | +Substitute ±Infinity.
+ |
+ |
toString |
+ base not an integer | +Truncate to integer. Ignore if not a number. |
+
| base out of range | +Ignore. | +
*No error is thrown if the value is NaN or 'NaN'.
+ The message of a BigNumber Error will also contain the name of the method from which + the error originated. +
+To determine if an exception is a BigNumber Error:
+
+try {
+ // ...
+} catch (e) {
+ if ( e instanceof Error && e.name == 'BigNumber Error' ) {
+ // ...
+ }
+}
+
+
+
+ + Some arbitrary-precision libraries retain trailing fractional zeros as they can indicate the + precision of a value. This can be useful but the results of arithmetic operations can be + misleading. +
+
+x = new BigDecimal("1.0")
+y = new BigDecimal("1.1000")
+z = x.add(y) // 2.1000
+
+x = new BigDecimal("1.20")
+y = new BigDecimal("3.45000")
+z = x.multiply(y) // 4.1400000
+ + To specify the precision of a value is to specify that the value lies + within a certain range. +
+
+ In the first example, x has a value of 1.0. The trailing zero shows
+ the precision of the value, implying that it is in the range 0.95 to
+ 1.05. Similarly, the precision indicated by the trailing zeros of y
+ indicates that the value is in the range 1.09995 to 1.10005.
+
+ If we add the two lowest values in the ranges we have, 0.95 + 1.09995 = 2.04995,
+ and if we add the two highest values we have, 1.05 + 1.10005 = 2.15005, so the
+ range of the result of the addition implied by the precision of its operands is
+ 2.04995 to 2.15005.
+
+ The result given by BigDecimal of 2.1000 however, indicates that the value is in
+ the range 2.09995 to 2.10005 and therefore the precision implied by
+ its trailing zeros may be misleading.
+
+ In the second example, the true range is 4.122744 to 4.157256 yet
+ the BigDecimal answer of 4.1400000 indicates a range of 4.13999995
+ to 4.14000005. Again, the precision implied by the trailing zeros may be
+ misleading.
+
+ This library, like binary floating point and most calculators, does not retain trailing
+ fractional zeros. Instead, the toExponential, toFixed and
+ toPrecision methods enable trailing zeros to be added if and when required.
+
+ * The settings, which are not base-dependent, comprise: + *
digits:
+ * the number of digits (precision) to be used for an operation
+ * form:
+ * the form of any exponent that results from the operation
+ * lostDigits:
+ * whether checking for lost digits is enabled
+ * roundingMode:
+ * the algorithm to be used for rounding.
+ *
+ * When provided, a MathContext object supplies the
+ * settings for an operation directly.
+ *
+ * When MathContext.DEFAULT is provided for a
+ * MathContext parameter then the default settings are used
+ * (9, SCIENTIFIC, false, ROUND_HALF_UP).
+ *
+ * In the BigDecimal class, all methods which accept a
+ * MathContext object defaults) also have a version of the
+ * method which does not accept a MathContext parameter. These versions
+ * carry out unlimited precision fixed point arithmetic (as though the
+ * settings were (0, PLAIN, false, ROUND_HALF_UP).
+ *
+ * The instance variables are shared with default access (so they are
+ * directly accessible to the BigDecimal class), but must
+ * never be changed.
+ *
+ * The rounding mode constants have the same names and values as the
+ * constants of the same name in java.math.BigDecimal, to
+ * maintain compatibility with earlier versions of
+ * BigDecimal.
+ *
+ * @see BigDecimal
+ * @author Mike Cowlishaw
+ * @stable ICU 2.0
+ */
+
+//--public final class MathContext implements java.io.Serializable{
+ //--private static final java.lang.String $0="MathContext.nrx";
+
+ //-- methods
+ MathContext.prototype.getDigits = getDigits;
+ MathContext.prototype.getForm = getForm;
+ MathContext.prototype.getLostDigits = getLostDigits;
+ MathContext.prototype.getRoundingMode = getRoundingMode;
+ MathContext.prototype.toString = toString;
+ MathContext.prototype.isValidRound = isValidRound;
+
+
+ /* ----- Properties ----- */
+ /* properties public constant */
+ /**
+ * Plain (fixed point) notation, without any exponent.
+ * Used as a setting to control the form of the result of a
+ * BigDecimal operation.
+ * A zero result in plain form may have a decimal part of one or
+ * more zeros.
+ *
+ * @see #ENGINEERING
+ * @see #SCIENTIFIC
+ * @stable ICU 2.0
+ */
+ //--public static final int PLAIN=0; // [no exponent]
+ MathContext.PLAIN = MathContext.prototype.PLAIN = 0; // [no exponent]
+
+ /**
+ * Standard floating point notation (with scientific exponential
+ * format, where there is one digit before any decimal point).
+ * Used as a setting to control the form of the result of a
+ * BigDecimal operation.
+ * A zero result in plain form may have a decimal part of one or
+ * more zeros.
+ *
+ * @see #ENGINEERING
+ * @see #PLAIN
+ * @stable ICU 2.0
+ */
+ //--public static final int SCIENTIFIC=1; // 1 digit before .
+ MathContext.SCIENTIFIC = MathContext.prototype.SCIENTIFIC = 1; // 1 digit before .
+
+ /**
+ * Standard floating point notation (with engineering exponential
+ * format, where the power of ten is a multiple of 3).
+ * Used as a setting to control the form of the result of a
+ * BigDecimal operation.
+ * A zero result in plain form may have a decimal part of one or
+ * more zeros.
+ *
+ * @see #PLAIN
+ * @see #SCIENTIFIC
+ * @stable ICU 2.0
+ */
+ //--public static final int ENGINEERING=2; // 1-3 digits before .
+ MathContext.ENGINEERING = MathContext.prototype.ENGINEERING = 2; // 1-3 digits before .
+
+ // The rounding modes match the original BigDecimal class values
+ /**
+ * Rounding mode to round to a more positive number.
+ * Used as a setting to control the rounding mode used during a
+ * BigDecimal operation.
+ *
+ * If any of the discarded digits are non-zero then the result
+ * should be rounded towards the next more positive digit.
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_CEILING=2;
+ MathContext.ROUND_CEILING = MathContext.prototype.ROUND_CEILING = 2;
+
+ /**
+ * Rounding mode to round towards zero.
+ * Used as a setting to control the rounding mode used during a
+ * BigDecimal operation.
+ *
+ * All discarded digits are ignored (truncated). The result is
+ * neither incremented nor decremented.
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_DOWN=1;
+ MathContext.ROUND_DOWN = MathContext.prototype.ROUND_DOWN = 1;
+
+ /**
+ * Rounding mode to round to a more negative number.
+ * Used as a setting to control the rounding mode used during a
+ * BigDecimal operation.
+ *
+ * If any of the discarded digits are non-zero then the result
+ * should be rounded towards the next more negative digit.
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_FLOOR=3;
+ MathContext.ROUND_FLOOR = MathContext.prototype.ROUND_FLOOR = 3;
+
+ /**
+ * Rounding mode to round to nearest neighbor, where an equidistant
+ * value is rounded down.
+ * Used as a setting to control the rounding mode used during a
+ * BigDecimal operation.
+ *
+ * If the discarded digits represent greater than half (0.5 times)
+ * the value of a one in the next position then the result should be
+ * rounded up (away from zero). Otherwise the discarded digits are
+ * ignored.
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_HALF_DOWN=5;
+ MathContext.ROUND_HALF_DOWN = MathContext.prototype.ROUND_HALF_DOWN = 5;
+
+ /**
+ * Rounding mode to round to nearest neighbor, where an equidistant
+ * value is rounded to the nearest even neighbor.
+ * Used as a setting to control the rounding mode used during a
+ * BigDecimal operation.
+ *
+ * If the discarded digits represent greater than half (0.5 times) + * the value of a one in the next position then the result should be + * rounded up (away from zero). If they represent less than half, + * then the result should be rounded down. + *
+ * Otherwise (they represent exactly half) the result is rounded
+ * down if its rightmost digit is even, or rounded up if its
+ * rightmost digit is odd (to make an even digit).
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_HALF_EVEN=6;
+ MathContext.ROUND_HALF_EVEN = MathContext.prototype.ROUND_HALF_EVEN = 6;
+
+ /**
+ * Rounding mode to round to nearest neighbor, where an equidistant
+ * value is rounded up.
+ * Used as a setting to control the rounding mode used during a
+ * BigDecimal operation.
+ *
+ * If the discarded digits represent greater than or equal to half
+ * (0.5 times) the value of a one in the next position then the result
+ * should be rounded up (away from zero). Otherwise the discarded
+ * digits are ignored.
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_HALF_UP=4;
+ MathContext.ROUND_HALF_UP = MathContext.prototype.ROUND_HALF_UP = 4;
+
+ /**
+ * Rounding mode to assert that no rounding is necessary.
+ * Used as a setting to control the rounding mode used during a
+ * BigDecimal operation.
+ *
+ * Rounding (potential loss of information) is not permitted.
+ * If any of the discarded digits are non-zero then an
+ * ArithmeticException should be thrown.
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_UNNECESSARY=7;
+ MathContext.ROUND_UNNECESSARY = MathContext.prototype.ROUND_UNNECESSARY = 7;
+
+ /**
+ * Rounding mode to round away from zero.
+ * Used as a setting to control the rounding mode used during a
+ * BigDecimal operation.
+ *
+ * If any of the discarded digits are non-zero then the result will + * be rounded up (away from zero). + * @stable ICU 2.0 + */ + //--public static final int ROUND_UP=0; + MathContext.ROUND_UP = MathContext.prototype.ROUND_UP = 0; + + + /* properties shared */ + /** + * The number of digits (precision) to be used for an operation. + * A value of 0 indicates that unlimited precision (as many digits + * as are required) will be used. + *
+ * The {@link BigDecimal} operator methods use this value to + * determine the precision of results. + * Note that leading zeros (in the integer part of a number) are + * never significant. + *
+ * digits will always be non-negative.
+ *
+ * @serial
+ */
+ //--int digits;
+
+ /**
+ * The form of results from an operation.
+ *
+ * The {@link BigDecimal} operator methods use this value to
+ * determine the form of results, in particular whether and how
+ * exponential notation should be used.
+ *
+ * @see #ENGINEERING
+ * @see #PLAIN
+ * @see #SCIENTIFIC
+ * @serial
+ */
+ //--int form; // values for this must fit in a byte
+
+ /**
+ * Controls whether lost digits checking is enabled for an
+ * operation.
+ * Set to true to enable checking, or
+ * to false to disable checking.
+ *
+ * When enabled, the {@link BigDecimal} operator methods check
+ * the precision of their operand or operands, and throw an
+ * ArithmeticException if an operand is more precise
+ * than the digits setting (that is, digits would be lost).
+ * When disabled, operands are rounded to the specified digits.
+ *
+ * @serial
+ */
+ //--boolean lostDigits;
+
+ /**
+ * The rounding algorithm to be used for an operation.
+ *
+ * The {@link BigDecimal} operator methods use this value to
+ * determine the algorithm to be used when non-zero digits have to
+ * be discarded in order to reduce the precision of a result.
+ * The value must be one of the public constants whose name starts
+ * with
+ * For example:
+ *
+ * Additional words may be appended to the result of
+ *
+ * As the numbers are decimal, there is an exact correspondence between
+ * an instance of a
+ * In the descriptions of constructors and methods in this documentation,
+ * the value of a
+ * The floating point arithmetic provided by this class is defined by
+ * the ANSI X3.274-1996 standard, and is also documented at
+ *
+ * Operations on
+ * Each operator method also has a version provided which does
+ * not take a
+ * For monadic operators, only the optional
+ * For dyadic operators, a
+ * For example, adding two
+ * (where
+ * When a where the value on the right of the results in results in
+ * The form of the exponential notation (scientific or engineering) is
+ * determined by the
+ * The names of methods in this class follow the conventions established
+ * by
+ * This property is an optimization; it allows us to defer number
+ * layout until it is actually needed as a string, hence avoiding
+ * unnecessary formatting.
+ *
+ * @serial
+ */
+ //--private byte form=(byte)com.ibm.icu.math.MathContext.PLAIN; // assumed PLAIN
+ // We only need two bits for this, at present, but use a byte
+ // [again, to allow for smooth future extension]
+
+ /**
+ * The value of the mantissa.
+ *
+ * Once constructed, this may become shared between several BigDecimal
+ * objects, so must not be altered.
+ *
+ * For efficiency (speed), this is a byte array, with each byte
+ * taking a value of 0 -> 9.
+ *
+ * If the first byte is 0 then the value of the number is zero (and
+ * mant.length=1, except when constructed from a plain number, for
+ * example, 0.000).
+ *
+ * @serial
+ */
+ //--private byte mant[]; // assumed null
+
+ /**
+ * The exponent.
+ *
+ * For fixed point arithmetic, scale is
+ * Constructs a
+ * (Note: this constructor is provided only in the
+ *
+ * Constructs a
+ * The
+ * Constructs a
+ * The
+ * Constructs a
+ * Using this constructor is faster than using the
+ *
+ * Constructs a
+ * Using this constructor is faster than using the
+ *
+ * Constructs a
+ * Note that this constructor it an exact conversion; it does not give
+ * the same result as converting
+ * Constructs a
+ * Constructs a
+ * Constructs a
+ * In summary, numbers in
+ * Some valid strings from which a
+ * (Exponential notation means that the number includes an optional
+ * sign and a power of ten following an 'E' that
+ * indicates how the decimal point will be shifted. Thus the
+ *
+ * The
+ * Any digits in the parameter must be decimal; that is,
+ *
+ * The same as {@link #abs(MathContext)}, where the context is
+ *
+ * The length of the decimal part (the scale) of the result will
+ * be
+ * If the current object is zero or positive, then the same result as
+ * invoking the {@link #plus(MathContext)} method with the same
+ * parameter is returned.
+ * Otherwise, the same result as invoking the
+ * {@link #negate(MathContext)} method with the same parameter is
+ * returned.
+ *
+ * @param set The
+ * The same as {@link #add(BigDecimal, MathContext)},
+ * where the
+ * The length of the decimal part (the scale) of the result will be
+ * the maximum of the scales of the two operands.
+ *
+ * @param rhs The
+ * Implements the addition (
+ * The same as {@link #compareTo(BigDecimal, MathContext)},
+ * where the
+ * Implements numeric comparison,
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns a result of type
+ * The result will be:
+ *
+ * A {@link #compareTo(Object)} method is also provided.
+ *
+ * @param rhs The
+ * The same as {@link #divide(BigDecimal, int)},
+ * where the
+ * The same as {@link #divide(BigDecimal, int, int)},
+ * where the
+ * The length of the decimal part (the scale) of the result will
+ * therefore be the same as the scale of the current object, if the
+ * latter were formatted without exponential notation.
+ *
+ * @param rhs The
+ * The same as {@link #divide(BigDecimal, MathContext)},
+ * where the
+ * The length of the decimal part (the scale) of the result will be
+ * the same as the scale of the current object, if the latter were
+ * formatted without exponential notation.
+ *
+ * @param rhs The
+ * Implements the division (
+ * The same as {@link #divideInteger(BigDecimal, MathContext)},
+ * where the
+ * Implements the integer division operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a
+ * The same as {@link #max(BigDecimal, MathContext)},
+ * where the
+ * Returns the larger of the current object and the first parameter.
+ *
+ * If calling the {@link #compareTo(BigDecimal, MathContext)} method
+ * with the same parameters would return
+ * The same as {@link #min(BigDecimal, MathContext)},
+ * where the
+ * Returns the smaller of the current object and the first parameter.
+ *
+ * If calling the {@link #compareTo(BigDecimal, MathContext)} method
+ * with the same parameters would return
+ * The same as {@link #add(BigDecimal, MathContext)},
+ * where the
+ * The length of the decimal part (the scale) of the result will be
+ * the sum of the scales of the operands, if they were formatted
+ * without exponential notation.
+ *
+ * @param rhs The
+ * Implements the multiplication (
+ * The same as {@link #negate(MathContext)}, where the context is
+ *
+ * The length of the decimal part (the scale) of the result will be
+ * be
+ * Implements the negation (Prefix
+ * The same as {@link #plus(MathContext)}, where the context is
+ *
+ * The length of the decimal part (the scale) of the result will be
+ * be
+ * Implements the plus (Prefix
+ * This method is useful for rounding or otherwise applying a context
+ * to a decimal value.
+ *
+ * @param set The
+ * The same as {@link #pow(BigDecimal, MathContext)},
+ * where the
+ * The parameter is the power to which the
+ * In addition, the power must not be negative, as no
+ *
+ * Implements the power (
+ * The first parameter is the power to which the
+ * If the
+ * The same as {@link #remainder(BigDecimal, MathContext)},
+ * where the
+ * This is not the modulo operator -- the result may be negative.
+ *
+ * @param rhs The
+ * Implements the remainder operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a
+ * This is not the modulo operator -- the result may be negative.
+ *
+ * @param rhs The
+ * The same as {@link #subtract(BigDecimal, MathContext)},
+ * where the
+ * The length of the decimal part (the scale) of the result will be
+ * the maximum of the scales of the two operands.
+ *
+ * @param rhs The
+ * Implements the subtraction (
+ * If the parameter is
+ * The {@link #compareTo(BigDecimal, MathContext)} method should be
+ * used when a
+ * The double produced is identical to result of expressing the
+ *
+ * If the parameter is
+ * "Exactly equal", here, means that the
+ * The {@link #compareTo(BigDecimal, MathContext)} method should be
+ * used for more general comparisons.
+ * @param rhs The
+ * The float produced is identical to result of expressing the
+ *
+ * This method is provided as a primitive for use by more
+ * sophisticated classes, such as
+ * The parameters, for both forms of the
+ * The parameters,
+ *
+ *
+ * Other rounding methods, and the use of exponential notation, can
+ * be selected by using {@link #format(int,int,int,int,int,int)}.
+ * Using the two-parameter form of the method has exactly the same
+ * effect as using the six-parameter form with the final four
+ * parameters all being -1.
+ *
+ * @param before The
+ * This method is provided as a primitive for use by more
+ * sophisticated classes, such as
+ * The parameters are all of type
+ * The first two parameters (
+ * The remaining parameters control the use of exponential notation
+ * and rounding. Three (
+ *
+ *
+ *
+ * Finally, the sixth argument,
+ * The special value
+ * Note that two
+ *
+ *
+ * If the given scale (which must be zero or positive) is the same as
+ * or greater than the length of the decimal part (the scale) of this
+ *
+ * If the given scale is less than the length of the decimal part (the
+ * scale) of this
+ * The same as {@link #setScale(int, int)}, where the first parameter
+ * is the scale, and the second is
+ *
+ * If the given scale (which must be zero or positive) is the same as
+ * or greater than the length of the decimal part (the scale) of this
+ *
+ * If the given scale is less than the length of the decimal part (the
+ * scale) of this
+ * If
+ * This is an exact conversion; the result is the same as if the
+ *
+ * (Note: this method is provided only in the
+ *
+ * Any decimal part is truncated (discarded).
+ * If an exception is desired should the decimal part be non-zero,
+ * use {@link #toBigIntegerExact()}.
+ *
+ * @return The
+ * An exception is thrown if the decimal part (if any) is non-zero.
+ *
+ * @return The
+ * By definition, using the {@link #BigDecimal(String)} constructor
+ * on the result
+ * Returns a
+ * The number is constructed as though
+ * The result is given by:
+ *
+ * A The mantissa will either already have been rounded (following an
+ operation) or will be of length appropriate (in the case of
+ construction from an int, for example).
+ We must not alter the mantissa, here.
+ 'form' describes whether we are to use exponential notation (and
+ if so, which), or if we are to lay out as a plain/pure numeric.
+ If OK, returns it as an int. This routine performs the calculation:
+
+ If M<0 then A>=B must be true, so the result is always
+ non-negative.
+
+ Leading zeros are not removed after a subtraction. The result is
+ either the same length as the longer of A and B, or 1 longer than
+ that (if a carry occurred).
+
+ A is not altered unless Arg6 is 1.
+ B is never altered.
+
+ Arg1 is A
+ Arg2 is A length to use (if longer than A, pad with 0's)
+ Arg3 is B
+ Arg4 is B length to use (if longer than B, pad with 0's)
+ Arg5 is M, the multiplier
+ Arg6 is 1 if A can be used to build the result (if it fits)
+
+ This routine is severely performance-critical; *any* change here
+ must be measured (timed) to assure no performance degradation.
+ */
+ // 1996.02.20 -- enhanced version of DMSRCN algorithm (1981)
+ // 1997.10.05 -- changed to byte arrays (from char arrays)
+ // 1998.07.01 -- changed to allow destructive reuse of LHS
+ // 1998.07.01 -- changed to allow virtual lengths for the arrays
+ // 1998.12.29 -- use lookaside for digit/carry calculation
+ // 1999.08.07 -- avoid multiply when mult=1, and make db an int
+ // 1999.12.22 -- special case m=-1, also drop 0 special case
+
+ //--private static final byte[] byteaddsub(byte a[],int avlen,byte b[],int bvlen,int m,boolean reuse){
+ function byteaddsub(a, avlen, b, bvlen, m, reuse) {
+ //--int alength;
+ var alength;
+ //--int blength;
+ var blength;
+ //--int ap;
+ var ap;
+ //--int bp;
+ var bp;
+ //--int maxarr;
+ var maxarr;
+ //--byte reb[];
+ var reb;
+ //--boolean quickm;
+ var quickm;
+ //--int digit;
+ var digit;
+ //--int op=0;
+ var op=0;
+ //--int dp90=0;
+ var dp90=0;
+ //--byte newarr[];
+ var newarr;
+ //--int i=0;
+ var i=0;
+
+
+
+
+ // We'll usually be right if we assume no carry
+ alength=a.length; // physical lengths
+ blength=b.length; // ..
+ ap=avlen-1; // -> final (rightmost) digit
+ bp=bvlen-1; // ..
+ maxarr=bp;
+ if (maxarr This does NOT make a copy of the mantissa array.
+
+ This finishes off the current number by:
+ 1. Rounding if necessary (NB: length includes leading zeros)
+ 2. Stripping trailing zeros (if requested and \PLAIN)
+ 3. Stripping leading zeros (always)
+ 4. Selecting exponential notation (if required)
+ 5. Converting a zero result to just '0' (if \PLAIN)
+ In practice, these operations overlap and share code.
+ It always sets form.
+ ROUND_.
+ *
+ * @see #ROUND_CEILING
+ * @see #ROUND_DOWN
+ * @see #ROUND_FLOOR
+ * @see #ROUND_HALF_DOWN
+ * @see #ROUND_HALF_EVEN
+ * @see #ROUND_HALF_UP
+ * @see #ROUND_UNNECESSARY
+ * @see #ROUND_UP
+ * @serial
+ */
+ //--int roundingMode;
+
+ /* properties private constant */
+ // default settings
+ //--private static final int DEFAULT_FORM=SCIENTIFIC;
+ //--private static final int DEFAULT_DIGITS=9;
+ //--private static final boolean DEFAULT_LOSTDIGITS=false;
+ //--private static final int DEFAULT_ROUNDINGMODE=ROUND_HALF_UP;
+ MathContext.prototype.DEFAULT_FORM=MathContext.prototype.SCIENTIFIC;
+ MathContext.prototype.DEFAULT_DIGITS=9;
+ MathContext.prototype.DEFAULT_LOSTDIGITS=false;
+ MathContext.prototype.DEFAULT_ROUNDINGMODE=MathContext.prototype.ROUND_HALF_UP;
+
+ /* properties private constant */
+
+ //--private static final int MIN_DIGITS=0; // smallest value for DIGITS.
+ //--private static final int MAX_DIGITS=999999999; // largest value for DIGITS. If increased,
+ MathContext.prototype.MIN_DIGITS=0; // smallest value for DIGITS.
+ MathContext.prototype.MAX_DIGITS=999999999; // largest value for DIGITS. If increased,
+ // the BigDecimal class may need update.
+ // list of valid rounding mode values, most common two first
+ //--private static final int ROUNDS[]=new int[]{ROUND_HALF_UP,ROUND_UNNECESSARY,ROUND_CEILING,ROUND_DOWN,ROUND_FLOOR,ROUND_HALF_DOWN,ROUND_HALF_EVEN,ROUND_UP};
+ MathContext.prototype.ROUNDS=new Array(MathContext.prototype.ROUND_HALF_UP,MathContext.prototype.ROUND_UNNECESSARY,MathContext.prototype.ROUND_CEILING,MathContext.prototype.ROUND_DOWN,MathContext.prototype.ROUND_FLOOR,MathContext.prototype.ROUND_HALF_DOWN,MathContext.prototype.ROUND_HALF_EVEN,MathContext.prototype.ROUND_UP);
+
+
+ //--private static final java.lang.String ROUNDWORDS[]=new java.lang.String[]{"ROUND_HALF_UP","ROUND_UNNECESSARY","ROUND_CEILING","ROUND_DOWN","ROUND_FLOOR","ROUND_HALF_DOWN","ROUND_HALF_EVEN","ROUND_UP"}; // matching names of the ROUNDS values
+ MathContext.prototype.ROUNDWORDS=new Array("ROUND_HALF_UP","ROUND_UNNECESSARY","ROUND_CEILING","ROUND_DOWN","ROUND_FLOOR","ROUND_HALF_DOWN","ROUND_HALF_EVEN","ROUND_UP"); // matching names of the ROUNDS values
+
+
+
+
+ /* properties private constant unused */
+
+ // Serialization version
+ //--private static final long serialVersionUID=7163376998892515376L;
+
+ /* properties public constant */
+ /**
+ * A MathContext object initialized to the default
+ * settings for general-purpose arithmetic. That is,
+ * digits=9 form=SCIENTIFIC lostDigits=false
+ * roundingMode=ROUND_HALF_UP.
+ *
+ * @see #SCIENTIFIC
+ * @see #ROUND_HALF_UP
+ * @stable ICU 2.0
+ */
+ //--public static final com.ibm.icu.math.MathContext DEFAULT=new com.ibm.icu.math.MathContext(DEFAULT_DIGITS,DEFAULT_FORM,DEFAULT_LOSTDIGITS,DEFAULT_ROUNDINGMODE);
+ MathContext.prototype.DEFAULT=new MathContext(MathContext.prototype.DEFAULT_DIGITS,MathContext.prototype.DEFAULT_FORM,MathContext.prototype.DEFAULT_LOSTDIGITS,MathContext.prototype.DEFAULT_ROUNDINGMODE);
+
+
+
+
+ /* ----- Constructors ----- */
+
+ /**
+ * Constructs a new MathContext with a specified
+ * precision.
+ * The other settings are set to the default values
+ * (see {@link #DEFAULT}).
+ *
+ * An IllegalArgumentException is thrown if the
+ * setdigits parameter is out of range
+ * (<0 or >999999999).
+ *
+ * @param setdigits The int digits setting
+ * for this MathContext.
+ * @throws IllegalArgumentException parameter out of range.
+ * @stable ICU 2.0
+ */
+
+ //--public MathContext(int setdigits){
+ //-- this(setdigits,DEFAULT_FORM,DEFAULT_LOSTDIGITS,DEFAULT_ROUNDINGMODE);
+ //-- return;}
+
+
+ /**
+ * Constructs a new MathContext with a specified
+ * precision and form.
+ * The other settings are set to the default values
+ * (see {@link #DEFAULT}).
+ *
+ * An IllegalArgumentException is thrown if the
+ * setdigits parameter is out of range
+ * (<0 or >999999999), or if the value given for the
+ * setform parameter is not one of the appropriate
+ * constants.
+ *
+ * @param setdigits The int digits setting
+ * for this MathContext.
+ * @param setform The int form setting
+ * for this MathContext.
+ * @throws IllegalArgumentException parameter out of range.
+ * @stable ICU 2.0
+ */
+
+ //--public MathContext(int setdigits,int setform){
+ //-- this(setdigits,setform,DEFAULT_LOSTDIGITS,DEFAULT_ROUNDINGMODE);
+ //-- return;}
+
+ /**
+ * Constructs a new MathContext with a specified
+ * precision, form, and lostDigits setting.
+ * The roundingMode setting is set to its default value
+ * (see {@link #DEFAULT}).
+ *
+ * An IllegalArgumentException is thrown if the
+ * setdigits parameter is out of range
+ * (<0 or >999999999), or if the value given for the
+ * setform parameter is not one of the appropriate
+ * constants.
+ *
+ * @param setdigits The int digits setting
+ * for this MathContext.
+ * @param setform The int form setting
+ * for this MathContext.
+ * @param setlostdigits The boolean lostDigits
+ * setting for this MathContext.
+ * @throws IllegalArgumentException parameter out of range.
+ * @stable ICU 2.0
+ */
+
+ //--public MathContext(int setdigits,int setform,boolean setlostdigits){
+ //-- this(setdigits,setform,setlostdigits,DEFAULT_ROUNDINGMODE);
+ //-- return;}
+
+ /**
+ * Constructs a new MathContext with a specified
+ * precision, form, lostDigits, and roundingMode setting.
+ *
+ * An IllegalArgumentException is thrown if the
+ * setdigits parameter is out of range
+ * (<0 or >999999999), or if the value given for the
+ * setform or setroundingmode parameters is
+ * not one of the appropriate constants.
+ *
+ * @param setdigits The int digits setting
+ * for this MathContext.
+ * @param setform The int form setting
+ * for this MathContext.
+ * @param setlostdigits The boolean lostDigits
+ * setting for this MathContext.
+ * @param setroundingmode The int roundingMode setting
+ * for this MathContext.
+ * @throws IllegalArgumentException parameter out of range.
+ * @stable ICU 2.0
+ */
+
+ //--public MathContext(int setdigits,int setform,boolean setlostdigits,int setroundingmode){super();
+ function MathContext() {
+ //-- members
+ this.digits = 0;
+ this.form = 0; // values for this must fit in a byte
+ this.lostDigits = false;
+ this.roundingMode = 0;
+
+ //-- overloaded ctor
+ var setform = this.DEFAULT_FORM;
+ var setlostdigits = this.DEFAULT_LOSTDIGITS;
+ var setroundingmode = this.DEFAULT_ROUNDINGMODE;
+ if (MathContext.arguments.length == 4)
+ {
+ setform = MathContext.arguments[1];
+ setlostdigits = MathContext.arguments[2];
+ setroundingmode = MathContext.arguments[3];
+ }
+ else if (MathContext.arguments.length == 3)
+ {
+ setform = MathContext.arguments[1];
+ setlostdigits = MathContext.arguments[2];
+ }
+ else if (MathContext.arguments.length == 2)
+ {
+ setform = MathContext.arguments[1];
+ }
+ else if (MathContext.arguments.length != 1)
+ {
+ throw "MathContext(): " + MathContext.arguments.length + " arguments given; expected 1 to 4";
+ }
+ var setdigits = MathContext.arguments[0];
+
+
+ // set values, after checking
+ if (setdigits!=this.DEFAULT_DIGITS)
+ {
+ if (setdigitsint which is the value of the digits
+ * setting
+ * @stable ICU 2.0
+ */
+
+ //--public int getDigits(){
+ function getDigits() {
+ return this.digits;
+ }
+
+ /**
+ * Returns the form setting.
+ * This will be one of
+ * {@link #ENGINEERING},
+ * {@link #PLAIN}, or
+ * {@link #SCIENTIFIC}.
+ *
+ * @return an int which is the value of the form setting
+ * @stable ICU 2.0
+ */
+
+ //--public int getForm(){
+ function getForm() {
+ return this.form;
+ }
+
+ /**
+ * Returns the lostDigits setting.
+ * This will be either true (enabled) or
+ * false (disabled).
+ *
+ * @return a boolean which is the value of the lostDigits
+ * setting
+ * @stable ICU 2.0
+ */
+
+ //--public boolean getLostDigits(){
+ function getLostDigits() {
+ return this.lostDigits;
+ }
+
+ /**
+ * Returns the roundingMode setting.
+ * This will be one of
+ * {@link #ROUND_CEILING},
+ * {@link #ROUND_DOWN},
+ * {@link #ROUND_FLOOR},
+ * {@link #ROUND_HALF_DOWN},
+ * {@link #ROUND_HALF_EVEN},
+ * {@link #ROUND_HALF_UP},
+ * {@link #ROUND_UNNECESSARY}, or
+ * {@link #ROUND_UP}.
+ *
+ * @return an int which is the value of the roundingMode
+ * setting
+ * @stable ICU 2.0
+ */
+
+ //--public int getRoundingMode(){
+ function getRoundingMode() {
+ return this.roundingMode;
+ }
+
+ /** Returns the MathContext as a readable string.
+ * The String returned represents the settings of the
+ * MathContext object as four blank-delimited words
+ * separated by a single blank and with no leading or trailing blanks,
+ * as follows:
+ *
+ *
+ * digits=, immediately followed by
+ * the value of the digits setting as a numeric word.
+ * form=, immediately followed by
+ * the value of the form setting as an uppercase word
+ * (one of SCIENTIFIC, PLAIN, or
+ * ENGINEERING).
+ * lostDigits=, immediately followed by
+ * the value of the lostDigits setting
+ * (1 if enabled, 0 if disabled).
+ * roundingMode=, immediately followed by
+ * the value of the roundingMode setting as a word.
+ * This word will be the same as the name of the corresponding public
+ * constant.
+ *
+ * digits=9 form=SCIENTIFIC lostDigits=0 roundingMode=ROUND_HALF_UP
+ *
+ * toString in the future if more properties are added
+ * to the class.
+ *
+ * @return a String representing the context settings.
+ * @stable ICU 2.0
+ */
+
+ //--public java.lang.String toString(){
+ function toString() {
+ //--java.lang.String formstr=null;
+ var formstr=null;
+ //--int r=0;
+ var r=0;
+ //--java.lang.String roundword=null;
+ var roundword=null;
+ {/*select*/
+ if (this.form==this.SCIENTIFIC)
+ formstr="SCIENTIFIC";
+ else if (this.form==this.ENGINEERING)
+ formstr="ENGINEERING";
+ else{
+ formstr="PLAIN";/* form=PLAIN */
+ }
+ }
+ {var $1=this.ROUNDS.length;r=0;r:for(;$1>0;$1--,r++){
+ if (this.roundingMode==this.ROUNDS[r])
+ {
+ roundword=this.ROUNDWORDS[r];
+ break r;
+ }
+ }
+ }/*r*/
+ return "digits="+this.digits+" "+"form="+formstr+" "+"lostDigits="+(this.lostDigits?"1":"0")+" "+"roundingMode="+roundword;
+ }
+
+
+ /* BigDecimal class implements immutable
+ * arbitrary-precision decimal numbers. The methods of the
+ * BigDecimal class provide operations for fixed and
+ * floating point arithmetic, comparison, format conversions, and
+ * hashing.
+ * BigDecimal object and its
+ * String representation; the BigDecimal class
+ * provides direct conversions to and from String and
+ * character array (char[]) objects, as well as conversions
+ * to and from the Java primitive types (which may not be exact) and
+ * BigInteger.
+ * BigDecimal number object is shown as the
+ * result of invoking the toString() method on the object.
+ * The internal representation of a decimal number is neither defined
+ * nor exposed, and is not permitted to affect the result of any
+ * operation.
+ * http://www2.hursley.ibm.com/decimal
+ *
[This URL will change.]
+ *
+ * Operator methods
+ * BigDecimal numbers are controlled by a
+ * {@link MathContext} object, which provides the context (precision and
+ * other information) for the operation. Methods that can take a
+ * MathContext parameter implement the standard arithmetic
+ * operators for BigDecimal objects and are known as
+ * operator methods. The default settings provided by the
+ * constant {@link MathContext#DEFAULT} (digits=9,
+ * form=SCIENTIFIC, lostDigits=false, roundingMode=ROUND_HALF_UP)
+ * perform general-purpose floating point arithmetic to nine digits of
+ * precision. The MathContext parameter must not be
+ * null.
+ * MathContext parameter. For this version of
+ * each method, the context settings used are digits=0,
+ * form=PLAIN, lostDigits=false, roundingMode=ROUND_HALF_UP;
+ * these settings perform fixed point arithmetic with unlimited
+ * precision, as defined for the original BigDecimal class in Java 1.1
+ * and Java 1.2.
+ * MathContext
+ * parameter is present; the operation acts upon the current object.
+ * BigDecimal parameter is always
+ * present; it must not be null.
+ * The operation acts with the current object being the left-hand operand
+ * and the BigDecimal parameter being the right-hand operand.
+ * BigDecimal objects referred to
+ * by the names award and extra could be
+ * written as any of:
+ *
+ * award.add(extra)
+ *
+ *
award.add(extra, MathContext.DEFAULT)
+ *
award.add(extra, acontext)
+ * acontext is a MathContext object),
+ * which would return a BigDecimal object whose value is
+ * the result of adding award and extra under
+ * the appropriate context settings.
+ * BigDecimal operator method is used, a set of
+ * rules define what the result will be (and, by implication, how the
+ * result would be represented as a character string).
+ * These rules are defined in the BigDecimal arithmetic documentation
+ * (see the URL above), but in summary:
+ *
+ *
MathContext parameter for an operation
+ * were MathContext.DEFAULT then the result would be
+ * rounded to 9 digits; the division of 2 by 3 would then result in
+ * 0.666666667.
+ *
+ * You can change the default of 9 significant digits by providing the
+ * method with a suitable MathContext object. This lets you
+ * calculate using as many digits as you need -- thousands, if necessary.
+ * Fixed point (scaled) arithmetic is indicated by using a
+ * digits setting of 0 (or omitting the
+ * MathContext parameter).
+ *
+ * Similarly, you can change the algorithm used for rounding from the
+ * default "classic" algorithm.
+ * form setting
+ * is not PLAIN), a zero result is always expressed as the
+ * single digit '0' (that is, with no sign, decimal point,
+ * or exponent part).
+ *
+ * So, for example:
+ *
+ * new BigDecimal("2.40").add( new BigDecimal("2")) => "4.40"
+ *
+ *
new BigDecimal("2.40").subtract(new BigDecimal("2")) => "0.40"
+ *
new BigDecimal("2.40").multiply(new BigDecimal("2")) => "4.80"
+ *
new BigDecimal("2.40").divide( new BigDecimal("2"), def) => "1.2"
+ * => would be the
+ * result of the operation, expressed as a String, and
+ * def (in this and following examples) refers to
+ * MathContext.DEFAULT).
+ * This preservation of trailing zeros is desirable for most
+ * calculations (including financial calculations).
+ * If necessary, trailing zeros may be easily removed using division by 1.
+ * digits
+ * (the default is 9 digits).
+ * If the number of places needed before the decimal point exceeds the
+ * digits setting, or the absolute value of the number is
+ * less than 0.000001, then the number will be expressed in
+ * exponential notation; thus
+ *
+ * new BigDecimal("1e+6").multiply(new BigDecimal("1e+6"), def)
+ *
+ * 1E+12 instead of
+ * 1000000000000, and
+ *
+ * new BigDecimal("1").divide(new BigDecimal("3E+10"), def)
+ *
+ * 3.33333333E-11 instead of
+ * 0.0000000000333333333.
+ * form setting.
+ * java.lang.Number, java.math.BigInteger,
+ * and java.math.BigDecimal in Java 1.1 and Java 1.2.
+ *
+ * @see MathContext
+ * @author Mike Cowlishaw
+ * @stable ICU 2.0
+ */
+
+//--public class BigDecimal extends java.lang.Number implements java.io.Serializable,java.lang.Comparable{
+//-- private static final java.lang.String $0="BigDecimal.nrx";
+
+ //-- methods
+ BigDecimal.prototype.abs = abs;
+ BigDecimal.prototype.add = add;
+ BigDecimal.prototype.compareTo = compareTo;
+ BigDecimal.prototype.divide = divide;
+ BigDecimal.prototype.divideInteger = divideInteger;
+ BigDecimal.prototype.max = max;
+ BigDecimal.prototype.min = min;
+ BigDecimal.prototype.multiply = multiply;
+ BigDecimal.prototype.negate = negate;
+ BigDecimal.prototype.plus = plus;
+ BigDecimal.prototype.pow = pow;
+ BigDecimal.prototype.remainder = remainder;
+ BigDecimal.prototype.subtract = subtract;
+ BigDecimal.prototype.equals = equals;
+ BigDecimal.prototype.format = format;
+ BigDecimal.prototype.intValueExact = intValueExact;
+ BigDecimal.prototype.movePointLeft = movePointLeft;
+ BigDecimal.prototype.movePointRight = movePointRight;
+ BigDecimal.prototype.scale = scale;
+ BigDecimal.prototype.setScale = setScale;
+ BigDecimal.prototype.signum = signum;
+ BigDecimal.prototype.toString = toString;
+ BigDecimal.prototype.layout = layout;
+ BigDecimal.prototype.intcheck = intcheck;
+ BigDecimal.prototype.dodivide = dodivide;
+ BigDecimal.prototype.bad = bad;
+ BigDecimal.prototype.badarg = badarg;
+ BigDecimal.prototype.extend = extend;
+ BigDecimal.prototype.byteaddsub = byteaddsub;
+ BigDecimal.prototype.diginit = diginit;
+ BigDecimal.prototype.clone = clone;
+ BigDecimal.prototype.checkdigits = checkdigits;
+ BigDecimal.prototype.round = round;
+ BigDecimal.prototype.allzero = allzero;
+ BigDecimal.prototype.finish = finish;
+
+ // Convenience methods
+ BigDecimal.prototype.isGreaterThan = isGreaterThan;
+ BigDecimal.prototype.isLessThan = isLessThan;
+ BigDecimal.prototype.isGreaterThanOrEqualTo = isGreaterThanOrEqualTo;
+ BigDecimal.prototype.isLessThanOrEqualTo = isLessThanOrEqualTo;
+ BigDecimal.prototype.isPositive = isPositive;
+ BigDecimal.prototype.isNegative = isNegative;
+ BigDecimal.prototype.isZero = isZero;
+
+
+ /* ----- Constants ----- */
+ /* properties constant public */ // useful to others
+ // the rounding modes (copied here for upwards compatibility)
+ /**
+ * Rounding mode to round to a more positive number.
+ * @see MathContext#ROUND_CEILING
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_CEILING=com.ibm.icu.math.MathContext.ROUND_CEILING;
+ BigDecimal.ROUND_CEILING = BigDecimal.prototype.ROUND_CEILING = MathContext.prototype.ROUND_CEILING;
+
+ /**
+ * Rounding mode to round towards zero.
+ * @see MathContext#ROUND_DOWN
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_DOWN=com.ibm.icu.math.MathContext.ROUND_DOWN;
+ BigDecimal.ROUND_DOWN = BigDecimal.prototype.ROUND_DOWN = MathContext.prototype.ROUND_DOWN;
+
+ /**
+ * Rounding mode to round to a more negative number.
+ * @see MathContext#ROUND_FLOOR
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_FLOOR=com.ibm.icu.math.MathContext.ROUND_FLOOR;
+ BigDecimal.ROUND_FLOOR = BigDecimal.prototype.ROUND_FLOOR = MathContext.prototype.ROUND_FLOOR;
+
+ /**
+ * Rounding mode to round to nearest neighbor, where an equidistant
+ * value is rounded down.
+ * @see MathContext#ROUND_HALF_DOWN
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_HALF_DOWN=com.ibm.icu.math.MathContext.ROUND_HALF_DOWN;
+ BigDecimal.ROUND_HALF_DOWN = BigDecimal.prototype.ROUND_HALF_DOWN = MathContext.prototype.ROUND_HALF_DOWN;
+
+ /**
+ * Rounding mode to round to nearest neighbor, where an equidistant
+ * value is rounded to the nearest even neighbor.
+ * @see MathContext#ROUND_HALF_EVEN
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_HALF_EVEN=com.ibm.icu.math.MathContext.ROUND_HALF_EVEN;
+ BigDecimal.ROUND_HALF_EVEN = BigDecimal.prototype.ROUND_HALF_EVEN = MathContext.prototype.ROUND_HALF_EVEN;
+
+ /**
+ * Rounding mode to round to nearest neighbor, where an equidistant
+ * value is rounded up.
+ * @see MathContext#ROUND_HALF_UP
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_HALF_UP=com.ibm.icu.math.MathContext.ROUND_HALF_UP;
+ BigDecimal.ROUND_HALF_UP = BigDecimal.prototype.ROUND_HALF_UP = MathContext.prototype.ROUND_HALF_UP;
+
+ /**
+ * Rounding mode to assert that no rounding is necessary.
+ * @see MathContext#ROUND_UNNECESSARY
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_UNNECESSARY=com.ibm.icu.math.MathContext.ROUND_UNNECESSARY;
+ BigDecimal.ROUND_UNNECESSARY = BigDecimal.prototype.ROUND_UNNECESSARY = MathContext.prototype.ROUND_UNNECESSARY;
+
+ /**
+ * Rounding mode to round away from zero.
+ * @see MathContext#ROUND_UP
+ * @stable ICU 2.0
+ */
+ //--public static final int ROUND_UP=com.ibm.icu.math.MathContext.ROUND_UP;
+ BigDecimal.ROUND_UP = BigDecimal.prototype.ROUND_UP = MathContext.prototype.ROUND_UP;
+
+ /* properties constant private */ // locals
+ //--private static final byte ispos=1; // ind: indicates positive (must be 1)
+ //--private static final byte iszero=0; // ind: indicates zero (must be 0)
+ //--private static final byte isneg=-1; // ind: indicates negative (must be -1)
+ BigDecimal.prototype.ispos = 1;
+ BigDecimal.prototype.iszero = 0;
+ BigDecimal.prototype.isneg = -1;
+ // [later could add NaN, +/- infinity, here]
+
+ //--private static final int MinExp=-999999999; // minimum exponent allowed
+ //--private static final int MaxExp=999999999; // maximum exponent allowed
+ //--private static final int MinArg=-999999999; // minimum argument integer
+ //--private static final int MaxArg=999999999; // maximum argument integer
+ BigDecimal.prototype.MinExp=-999999999; // minimum exponent allowed
+ BigDecimal.prototype.MaxExp=999999999; // maximum exponent allowed
+ BigDecimal.prototype.MinArg=-999999999; // minimum argument integer
+ BigDecimal.prototype.MaxArg=999999999; // maximum argument integer
+
+ //--private static final com.ibm.icu.math.MathContext plainMC=new com.ibm.icu.math.MathContext(0,com.ibm.icu.math.MathContext.PLAIN); // context for plain unlimited math
+ BigDecimal.prototype.plainMC=new MathContext(0, MathContext.prototype.PLAIN);
+
+ /* properties constant private unused */ // present but not referenced
+
+ // Serialization version
+ //--private static final long serialVersionUID=8245355804974198832L;
+
+ //--private static final java.lang.String copyright=" Copyright (c) IBM Corporation 1996, 2000. All rights reserved. ";
+
+ /* properties static private */
+ // Precalculated constant arrays (used by byteaddsub)
+ //--private static byte bytecar[]=new byte[(90+99)+1]; // carry/borrow array
+ //--private static byte bytedig[]=diginit(); // next digit array
+ BigDecimal.prototype.bytecar = new Array((90+99)+1);
+ BigDecimal.prototype.bytedig = diginit();
+
+ /**
+ * The BigDecimal constant "0".
+ *
+ * @see #ONE
+ * @see #TEN
+ * @stable ICU 2.0
+ */
+ //--public static final com.ibm.icu.math.BigDecimal ZERO=new com.ibm.icu.math.BigDecimal((long)0); // use long as we want the int constructor
+ // .. to be able to use this, for speed
+BigDecimal.ZERO = BigDecimal.prototype.ZERO = new BigDecimal("0");
+
+ /**
+ * The BigDecimal constant "1".
+ *
+ * @see #TEN
+ * @see #ZERO
+ * @stable ICU 2.0
+ */
+ //--public static final com.ibm.icu.math.BigDecimal ONE=new com.ibm.icu.math.BigDecimal((long)1); // use long as we want the int constructor
+ // .. to be able to use this, for speed
+BigDecimal.ONE = BigDecimal.prototype.ONE = new BigDecimal("1");
+
+ /**
+ * The BigDecimal constant "10".
+ *
+ * @see #ONE
+ * @see #ZERO
+ * @stable ICU 2.0
+ */
+ //--public static final com.ibm.icu.math.BigDecimal TEN=new com.ibm.icu.math.BigDecimal(10);
+ BigDecimal.TEN = BigDecimal.prototype.TEN = new BigDecimal("10");
+
+ /* ----- Instance properties [all private and immutable] ----- */
+ /* properties private */
+
+ /**
+ * The indicator. This may take the values:
+ *
+ *
+ *
+ * @serial
+ */
+ //--private byte ind; // assumed undefined
+ // Note: some code below assumes IND = Sign [-1, 0, 1], at present.
+ // We only need two bits for this, but use a byte [also permits
+ // smooth future extension].
+
+ /**
+ * The formatting style. This may take the values:
+ *
+ *
+ * -exp, and can
+ * apply to zero.
+ *
+ * Note that this property can have a value less than MinExp when
+ * the mantissa has more than one digit.
+ *
+ * @serial
+ */
+ //--private int exp;
+ // assumed 0
+
+ /* ---------------------------------------------------------------- */
+ /* Constructors */
+ /* ---------------------------------------------------------------- */
+
+ /**
+ * Constructs a BigDecimal object from a
+ * java.math.BigDecimal.
+ * BigDecimal as though the parameter had
+ * been represented as a String (using its
+ * toString method) and the
+ * {@link #BigDecimal(java.lang.String)} constructor had then been
+ * used.
+ * The parameter must not be null.
+ * com.ibm.icu.math version of the BigDecimal class.
+ * It would not be present in a java.math version.)
+ *
+ * @param bd The BigDecimal to be translated.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(java.math.BigDecimal bd){
+ //-- this(bd.toString());
+ //-- return;}
+
+ /**
+ * Constructs a BigDecimal object from a
+ * BigInteger, with scale 0.
+ * BigDecimal which is the exact decimal
+ * representation of the BigInteger, with a scale of
+ * zero.
+ * The value of the BigDecimal is identical to the value
+ * of the BigInteger.
+ * The parameter must not be null.
+ * BigDecimal will contain only decimal digits,
+ * prefixed with a leading minus sign (hyphen) if the
+ * BigInteger is negative. A leading zero will be
+ * present only if the BigInteger is zero.
+ *
+ * @param bi The BigInteger to be converted.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(java.math.BigInteger bi){
+ //-- this(bi.toString(10));
+ //-- return;}
+ // exp remains 0
+
+ /**
+ * Constructs a BigDecimal object from a
+ * BigInteger and a scale.
+ * BigDecimal which is the exact decimal
+ * representation of the BigInteger, scaled by the
+ * second parameter, which may not be negative.
+ * The value of the BigDecimal is the
+ * BigInteger divided by ten to the power of the scale.
+ * The BigInteger parameter must not be
+ * null.
+ * BigDecimal will contain only decimal digits, (with
+ * an embedded decimal point followed by scale decimal
+ * digits if the scale is positive), prefixed with a leading minus
+ * sign (hyphen) if the BigInteger is negative. A
+ * leading zero will be present only if the BigInteger is
+ * zero.
+ *
+ * @param bi The BigInteger to be converted.
+ * @param scale The int specifying the scale.
+ * @throws NumberFormatException if the scale is negative.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(java.math.BigInteger bi,int scale){
+ //-- this(bi.toString(10));
+ //-- if (scale<0)
+ //-- throw new java.lang.NumberFormatException("Negative scale:"+" "+scale);
+ //-- exp=(int)-scale; // exponent is -scale
+ //-- return;}
+
+ /**
+ * Constructs a BigDecimal object from an array of characters.
+ * BigDecimal as though a
+ * String had been constructed from the character array
+ * and the {@link #BigDecimal(java.lang.String)} constructor had then
+ * been used. The parameter must not be null.
+ * BigDecimal(String) constructor if the string is
+ * already available in character array form.
+ *
+ * @param inchars The char[] array containing the number
+ * to be converted.
+ * @throws NumberFormatException if the parameter is not a valid
+ * number.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(char inchars[]){
+ //-- this(inchars,0,inchars.length);
+ //-- return;}
+
+ /**
+ * Constructs a BigDecimal object from an array of characters.
+ * BigDecimal as though a
+ * String had been constructed from the character array
+ * (or a subarray of that array) and the
+ * {@link #BigDecimal(java.lang.String)} constructor had then been
+ * used. The first parameter must not be null, and the
+ * subarray must be wholly contained within it.
+ * BigDecimal(String) constructor if the string is
+ * already available within a character array.
+ *
+ * @param inchars The char[] array containing the number
+ * to be converted.
+ * @param offset The int offset into the array of the
+ * start of the number to be converted.
+ * @param length The int length of the number.
+ * @throws NumberFormatException if the parameter is not a valid
+ * number for any reason.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(char inchars[],int offset,int length){super();
+ function BigDecimal() {
+ //-- members
+ this.ind = 0;
+ this.form = MathContext.prototype.PLAIN;
+ this.mant = null;
+ this.exp = 0;
+
+ //-- overloaded ctor
+ if (BigDecimal.arguments.length == 0)
+ return;
+ var inchars;
+ var offset;
+ var length;
+ if (BigDecimal.arguments.length == 1)
+ {
+ inchars = BigDecimal.arguments[0];
+ offset = 0;
+ length = inchars.length;
+ }
+ else
+ {
+ inchars = BigDecimal.arguments[0];
+ offset = BigDecimal.arguments[1];
+ length = BigDecimal.arguments[2];
+ }
+ if (typeof inchars == "string")
+ {
+ inchars = inchars.split("");
+ }
+
+ //--boolean exotic;
+ var exotic;
+ //--boolean hadexp;
+ var hadexp;
+ //--int d;
+ var d;
+ //--int dotoff;
+ var dotoff;
+ //--int last;
+ var last;
+ //--int i=0;
+ var i=0;
+ //--char si=0;
+ var si=0;
+ //--boolean eneg=false;
+ var eneg=false;
+ //--int k=0;
+ var k=0;
+ //--int elen=0;
+ var elen=0;
+ //--int j=0;
+ var j=0;
+ //--char sj=0;
+ var sj=0;
+ //--int dvalue=0;
+ var dvalue=0;
+ //--int mag=0;
+ var mag=0;
+ // This is the primary constructor; all incoming strings end up
+ // here; it uses explicit (inline) parsing for speed and to avoid
+ // generating intermediate (temporary) objects of any kind.
+ // 1998.06.25: exponent form built only if E/e in string
+ // 1998.06.25: trailing zeros not removed for zero
+ // 1999.03.06: no embedded blanks; allow offset and length
+ if (length<=0)
+ this.bad("BigDecimal(): ", inchars); // bad conversion (empty string)
+ // [bad offset will raise array bounds exception]
+
+ /* Handle and step past sign */
+ this.ind=this.ispos; // assume positive
+ if (inchars[0]==('-'))
+ {
+ length--;
+ if (length==0)
+ this.bad("BigDecimal(): ", inchars); // nothing after sign
+ this.ind=this.isneg;
+ offset++;
+ }
+ else
+ if (inchars[0]==('+'))
+ {
+ length--;
+ if (length==0)
+ this.bad("BigDecimal(): ", inchars); // nothing after sign
+ offset++;
+ }
+
+ /* We're at the start of the number */
+ exotic=false; // have extra digits
+ hadexp=false; // had explicit exponent
+ d=0; // count of digits found
+ dotoff=-1; // offset where dot was found
+ last=-1; // last character of mantissa
+ {var $1=length;i=offset;i:for(;$1>0;$1--,i++){
+ si=inchars[i];
+ if (si>='0') // test for Arabic digit
+ if (si<='9')
+ {
+ last=i;
+ d++; // still in mantissa
+ continue i;
+ }
+ if (si=='.')
+ { // record and ignore
+ if (dotoff>=0)
+ this.bad("BigDecimal(): ", inchars); // two dots
+ dotoff=i-offset; // offset into mantissa
+ continue i;
+ }
+ if (si!='e')
+ if (si!='E')
+ { // expect an extra digit
+ if (si<'0' || si>'9')
+ this.bad("BigDecimal(): ", inchars); // not a number
+ // defer the base 10 check until later to avoid extra method call
+ exotic=true; // will need conversion later
+ last=i;
+ d++; // still in mantissa
+ continue i;
+ }
+ /* Found 'e' or 'E' -- now process explicit exponent */
+ // 1998.07.11: sign no longer required
+ if ((i-offset)>(length-2))
+ this.bad("BigDecimal(): ", inchars); // no room for even one digit
+ eneg=false;
+ if ((inchars[i+1])==('-'))
+ {
+ eneg=true;
+ k=i+2;
+ }
+ else
+ if ((inchars[i+1])==('+'))
+ k=i+2;
+ else
+ k=i+1;
+ // k is offset of first expected digit
+ elen=length-((k-offset)); // possible number of digits
+ if ((elen==0)||(elen>9))
+ this.bad("BigDecimal(): ", inchars); // 0 or more than 9 digits
+ {var $2=elen;j=k;j:for(;$2>0;$2--,j++){
+ sj=inchars[j];
+ if (sj<'0')
+ this.bad("BigDecimal(): ", inchars); // always bad
+ if (sj>'9')
+ { // maybe an exotic digit
+ /*if (si<'0' || si>'9')
+ this.bad(inchars); // not a number
+ dvalue=java.lang.Character.digit(sj,10); // check base
+ if (dvalue<0)
+ bad(inchars); // not base 10*/
+ this.bad("BigDecimal(): ", inchars);
+ }
+ else
+ dvalue=sj-'0';
+ this.exp=(this.exp*10)+dvalue;
+ }
+ }/*j*/
+ if (eneg)
+ this.exp=-this.exp; // was negative
+ hadexp=true; // remember we had one
+ break i; // we are done
+ }
+ }/*i*/
+
+ /* Here when all inspected */
+ if (d==0)
+ this.bad("BigDecimal(): ", inchars); // no mantissa digits
+ if (dotoff>=0)
+ this.exp=(this.exp+dotoff)-d; // adjust exponent if had dot
+
+ /* strip leading zeros/dot (leave final if all 0's) */
+ {var $3=last-1;i=offset;i:for(;i<=$3;i++){
+ si=inchars[i];
+ if (si=='0')
+ {
+ offset++;
+ dotoff--;
+ d--;
+ }
+ else
+ if (si=='.')
+ {
+ offset++; // step past dot
+ dotoff--;
+ }
+ else
+ if (si<='9')
+ break i;/* non-0 */
+ else
+ {/* exotic */
+ //if ((java.lang.Character.digit(si,10))!=0)
+ break i; // non-0 or bad
+ // is 0 .. strip like '0'
+ //offset++;
+ //dotoff--;
+ //d--;
+ }
+ }
+ }/*i*/
+
+ /* Create the mantissa array */
+ this.mant=new Array(d); // we know the length
+ j=offset; // input offset
+ if (exotic)
+ {exotica:do{ // slow: check for exotica
+ {var $4=d;i=0;i:for(;$4>0;$4--,i++){
+ if (i==dotoff)
+ j++; // at dot
+ sj=inchars[j];
+ if (sj<='9')
+ this.mant[i]=sj-'0';/* easy */
+ else
+ {
+ //dvalue=java.lang.Character.digit(sj,10);
+ //if (dvalue<0)
+ this.bad("BigDecimal(): ", inchars); // not a number after all
+ //mant[i]=(byte)dvalue;
+ }
+ j++;
+ }
+ }/*i*/
+ }while(false);}/*exotica*/
+ else
+ {simple:do{
+ {var $5=d;i=0;i:for(;$5>0;$5--,i++){
+ if (i==dotoff)
+ j++;
+ this.mant[i]=inchars[j]-'0';
+ j++;
+ }
+ }/*i*/
+ }while(false);}/*simple*/
+
+ /* Looks good. Set the sign indicator and form, as needed. */
+ // Trailing zeros are preserved
+ // The rule here for form is:
+ // If no E-notation, then request plain notation
+ // Otherwise act as though add(0,DEFAULT) and request scientific notation
+ // [form is already PLAIN]
+ if (this.mant[0]==0)
+ {
+ this.ind=this.iszero; // force to show zero
+ // negative exponent is significant (e.g., -3 for 0.000) if plain
+ if (this.exp>0)
+ this.exp=0; // positive exponent can be ignored
+ if (hadexp)
+ { // zero becomes single digit from add
+ this.mant=this.ZERO.mant;
+ this.exp=0;
+ }
+ }
+ else
+ { // non-zero
+ // [ind was set earlier]
+ // now determine form
+ if (hadexp)
+ {
+ this.form=MathContext.prototype.SCIENTIFIC;
+ // 1999.06.29 check for overflow
+ mag=(this.exp+this.mant.length)-1; // true exponent in scientific notation
+ if ((magBigDecimal object directly from a
+ * double.
+ * BigDecimal which is the exact decimal
+ * representation of the 64-bit signed binary floating point
+ * parameter.
+ * num to a
+ * String using the Double.toString() method
+ * and then using the {@link #BigDecimal(java.lang.String)}
+ * constructor.
+ * To get that result, use the static {@link #valueOf(double)}
+ * method to construct a BigDecimal from a
+ * double.
+ *
+ * @param num The double to be converted.
+ * @throws NumberFormatException if the parameter is infinite or
+ * not a number.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(double num){
+ //-- // 1999.03.06: use exactly the old algorithm
+ //-- // 2000.01.01: note that this constructor does give an exact result,
+ //-- // so perhaps it should not be deprecated
+ //-- // 2000.06.18: no longer deprecated
+ //-- this((new java.math.BigDecimal(num)).toString());
+ //-- return;}
+
+ /**
+ * Constructs a BigDecimal object directly from a
+ * int.
+ * BigDecimal which is the exact decimal
+ * representation of the 32-bit signed binary integer parameter.
+ * The BigDecimal will contain only decimal digits,
+ * prefixed with a leading minus sign (hyphen) if the parameter is
+ * negative.
+ * A leading zero will be present only if the parameter is zero.
+ *
+ * @param num The int to be converted.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(int num){super();
+ //-- int mun;
+ //-- int i=0;
+ //-- // We fastpath commoners
+ //-- if (num<=9)
+ //-- if (num>=(-9))
+ //-- {singledigit:do{
+ //-- // very common single digit case
+ //-- {/*select*/
+ //-- if (num==0)
+ //-- {
+ //-- mant=ZERO.mant;
+ //-- ind=iszero;
+ //-- }
+ //-- else if (num==1)
+ //-- {
+ //-- mant=ONE.mant;
+ //-- ind=ispos;
+ //-- }
+ //-- else if (num==(-1))
+ //-- {
+ //-- mant=ONE.mant;
+ //-- ind=isneg;
+ //-- }
+ //-- else{
+ //-- {
+ //-- mant=new byte[1];
+ //-- if (num>0)
+ //-- {
+ //-- mant[0]=(byte)num;
+ //-- ind=ispos;
+ //-- }
+ //-- else
+ //-- { // num<-1
+ //-- mant[0]=(byte)((int)-num);
+ //-- ind=isneg;
+ //-- }
+ //-- }
+ //-- }
+ //-- }
+ //-- return;
+ //-- }while(false);}/*singledigit*/
+ //--
+ //-- /* We work on negative numbers so we handle the most negative number */
+ //-- if (num>0)
+ //-- {
+ //-- ind=ispos;
+ //-- num=(int)-num;
+ //-- }
+ //-- else
+ //-- ind=isneg;/* negative */ // [0 case already handled]
+ //-- // [it is quicker, here, to pre-calculate the length with
+ //-- // one loop, then allocate exactly the right length of byte array,
+ //-- // then re-fill it with another loop]
+ //-- mun=num; // working copy
+ //-- {i=9;i:for(;;i--){
+ //-- mun=mun/10;
+ //-- if (mun==0)
+ //-- break i;
+ //-- }
+ //-- }/*i*/
+ //-- // i is the position of the leftmost digit placed
+ //-- mant=new byte[10-i];
+ //-- {i=(10-i)-1;i:for(;;i--){
+ //-- mant[i]=(byte)-(((byte)(num%10)));
+ //-- num=num/10;
+ //-- if (num==0)
+ //-- break i;
+ //-- }
+ //-- }/*i*/
+ //-- return;
+ //-- }
+
+ /**
+ * Constructs a BigDecimal object directly from a
+ * long.
+ * BigDecimal which is the exact decimal
+ * representation of the 64-bit signed binary integer parameter.
+ * The BigDecimal will contain only decimal digits,
+ * prefixed with a leading minus sign (hyphen) if the parameter is
+ * negative.
+ * A leading zero will be present only if the parameter is zero.
+ *
+ * @param num The long to be converted.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(long num){super();
+ //-- long mun;
+ //-- int i=0;
+ //-- // Not really worth fastpathing commoners in this constructor [also,
+ //-- // we use this to construct the static constants].
+ //-- // This is much faster than: this(String.valueOf(num).toCharArray())
+ //-- /* We work on negative num so we handle the most negative number */
+ //-- if (num>0)
+ //-- {
+ //-- ind=ispos;
+ //-- num=(long)-num;
+ //-- }
+ //-- else
+ //-- if (num==0)
+ //-- ind=iszero;
+ //-- else
+ //-- ind=isneg;/* negative */
+ //-- mun=num;
+ //-- {i=18;i:for(;;i--){
+ //-- mun=mun/10;
+ //-- if (mun==0)
+ //-- break i;
+ //-- }
+ //-- }/*i*/
+ //-- // i is the position of the leftmost digit placed
+ //-- mant=new byte[19-i];
+ //-- {i=(19-i)-1;i:for(;;i--){
+ //-- mant[i]=(byte)-(((byte)(num%10)));
+ //-- num=num/10;
+ //-- if (num==0)
+ //-- break i;
+ //-- }
+ //-- }/*i*/
+ //-- return;
+ //-- }
+
+ /**
+ * Constructs a BigDecimal object from a String.
+ * BigDecimal from the parameter, which must
+ * not be null and must represent a valid number,
+ * as described formally in the documentation referred to
+ * {@link BigDecimal above}.
+ * String form must have at least
+ * one digit, may have a leading sign, may have a decimal point, and
+ * exponential notation may be used. They follow conventional syntax,
+ * and may not contain blanks.
+ * BigDecimal might
+ * be constructed are:
+ *
+ * "0" -- Zero
+ * "12" -- A whole number
+ * "-76" -- A signed whole number
+ * "12.70" -- Some decimal places
+ * "+0.003" -- Plus sign is allowed
+ * "17." -- The same as 17
+ * ".5" -- The same as 0.5
+ * "4E+9" -- Exponential notation
+ * "0.73e-7" -- Exponential notation
+ *
+ * "4E+9" above is just a short way of writing
+ * 4000000000, and the "0.73e-7" is short
+ * for 0.000000073.)
+ * BigDecimal constructed from the String is in a
+ * standard form, with no blanks, as though the
+ * {@link #add(BigDecimal)} method had been used to add zero to the
+ * number with unlimited precision.
+ * If the string uses exponential notation (that is, includes an
+ * e or an E), then the
+ * BigDecimal number will be expressed in scientific
+ * notation (where the power of ten is adjusted so there is a single
+ * non-zero digit to the left of the decimal point); in this case if
+ * the number is zero then it will be expressed as the single digit 0,
+ * and if non-zero it will have an exponent unless that exponent would
+ * be 0. The exponent must fit in nine digits both before and after it
+ * is expressed in scientific notation.
+ * Character.digit(c, 10) (where c is the
+ * character in question) would not return -1.
+ *
+ * @param string The String to be converted.
+ * @throws NumberFormatException if the parameter is not a valid
+ * number.
+ * @stable ICU 2.0
+ */
+
+ //--public BigDecimal(java.lang.String string){
+ //-- this(string.toCharArray(),0,string.length());
+ //-- return;}
+
+ /* BigDecimal whose value is the absolute
+ * value of this BigDecimal.
+ * new MathContext(0, MathContext.PLAIN).
+ * this.scale()
+ *
+ * @return A BigDecimal whose value is the absolute
+ * value of this BigDecimal.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal abs(){
+ //- return this.abs(plainMC);
+ //- }
+
+ /**
+ * Returns a BigDecimal whose value is the absolute value
+ * of this BigDecimal.
+ * MathContext arithmetic settings.
+ * @return A BigDecimal whose value is the absolute
+ * value of this BigDecimal.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal abs(com.ibm.icu.math.MathContext set){
+ function abs() {
+ var set;
+ if (abs.arguments.length == 1)
+ {
+ set = abs.arguments[0];
+ }
+ else if (abs.arguments.length == 0)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "abs(): " + abs.arguments.length + " arguments given; expected 0 or 1";
+ }
+ if (this.ind==this.isneg)
+ return this.negate(set);
+ return this.plus(set);
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * this+rhs, using fixed point arithmetic.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ * BigDecimal for the right hand side of
+ * the addition.
+ * @return A BigDecimal whose value is
+ * this+rhs, using fixed point arithmetic.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal add(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.add(rhs,plainMC);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is this+rhs.
+ * +) operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a BigDecimal object.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the addition.
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * this+rhs.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal add(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function add() {
+ var set;
+ if (add.arguments.length == 2)
+ {
+ set = add.arguments[1];
+ }
+ else if (add.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "add(): " + add.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = add.arguments[0];
+ //--com.ibm.icu.math.BigDecimal lhs;
+ var lhs;
+ //--int reqdig;
+ var reqdig;
+ //--com.ibm.icu.math.BigDecimal res;
+ var res;
+ //--byte usel[];
+ var usel;
+ //--int usellen;
+ var usellen;
+ //--byte user[];
+ var user;
+ //--int userlen;
+ var userlen;
+ //--int newlen=0;
+ var newlen=0;
+ //--int tlen=0;
+ var tlen=0;
+ //--int mult=0;
+ var mult=0;
+ //--byte t[]=null;
+ var t=null;
+ //--int ia=0;
+ var ia=0;
+ //--int ib=0;
+ var ib=0;
+ //--int ea=0;
+ var ea=0;
+ //int eb=0;
+ var eb=0;
+ //byte ca=0;
+ var ca=0;
+ //--byte cb=0;
+ var cb=0;
+ /* determine requested digits and form */
+ if (set.lostDigits)
+ this.checkdigits(rhs,set.digits);
+ lhs=this; // name for clarity and proxy
+
+ /* Quick exit for add floating 0 */
+ // plus() will optimize to return same object if possible
+ if (lhs.ind==0)
+ if (set.form!=MathContext.prototype.PLAIN)
+ return rhs.plus(set);
+ if (rhs.ind==0)
+ if (set.form!=MathContext.prototype.PLAIN)
+ return lhs.plus(set);
+
+ /* Prepare numbers (round, unless unlimited precision) */
+ reqdig=set.digits; // local copy (heavily used)
+ if (reqdig>0)
+ {
+ if (lhs.mant.length>reqdig)
+ lhs=this.clone(lhs).round(set);
+ if (rhs.mant.length>reqdig)
+ rhs=this.clone(rhs).round(set);
+ // [we could reuse the new LHS for result in this case]
+ }
+
+ res=new BigDecimal(); // build result here
+
+ /* Now see how much we have to pad or truncate lhs or rhs in order
+ to align the numbers. If one number is much larger than the
+ other, then the smaller cannot affect the answer [but we may
+ still need to pad with up to DIGITS trailing zeros]. */
+ // Note sign may be 0 if digits (reqdig) is 0
+ // usel and user will be the byte arrays passed to the adder; we'll
+ // use them on all paths except quick exits
+ usel=lhs.mant;
+ usellen=lhs.mant.length;
+ user=rhs.mant;
+ userlen=rhs.mant.length;
+ {padder:do{/*select*/
+ if (lhs.exp==rhs.exp)
+ {/* no padding needed */
+ // This is the most common, and fastest, path
+ res.exp=lhs.exp;
+ }
+ else if (lhs.exp>rhs.exp)
+ { // need to pad lhs and/or truncate rhs
+ newlen=(usellen+lhs.exp)-rhs.exp;
+ /* If, after pad, lhs would be longer than rhs by digits+1 or
+ more (and digits>0) then rhs cannot affect answer, so we only
+ need to pad up to a length of DIGITS+1. */
+ if (newlen>=((userlen+reqdig)+1))
+ if (reqdig>0)
+ {
+ // LHS is sufficient
+ res.mant=usel;
+ res.exp=lhs.exp;
+ res.ind=lhs.ind;
+ if (usellenBigDecimal to another, using unlimited
+ * precision.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the comparison.
+ * @return An int whose value is -1, 0, or 1 as
+ * this is numerically less than, equal to,
+ * or greater than rhs.
+ * @see #compareTo(Object)
+ * @stable ICU 2.0
+ */
+
+ //--public int compareTo(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.compareTo(rhs,plainMC);
+ //-- }
+
+ /**
+ * Compares this BigDecimal to another.
+ * int.
+ *
+ *
+ * -1
+ * if the current object is less than the first parameter
+ *
+ * 0
+ * if the current object is equal to the first parameter
+ *
+ * 1
+ * if the current object is greater than the first parameter.
+ * BigDecimal for the right hand side of
+ * the comparison.
+ * @param set The MathContext arithmetic settings.
+ * @return An int whose value is -1, 0, or 1 as
+ * this is numerically less than, equal to,
+ * or greater than rhs.
+ * @see #compareTo(Object)
+ * @stable ICU 2.0
+ */
+
+ //public int compareTo(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function compareTo() {
+ var set;
+ if (compareTo.arguments.length == 2)
+ {
+ set = compareTo.arguments[1];
+ }
+ else if (compareTo.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "compareTo(): " + compareTo.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = compareTo.arguments[0];
+ //--int thislength=0;
+ var thislength=0;
+ //--int i=0;
+ var i=0;
+ //--com.ibm.icu.math.BigDecimal newrhs;
+ var newrhs;
+ // rhs=null will raise NullPointerException, as per Comparable interface
+ if (set.lostDigits)
+ this.checkdigits(rhs,set.digits);
+ // [add will recheck in slowpath cases .. but would report -rhs]
+ if ((this.ind==rhs.ind)&&(this.exp==rhs.exp))
+ {
+ /* sign & exponent the same [very common] */
+ thislength=this.mant.length;
+ if (thislengthBigDecimal whose value is
+ * this/rhs, using fixed point arithmetic.
+ * BigDecimal is rhs,
+ * and the rounding mode is {@link MathContext#ROUND_HALF_UP}.
+ *
+ * The length of the decimal part (the scale) of the result will be
+ * the same as the scale of the current object, if the latter were
+ * formatted without exponential notation.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the division.
+ * @return A plain BigDecimal whose value is
+ * this/rhs, using fixed point arithmetic.
+ * @throws ArithmeticException if rhs is zero.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal divide(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.dodivide('D',rhs,plainMC,-1);
+ //-- }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * this/rhs, using fixed point arithmetic and a
+ * rounding mode.
+ * BigDecimal is rhs,
+ * and the second parameter is this.scale(), and
+ * the third is round.
+ * BigDecimal for the right hand side of
+ * the division.
+ * @param round The int rounding mode to be used for
+ * the division (see the {@link MathContext} class).
+ * @return A plain BigDecimal whose value is
+ * this/rhs, using fixed point arithmetic
+ * and the specified rounding mode.
+ * @throws IllegalArgumentException if round is not a
+ * valid rounding mode.
+ * @throws ArithmeticException if rhs is zero.
+ * @throws ArithmeticException if round is {@link
+ * MathContext#ROUND_UNNECESSARY} and
+ * this.scale() is insufficient to
+ * represent the result exactly.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal divide(com.ibm.icu.math.BigDecimal rhs,int round){
+ //-- com.ibm.icu.math.MathContext set;
+ //-- set=new com.ibm.icu.math.MathContext(0,com.ibm.icu.math.MathContext.PLAIN,false,round); // [checks round, too]
+ //-- return this.dodivide('D',rhs,set,-1); // take scale from LHS
+ //-- }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * this/rhs, using fixed point arithmetic and a
+ * given scale and rounding mode.
+ * BigDecimal is rhs,
+ * new MathContext(0, MathContext.PLAIN, false, round),
+ * except that the length of the decimal part (the scale) to be used
+ * for the result is explicit rather than being taken from
+ * this.
+ * BigDecimal for the right hand side of
+ * the division.
+ * @param scale The int scale to be used for the result.
+ * @param round The int rounding mode to be used for
+ * the division (see the {@link MathContext} class).
+ * @return A plain BigDecimal whose value is
+ * this/rhs, using fixed point arithmetic
+ * and the specified rounding mode.
+ * @throws IllegalArgumentException if round is not a
+ * valid rounding mode.
+ * @throws ArithmeticException if rhs is zero.
+ * @throws ArithmeticException if scale is negative.
+ * @throws ArithmeticException if round is {@link
+ * MathContext#ROUND_UNNECESSARY} and scale
+ * is insufficient to represent the result exactly.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal divide(com.ibm.icu.math.BigDecimal rhs,int scale,int round){
+ //-- com.ibm.icu.math.MathContext set;
+ //-- if (scale<0)
+ //-- throw new java.lang.ArithmeticException("Negative scale:"+" "+scale);
+ //-- set=new com.ibm.icu.math.MathContext(0,com.ibm.icu.math.MathContext.PLAIN,false,round); // [checks round]
+ //-- return this.dodivide('D',rhs,set,scale);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is this/rhs.
+ * /) operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a BigDecimal object.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the division.
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * this/rhs.
+ * @throws ArithmeticException if rhs is zero.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal divide(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function divide() {
+ var set;
+ var scale = -1;
+ if (divide.arguments.length == 2)
+ {
+ if (typeof divide.arguments[1] == 'number')
+ {
+ set=new MathContext(0,MathContext.prototype.PLAIN,false,divide.arguments[1]); // [checks round, too]
+ }
+ else
+ {
+ set = divide.arguments[1];
+ }
+ }
+ else if (divide.arguments.length == 3)
+ {
+ scale = divide.arguments[1];
+ if (scale<0)
+ throw "divide(): Negative scale: "+scale;
+ set=new MathContext(0,MathContext.prototype.PLAIN,false,divide.arguments[2]); // [checks round]
+ }
+ else if (divide.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "divide(): " + divide.arguments.length + " arguments given; expected between 1 and 3";
+ }
+ var rhs = divide.arguments[0];
+ return this.dodivide('D',rhs,set,scale);
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is the integer
+ * part of this/rhs.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the integer division.
+ * @return A BigDecimal whose value is the integer
+ * part of this/rhs.
+ * @throws ArithmeticException if rhs is zero.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal divideInteger(com.ibm.icu.math.BigDecimal rhs){
+ //-- // scale 0 to drop .000 when plain
+ //-- return this.dodivide('I',rhs,plainMC,0);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is the integer
+ * part of this/rhs.
+ * BigDecimal object.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the integer division.
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is the integer
+ * part of this/rhs.
+ * @throws ArithmeticException if rhs is zero.
+ * @throws ArithmeticException if the result will not fit in the
+ * number of digits specified for the context.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal divideInteger(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function divideInteger() {
+ var set;
+ if (divideInteger.arguments.length == 2)
+ {
+ set = divideInteger.arguments[1];
+ }
+ else if (divideInteger.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "divideInteger(): " + divideInteger.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = divideInteger.arguments[0];
+ // scale 0 to drop .000 when plain
+ return this.dodivide('I',rhs,set,0);
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * the maximum of this and rhs.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the comparison.
+ * @return A BigDecimal whose value is
+ * the maximum of this and rhs.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal max(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.max(rhs,plainMC);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is
+ * the maximum of this and rhs.
+ * 1 or
+ * 0, then the result of calling the
+ * {@link #plus(MathContext)} method on the current object (using the
+ * same MathContext parameter) is returned.
+ * Otherwise, the result of calling the {@link #plus(MathContext)}
+ * method on the first parameter object (using the same
+ * MathContext parameter) is returned.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the comparison.
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * the maximum of this and rhs.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal max(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function max() {
+ var set;
+ if (max.arguments.length == 2)
+ {
+ set = max.arguments[1];
+ }
+ else if (max.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "max(): " + max.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = max.arguments[0];
+ if ((this.compareTo(rhs,set))>=0)
+ return this.plus(set);
+ else
+ return rhs.plus(set);
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * the minimum of this and rhs.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the comparison.
+ * @return A BigDecimal whose value is
+ * the minimum of this and rhs.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal min(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.min(rhs,plainMC);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is
+ * the minimum of this and rhs.
+ * -1 or
+ * 0, then the result of calling the
+ * {@link #plus(MathContext)} method on the current object (using the
+ * same MathContext parameter) is returned.
+ * Otherwise, the result of calling the {@link #plus(MathContext)}
+ * method on the first parameter object (using the same
+ * MathContext parameter) is returned.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the comparison.
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * the minimum of this and rhs.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal min(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function min() {
+ var set;
+ if (min.arguments.length == 2)
+ {
+ set = min.arguments[1];
+ }
+ else if (min.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "min(): " + min.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = min.arguments[0];
+ if ((this.compareTo(rhs,set))<=0)
+ return this.plus(set);
+ else
+ return rhs.plus(set);
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * this*rhs, using fixed point arithmetic.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ * BigDecimal for the right hand side of
+ * the multiplication.
+ * @return A BigDecimal whose value is
+ * this*rhs, using fixed point arithmetic.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal multiply(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.multiply(rhs,plainMC);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is this*rhs.
+ * *) operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a BigDecimal object.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the multiplication.
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * this*rhs.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal multiply(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function multiply() {
+ var set;
+ if (multiply.arguments.length == 2)
+ {
+ set = multiply.arguments[1];
+ }
+ else if (multiply.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "multiply(): " + multiply.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = multiply.arguments[0];
+ //--com.ibm.icu.math.BigDecimal lhs;
+ var lhs;
+ //--int padding;
+ var padding;
+ //--int reqdig;
+ var reqdig;
+ //--byte multer[]=null;
+ var multer=null;
+ //--byte multand[]=null;
+ var multand=null;
+ //--int multandlen;
+ var multandlen;
+ //--int acclen=0;
+ var acclen=0;
+ //--com.ibm.icu.math.BigDecimal res;
+ var res;
+ //--byte acc[];
+ var acc;
+ //--int n=0;
+ var n=0;
+ //--byte mult=0;
+ var mult=0;
+ if (set.lostDigits)
+ this.checkdigits(rhs,set.digits);
+ lhs=this; // name for clarity and proxy
+
+ /* Prepare numbers (truncate, unless unlimited precision) */
+ padding=0; // trailing 0's to add
+ reqdig=set.digits; // local copy
+ if (reqdig>0)
+ {
+ if (lhs.mant.length>reqdig)
+ lhs=this.clone(lhs).round(set);
+ if (rhs.mant.length>reqdig)
+ rhs=this.clone(rhs).round(set);
+ // [we could reuse the new LHS for result in this case]
+ }
+ else
+ {/* unlimited */
+ // fixed point arithmetic will want every trailing 0; we add these
+ // after the calculation rather than before, for speed.
+ if (lhs.exp>0)
+ padding=padding+lhs.exp;
+ if (rhs.exp>0)
+ padding=padding+rhs.exp;
+ }
+
+ // For best speed, as in DMSRCN, we use the shorter number as the
+ // multiplier and the longer as the multiplicand.
+ // 1999.12.22: We used to special case when the result would fit in
+ // a long, but with Java 1.3 this gave no advantage.
+ if (lhs.mant.lengthBigDecimal whose value is
+ * -this.
+ * new MathContext(0, MathContext.PLAIN).
+ * this.scale()
+ *
+ *
+ * @return A BigDecimal whose value is
+ * -this.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal negate(){
+ //-- return this.negate(plainMC);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is -this.
+ * -) operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a BigDecimal object.
+ *
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * -this.
+ * @stable ICU 2.0
+ */
+
+ //public com.ibm.icu.math.BigDecimal negate(com.ibm.icu.math.MathContext set){
+ function negate() {
+ var set;
+ if (negate.arguments.length == 1)
+ {
+ set = negate.arguments[0];
+ }
+ else if (negate.arguments.length == 0)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "negate(): " + negate.arguments.length + " arguments given; expected 0 or 1";
+ }
+ //--com.ibm.icu.math.BigDecimal res;
+ var res;
+ // Originally called minus(), changed to matched Java precedents
+ // This simply clones, flips the sign, and possibly rounds
+ if (set.lostDigits)
+ this.checkdigits(null,set.digits);
+ res=this.clone(this); // safe copy
+ res.ind=-res.ind;
+ return res.finish(set,false);
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * +this.
+ * Note that this is not necessarily a
+ * plain BigDecimal, but the result will always be.
+ * new MathContext(0, MathContext.PLAIN).
+ * this.scale()
+ *
+ * @return A BigDecimal whose value is
+ * +this.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal plus(){
+ //-- return this.plus(plainMC);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is
+ * +this.
+ * +) operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a BigDecimal object.
+ * MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * +this.
+ * @stable ICU 2.0
+ */
+
+ //public com.ibm.icu.math.BigDecimal plus(com.ibm.icu.math.MathContext set){
+ function plus() {
+ var set;
+ if (plus.arguments.length == 1)
+ {
+ set = plus.arguments[0];
+ }
+ else if (plus.arguments.length == 0)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "plus(): " + plus.arguments.length + " arguments given; expected 0 or 1";
+ }
+ // This clones and forces the result to the new settings
+ // May return same object
+ if (set.lostDigits)
+ this.checkdigits(null,set.digits);
+ // Optimization: returns same object for some common cases
+ if (set.form==MathContext.prototype.PLAIN)
+ if (this.form==MathContext.prototype.PLAIN)
+ {
+ if (this.mant.length<=set.digits)
+ return this;
+ if (set.digits==0)
+ return this;
+ }
+ return this.clone(this).finish(set,false);
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * this**rhs, using fixed point arithmetic.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ * this will be
+ * raised; it must be in the range 0 through 999999999, and must
+ * have a decimal part of zero. Note that these restrictions may be
+ * removed in the future, so they should not be used as a test for a
+ * whole number.
+ * MathContext is used and so the result would then
+ * always be 0.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the operation (the power).
+ * @return A BigDecimal whose value is
+ * this**rhs, using fixed point arithmetic.
+ * @throws ArithmeticException if rhs is out of range or
+ * is not a whole number.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal pow(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.pow(rhs,plainMC);
+ //-- }
+ // The name for this method is inherited from the precedent set by the
+ // BigInteger and Math classes.
+
+ /**
+ * Returns a BigDecimal whose value is this**rhs.
+ * **) operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a BigDecimal object.
+ * this
+ * will be raised; it must be in the range -999999999 through
+ * 999999999, and must have a decimal part of zero. Note that these
+ * restrictions may be removed in the future, so they should not be
+ * used as a test for a whole number.
+ * digits setting of the MathContext
+ * parameter is 0, the power must be zero or positive.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the operation (the power).
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * this**rhs.
+ * @throws ArithmeticException if rhs is out of range or
+ * is not a whole number.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal pow(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function pow() {
+ var set;
+ if (pow.arguments.length == 2)
+ {
+ set = pow.arguments[1];
+ }
+ else if (pow.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "pow(): " + pow.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = pow.arguments[0];
+ //--int n;
+ var n;
+ //--com.ibm.icu.math.BigDecimal lhs;
+ var lhs;
+ //--int reqdig;
+ var reqdig;
+ //-- int workdigits=0;
+ var workdigits=0;
+ //--int L=0;
+ var L=0;
+ //--com.ibm.icu.math.MathContext workset;
+ var workset;
+ //--com.ibm.icu.math.BigDecimal res;
+ var res;
+ //--boolean seenbit;
+ var seenbit;
+ //--int i=0;
+ var i=0;
+ if (set.lostDigits)
+ this.checkdigits(rhs,set.digits);
+ n=rhs.intcheck(this.MinArg,this.MaxArg); // check RHS by the rules
+ lhs=this; // clarified name
+
+ reqdig=set.digits; // local copy (heavily used)
+ if (reqdig==0)
+ {
+ if (rhs.ind==this.isneg)
+ //--throw new java.lang.ArithmeticException("Negative power:"+" "+rhs.toString());
+ throw "pow(): Negative power: " + rhs.toString();
+ workdigits=0;
+ }
+ else
+ {/* non-0 digits */
+ if ((rhs.mant.length+rhs.exp)>reqdig)
+ //--throw new java.lang.ArithmeticException("Too many digits:"+" "+rhs.toString());
+ throw "pow(): Too many digits: " + rhs.toString();
+
+ /* Round the lhs to DIGITS if need be */
+ if (lhs.mant.length>reqdig)
+ lhs=this.clone(lhs).round(set);
+
+ /* L for precision calculation [see ANSI X3.274-1996] */
+ L=rhs.mant.length+rhs.exp; // length without decimal zeros/exp
+ workdigits=(reqdig+L)+1; // calculate the working DIGITS
+ }
+
+ /* Create a copy of set for working settings */
+ // Note: no need to check for lostDigits again.
+ // 1999.07.17 Note: this construction must follow RHS check
+ workset=new MathContext(workdigits,set.form,false,set.roundingMode);
+
+ res=this.ONE; // accumulator
+ if (n==0)
+ return res; // x**0 == 1
+ if (n<0)
+ n=-n; // [rhs.ind records the sign]
+ seenbit=false; // set once we've seen a 1-bit
+ {i=1;i:for(;;i++){ // for each bit [top bit ignored]
+ //n=n+n; // shift left 1 bit
+ n<<=1;
+ if (n<0)
+ { // top bit is set
+ seenbit=true; // OK, we're off
+ res=res.multiply(lhs,workset); // acc=acc*x
+ }
+ if (i==31)
+ break i; // that was the last bit
+ if ((!seenbit))
+ continue i; // we don't have to square 1
+ res=res.multiply(res,workset); // acc=acc*acc [square]
+ }
+ }/*i*/ // 32 bits
+ if (rhs.ind<0) // was a **-n [hence digits>0]
+ res=this.ONE.divide(res,workset); // .. so acc=1/acc
+ return res.finish(set,true); // round and strip [original digits]
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * the remainder of this/rhs, using fixed point arithmetic.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ * BigDecimal for the right hand side of
+ * the remainder operation.
+ * @return A BigDecimal whose value is the remainder
+ * of this/rhs, using fixed point arithmetic.
+ * @throws ArithmeticException if rhs is zero.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal remainder(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.dodivide('R',rhs,plainMC,-1);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is the remainder of
+ * this/rhs.
+ * BigDecimal object.
+ * BigDecimal for the right hand side of
+ * the remainder operation.
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is the remainder
+ * of this+rhs.
+ * @throws ArithmeticException if rhs is zero.
+ * @throws ArithmeticException if the integer part of the result will
+ * not fit in the number of digits specified for the
+ * context.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal remainder(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function remainder() {
+ var set;
+ if (remainder.arguments.length == 2)
+ {
+ set = remainder.arguments[1];
+ }
+ else if (remainder.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "remainder(): " + remainder.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = remainder.arguments[0];
+ return this.dodivide('R',rhs,set,-1);
+ }
+
+ /**
+ * Returns a plain BigDecimal whose value is
+ * this-rhs, using fixed point arithmetic.
+ * BigDecimal is rhs,
+ * and the context is new MathContext(0, MathContext.PLAIN).
+ * BigDecimal for the right hand side of
+ * the subtraction.
+ * @return A BigDecimal whose value is
+ * this-rhs, using fixed point arithmetic.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal subtract(com.ibm.icu.math.BigDecimal rhs){
+ //-- return this.subtract(rhs,plainMC);
+ //-- }
+
+ /**
+ * Returns a BigDecimal whose value is this-rhs.
+ * -) operator
+ * (as defined in the decimal documentation, see {@link BigDecimal
+ * class header}),
+ * and returns the result as a BigDecimal object.
+ *
+ * @param rhs The BigDecimal for the right hand side of
+ * the subtraction.
+ * @param set The MathContext arithmetic settings.
+ * @return A BigDecimal whose value is
+ * this-rhs.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal subtract(com.ibm.icu.math.BigDecimal rhs,com.ibm.icu.math.MathContext set){
+ function subtract() {
+ var set;
+ if (subtract.arguments.length == 2)
+ {
+ set = subtract.arguments[1];
+ }
+ else if (subtract.arguments.length == 1)
+ {
+ set = this.plainMC;
+ }
+ else
+ {
+ throw "subtract(): " + subtract.arguments.length + " arguments given; expected 1 or 2";
+ }
+ var rhs = subtract.arguments[0];
+ //--com.ibm.icu.math.BigDecimal newrhs;
+ var newrhs;
+ if (set.lostDigits)
+ this.checkdigits(rhs,set.digits);
+ // [add will recheck .. but would report -rhs]
+ /* carry out the subtraction */
+ // we could fastpath -0, but it is too rare.
+ newrhs=this.clone(rhs); // safe copy
+ newrhs.ind=-newrhs.ind; // prepare to subtract
+ return this.add(newrhs,set); // arithmetic
+ }
+
+ /* ---------------------------------------------------------------- */
+ /* Other methods */
+ /* ---------------------------------------------------------------- */
+
+ /**
+ * Converts this BigDecimal to a byte.
+ * If the BigDecimal has a non-zero decimal part or is
+ * out of the possible range for a byte (8-bit signed
+ * integer) result then an ArithmeticException is thrown.
+ *
+ * @return A byte equal in value to this.
+ * @throws ArithmeticException if this has a non-zero
+ * decimal part, or will not fit in a byte.
+ * @stable ICU 2.0
+ */
+
+ //--public byte byteValueExact(){
+ //-- int num;
+ //-- num=this.intValueExact(); // will check decimal part too
+ //-- if ((num>127)|(num<(-128)))
+ //-- throw new java.lang.ArithmeticException("Conversion overflow:"+" "+this.toString());
+ //-- return (byte)num;
+ //-- }
+
+ /**
+ * Compares this BigDecimal with the value of the parameter.
+ * null, or is not an instance of the
+ * BigDecimal type, an exception is thrown.
+ * Otherwise, the parameter is cast to type BigDecimal
+ * and the result of the {@link #compareTo(BigDecimal)} method,
+ * using the cast parameter, is returned.
+ * MathContext is needed for the comparison.
+ *
+ * @param rhs The Object for the right hand side of
+ * the comparison.
+ * @return An int whose value is -1, 0, or 1 as
+ * this is numerically less than, equal to,
+ * or greater than rhs.
+ * @throws ClassCastException if rhs cannot be cast to
+ * a BigDecimal object.
+ * @see #compareTo(BigDecimal)
+ * @stable ICU 2.0
+ */
+
+ //--public int compareTo(java.lang.Object rhsobj){
+ //-- // the cast in the next line will raise ClassCastException if necessary
+ //-- return compareTo((com.ibm.icu.math.BigDecimal)rhsobj,plainMC);
+ //-- }
+
+ /**
+ * Converts this BigDecimal to a double.
+ * If the BigDecimal is out of the possible range for a
+ * double (64-bit signed floating point) result then an
+ * ArithmeticException is thrown.
+ * BigDecimal as a String and then
+ * converting it using the Double(String) constructor;
+ * this can result in values of Double.NEGATIVE_INFINITY
+ * or Double.POSITIVE_INFINITY.
+ *
+ * @return A double corresponding to this.
+ * @stable ICU 2.0
+ */
+
+ //--public double doubleValue(){
+ //-- // We go via a String [as does BigDecimal in JDK 1.2]
+ //-- // Next line could possibly raise NumberFormatException
+ //-- return java.lang.Double.valueOf(this.toString()).doubleValue();
+ //-- }
+
+ /**
+ * Compares this BigDecimal with rhs for
+ * equality.
+ * null, or is not an instance of the
+ * BigDecimal type, or is not exactly equal to the current
+ * BigDecimal object, then false is returned.
+ * Otherwise, true is returned.
+ * String
+ * representations of the BigDecimal numbers are
+ * identical (they have the same characters in the same sequence).
+ * Object for the right hand side of
+ * the comparison.
+ * @return A boolean whose value true if and
+ * only if the operands have identical string representations.
+ * @throws ClassCastException if rhs cannot be cast to
+ * a BigDecimal object.
+ * @stable ICU 2.0
+ * @see #compareTo(Object)
+ * @see #compareTo(BigDecimal)
+ * @see #compareTo(BigDecimal, MathContext)
+ */
+
+ //--public boolean equals(java.lang.Object obj){
+ function equals(obj) {
+ //--com.ibm.icu.math.BigDecimal rhs;
+ var rhs;
+ //--int i=0;
+ var i=0;
+ //--char lca[]=null;
+ var lca=null;
+ //--char rca[]=null;
+ var rca=null;
+ // We are equal iff toString of both are exactly the same
+ if (obj==null)
+ return false; // not equal
+ if ((!(((obj instanceof BigDecimal)))))
+ return false; // not a decimal
+ rhs=obj; // cast; we know it will work
+ if (this.ind!=rhs.ind)
+ return false; // different signs never match
+ if (((this.mant.length==rhs.mant.length)&&(this.exp==rhs.exp))&&(this.form==rhs.form))
+
+ { // mantissas say all
+ // here with equal-length byte arrays to compare
+ {var $8=this.mant.length;i=0;i:for(;$8>0;$8--,i++){
+ if (this.mant[i]!=rhs.mant[i])
+ return false;
+ }
+ }/*i*/
+ }
+ else
+ { // need proper layout
+ lca=this.layout(); // layout to character array
+ rca=rhs.layout();
+ if (lca.length!=rca.length)
+ return false; // mismatch
+ // here with equal-length character arrays to compare
+ {var $9=lca.length;i=0;i:for(;$9>0;$9--,i++){
+ if (lca[i]!=rca[i])
+ return false;
+ }
+ }/*i*/
+ }
+ return true; // arrays have identical content
+ }
+
+ /**
+ * Converts this BigDecimal to a float.
+ * If the BigDecimal is out of the possible range for a
+ * float (32-bit signed floating point) result then an
+ * ArithmeticException is thrown.
+ * BigDecimal as a String and then
+ * converting it using the Float(String) constructor;
+ * this can result in values of Float.NEGATIVE_INFINITY
+ * or Float.POSITIVE_INFINITY.
+ *
+ * @return A float corresponding to this.
+ * @stable ICU 2.0
+ */
+
+ //--public float floatValue(){
+ //-- return java.lang.Float.valueOf(this.toString()).floatValue();
+ //-- }
+
+ /**
+ * Returns the String representation of this
+ * BigDecimal, modified by layout parameters.
+ * DecimalFormat, that
+ * can apply locale-sensitive editing of the result. The level of
+ * formatting that it provides is a necessary part of the BigDecimal
+ * class as it is sensitive to and must follow the calculation and
+ * rounding rules for BigDecimal arithmetic.
+ * However, if the function is provided elsewhere, it may be removed
+ * from this class.
+ * format method
+ * are all of type int.
+ * A value of -1 for any parameter indicates that the default action
+ * or value for that parameter should be used.
+ * before and after,
+ * specify the number of characters to be used for the integer part
+ * and decimal part of the result respectively. Exponential notation
+ * is not used. If either parameter is -1 (which indicates the default
+ * action), the number of characters used will be exactly as many as
+ * are needed for that part.
+ * before must be a positive number; if it is larger than
+ * is needed to contain the integer part, that part is padded on the
+ * left with blanks to the requested length. If before is
+ * not large enough to contain the integer part of the number
+ * (including the sign, for negative numbers) an exception is thrown.
+ * after must be a non-negative number; if it is not the
+ * same size as the decimal part of the number, the number will be
+ * rounded (or extended with zeros) to fit. Specifying 0 for
+ * after will cause the number to be rounded to an
+ * integer (that is, it will have no decimal part or decimal point).
+ * The rounding method will be the default,
+ * MathContext.ROUND_HALF_UP.
+ * int specifying the number of places
+ * before the decimal point. Use -1 for 'as many as
+ * are needed'.
+ * @param after The int specifying the number of places
+ * after the decimal point. Use -1 for 'as many as are
+ * needed'.
+ * @return A String representing this
+ * BigDecimal, laid out according to the
+ * specified parameters
+ * @throws ArithmeticException if the number cannot be laid out as
+ * requested.
+ * @throws IllegalArgumentException if a parameter is out of range.
+ * @stable ICU 2.0
+ * @see #toString
+ * @see #toCharArray
+ */
+
+ //--public java.lang.String format(int before,int after){
+ //-- return format(before,after,-1,-1,com.ibm.icu.math.MathContext.SCIENTIFIC,ROUND_HALF_UP);
+ //-- }
+
+ /**
+ * Returns the String representation of this
+ * BigDecimal, modified by layout parameters and allowing
+ * exponential notation.
+ * DecimalFormat, that
+ * can apply locale-sensitive editing of the result. The level of
+ * formatting that it provides is a necessary part of the BigDecimal
+ * class as it is sensitive to and must follow the calculation and
+ * rounding rules for BigDecimal arithmetic.
+ * However, if the function is provided elsewhere, it may be removed
+ * from this class.
+ * int.
+ * A value of -1 for any parameter indicates that the default action
+ * or value for that parameter should be used.
+ * before and
+ * after) specify the number of characters to be used for
+ * the integer part and decimal part of the result respectively, as
+ * defined for {@link #format(int,int)}.
+ * If either of these is -1 (which indicates the default action), the
+ * number of characters used will be exactly as many as are needed for
+ * that part.
+ * explaces, exdigits,
+ * and exform) control the exponent part of the result.
+ * As before, the default action for any of these parameters may be
+ * selected by using the value -1.
+ * explaces must be a positive number; it sets the number
+ * of places (digits after the sign of the exponent) to be used for
+ * any exponent part, the default (when explaces is -1)
+ * being to use as many as are needed.
+ * If explaces is not -1, space is always reserved for
+ * an exponent; if one is not needed (for example, if the exponent
+ * will be 0) then explaces+2 blanks are appended to the
+ * result.
+ *
+ * If explaces is not -1 and is not large enough to
+ * contain the exponent, an exception is thrown.
+ * exdigits sets the trigger point for use of exponential
+ * notation. If, before any rounding, the number of places needed
+ * before the decimal point exceeds exdigits, or if the
+ * absolute value of the result is less than 0.000001,
+ * then exponential form will be used, provided that
+ * exdigits was specified.
+ * When exdigits is -1, exponential notation will never
+ * be used. If 0 is specified for exdigits, exponential
+ * notation is always used unless the exponent would be 0.
+ * exform sets the form for exponential notation (if
+ * needed).
+ * It may be either {@link MathContext#SCIENTIFIC} or
+ * {@link MathContext#ENGINEERING}.
+ * If the latter, engineering, form is requested, up to three digits
+ * (plus sign, if negative) may be needed for the integer part of the
+ * result (before). Otherwise, only one digit (plus
+ * sign, if negative) is needed.
+ * exround, selects the
+ * rounding algorithm to be used, and must be one of the values
+ * indicated by a public constant in the {@link MathContext} class
+ * whose name starts with ROUND_.
+ * The default (ROUND_HALF_UP) may also be selected by
+ * using the value -1, as before.
+ * MathContext.ROUND_UNNECESSARY may be
+ * used to detect whether non-zero digits are discarded -- if
+ * exround has this value than if non-zero digits would
+ * be discarded (rounded) during formatting then an
+ * ArithmeticException is thrown.
+ *
+ * @param before The int specifying the number of places
+ * before the decimal point.
+ * Use -1 for 'as many as are needed'.
+ * @param after The int specifying the number of places
+ * after the decimal point.
+ * Use -1 for 'as many as are needed'.
+ * @param explaces The int specifying the number of places
+ * to be used for any exponent.
+ * Use -1 for 'as many as are needed'.
+ * @param exdigits The int specifying the trigger
+ * (digits before the decimal point) which if
+ * exceeded causes exponential notation to be used.
+ * Use 0 to force exponential notation.
+ * Use -1 to force plain notation (no exponential
+ * notation).
+ * @param exform The int specifying the form of
+ * exponential notation to be used
+ * ({@link MathContext#SCIENTIFIC} or
+ * {@link MathContext#ENGINEERING}).
+ * @param exround The int specifying the rounding mode
+ * to use.
+ * Use -1 for the default, {@link MathContext#ROUND_HALF_UP}.
+ * @return A String representing this
+ * BigDecimal, laid out according to the
+ * specified parameters
+ * @throws ArithmeticException if the number cannot be laid out as
+ * requested.
+ * @throws IllegalArgumentException if a parameter is out of range.
+ * @see #toString
+ * @see #toCharArray
+ * @stable ICU 2.0
+ */
+
+ //--public java.lang.String format(int before,int after,int explaces,int exdigits,int exformint,int exround){
+ function format() {
+ var explaces;
+ var exdigits;
+ var exformint;
+ var exround;
+ if (format.arguments.length == 6)
+ {
+ explaces = format.arguments[2];
+ exdigits = format.arguments[3];
+ exformint = format.arguments[4];
+ exround = format.arguments[5];
+ }
+ else if (format.arguments.length == 2)
+ {
+ explaces = -1;
+ exdigits = -1;
+ exformint = MathContext.prototype.SCIENTIFIC;
+ exround = this.ROUND_HALF_UP;
+ }
+ else
+ {
+ throw "format(): " + format.arguments.length + " arguments given; expected 2 or 6";
+ }
+ var before = format.arguments[0];
+ var after = format.arguments[1];
+ //--com.ibm.icu.math.BigDecimal num;
+ var num;
+ //--int mag=0;
+ var mag=0;
+ //--int thisafter=0;
+ var thisafter=0;
+ //--int lead=0;
+ var lead=0;
+ //--byte newmant[]=null;
+ var newmant=null;
+ //--int chop=0;
+ var chop=0;
+ //--int need=0;
+ var need=0;
+ //--int oldexp=0;
+ var oldexp=0;
+ //--char a[];
+ var a;
+ //--int p=0;
+ var p=0;
+ //--char newa[]=null;
+ var newa=null;
+ //--int i=0;
+ var i=0;
+ //--int places=0;
+ var places=0;
+
+
+ /* Check arguments */
+ if ((before<(-1))||(before==0))
+ this.badarg("format",1,before);
+ if (after<(-1))
+ this.badarg("format",2,after);
+ if ((explaces<(-1))||(explaces==0))
+ this.badarg("format",3,explaces);
+ if (exdigits<(-1))
+ this.badarg("format",4,exdigits);
+ {/*select*/
+ if (exformint==MathContext.prototype.SCIENTIFIC)
+ {}
+ else if (exformint==MathContext.prototype.ENGINEERING)
+ {}
+ else if (exformint==(-1))
+ exformint=MathContext.prototype.SCIENTIFIC;
+ // note PLAIN isn't allowed
+ else{
+ this.badarg("format",5,exformint);
+ }
+ }
+ // checking the rounding mode is done by trying to construct a
+ // MathContext object with that mode; it will fail if bad
+ if (exround!=this.ROUND_HALF_UP)
+ {try{ // if non-default...
+ if (exround==(-1))
+ exround=this.ROUND_HALF_UP;
+ else
+ new MathContext(9,MathContext.prototype.SCIENTIFIC,false,exround);
+ }
+ catch ($10){
+ this.badarg("format",6,exround);
+ }}
+
+ num=this.clone(this); // make private copy
+
+ /* Here:
+ num is BigDecimal to format
+ before is places before point [>0]
+ after is places after point [>=0]
+ explaces is exponent places [>0]
+ exdigits is exponent digits [>=0]
+ exformint is exponent form [one of two]
+ exround is rounding mode [one of eight]
+ 'before' through 'exdigits' are -1 if not specified
+ */
+
+ /* determine form */
+ {setform:do{/*select*/
+ if (exdigits==(-1))
+ num.form=MathContext.prototype.PLAIN;
+ else if (num.ind==this.iszero)
+ num.form=MathContext.prototype.PLAIN;
+ else{
+ // determine whether triggers
+ mag=num.exp+num.mant.length;
+ if (mag>exdigits)
+ num.form=exformint;
+ else
+ if (mag<(-5))
+ num.form=exformint;
+ else
+ num.form=MathContext.prototype.PLAIN;
+ }
+ }while(false);}/*setform*/
+
+ /* If 'after' was specified then we may need to adjust the
+ mantissa. This is a little tricky, as we must conform to the
+ rules of exponential layout if necessary (e.g., we cannot end up
+ with 10.0 if scientific). */
+ if (after>=0)
+ {setafter:for(;;){
+ // calculate the current after-length
+ {/*select*/
+ if (num.form==MathContext.prototype.PLAIN)
+ thisafter=-num.exp; // has decimal part
+ else if (num.form==MathContext.prototype.SCIENTIFIC)
+ thisafter=num.mant.length-1;
+ else{ // engineering
+ lead=(((num.exp+num.mant.length)-1))%3; // exponent to use
+ if (lead<0)
+ lead=3+lead; // negative exponent case
+ lead++; // number of leading digits
+ if (lead>=num.mant.length)
+ thisafter=0;
+ else
+ thisafter=num.mant.length-lead;
+ }
+ }
+ if (thisafter==after)
+ break setafter; // we're in luck
+ if (thisafterBigDecimal.
+ * This hashcode is suitable for use by the
+ * java.util.Hashtable class.
+ * BigDecimal objects are only guaranteed
+ * to produce the same hashcode if they are exactly equal (that is,
+ * the String representations of the
+ * BigDecimal numbers are identical -- they have the same
+ * characters in the same sequence).
+ *
+ * @return An int that is the hashcode for this.
+ * @stable ICU 2.0
+ */
+
+ //--public int hashCode(){
+ //-- // Maybe calculate ourselves, later. If so, note that there can be
+ //-- // more than one internal representation for a given toString() result.
+ //-- return this.toString().hashCode();
+ //-- }
+
+ /**
+ * Converts this BigDecimal to an int.
+ * If the BigDecimal has a non-zero decimal part it is
+ * discarded. If the BigDecimal is out of the possible
+ * range for an int (32-bit signed integer) result then
+ * only the low-order 32 bits are used. (That is, the number may be
+ * decapitated.) To avoid unexpected errors when these
+ * conditions occur, use the {@link #intValueExact} method.
+ *
+ * @return An int converted from this,
+ * truncated and decapitated if necessary.
+ * @stable ICU 2.0
+ */
+
+ //--public int intValue(){
+ //-- return toBigInteger().intValue();
+ //-- }
+
+ /**
+ * Converts this BigDecimal to an int.
+ * If the BigDecimal has a non-zero decimal part or is
+ * out of the possible range for an int (32-bit signed
+ * integer) result then an ArithmeticException is thrown.
+ *
+ * @return An int equal in value to this.
+ * @throws ArithmeticException if this has a non-zero
+ * decimal part, or will not fit in an
+ * int.
+ * @stable ICU 2.0
+ */
+
+ //--public int intValueExact(){
+ function intValueExact() {
+ //--int lodigit;
+ var lodigit;
+ //--int useexp=0;
+ var useexp=0;
+ //--int result;
+ var result;
+ //--int i=0;
+ var i=0;
+ //--int topdig=0;
+ var topdig=0;
+ // This does not use longValueExact() as the latter can be much
+ // slower.
+ // intcheck (from pow) relies on this to check decimal part
+ if (this.ind==this.iszero)
+ return 0; // easy, and quite common
+ /* test and drop any trailing decimal part */
+ lodigit=this.mant.length-1;
+ if (this.exp<0)
+ {
+ lodigit=lodigit+this.exp; // reduces by -(-exp)
+ /* all decimal places must be 0 */
+ if ((!(this.allzero(this.mant,lodigit+1))))
+ throw "intValueExact(): Decimal part non-zero: " + this.toString();
+ if (lodigit<0)
+ return 0; // -1BigDecimal to a long.
+ * If the BigDecimal has a non-zero decimal part it is
+ * discarded. If the BigDecimal is out of the possible
+ * range for a long (64-bit signed integer) result then
+ * only the low-order 64 bits are used. (That is, the number may be
+ * decapitated.) To avoid unexpected errors when these
+ * conditions occur, use the {@link #longValueExact} method.
+ *
+ * @return A long converted from this,
+ * truncated and decapitated if necessary.
+ * @stable ICU 2.0
+ */
+
+ //--public long longValue(){
+ //-- return toBigInteger().longValue();
+ //-- }
+
+ /**
+ * Converts this BigDecimal to a long.
+ * If the BigDecimal has a non-zero decimal part or is
+ * out of the possible range for a long (64-bit signed
+ * integer) result then an ArithmeticException is thrown.
+ *
+ * @return A long equal in value to this.
+ * @throws ArithmeticException if this has a non-zero
+ * decimal part, or will not fit in a
+ * long.
+ * @stable ICU 2.0
+ */
+
+ //--public long longValueExact(){
+ //-- int lodigit;
+ //-- int cstart=0;
+ //-- int useexp=0;
+ //-- long result;
+ //-- int i=0;
+ //-- long topdig=0;
+ //-- // Identical to intValueExact except for result=long, and exp>=20 test
+ //-- if (ind==0)
+ //-- return 0; // easy, and quite common
+ //-- lodigit=mant.length-1; // last included digit
+ //-- if (exp<0)
+ //-- {
+ //-- lodigit=lodigit+exp; // -(-exp)
+ //-- /* all decimal places must be 0 */
+ //-- if (lodigit<0)
+ //-- cstart=0;
+ //-- else
+ //-- cstart=lodigit+1;
+ //-- if ((!(allzero(mant,cstart))))
+ //-- throw new java.lang.ArithmeticException("Decimal part non-zero:"+" "+this.toString());
+ //-- if (lodigit<0)
+ //-- return 0; // -1BigDecimal whose decimal point has
+ * been moved to the left by a specified number of positions.
+ * The parameter, n, specifies the number of positions to
+ * move the decimal point.
+ * That is, if n is 0 or positive, the number returned is
+ * given by:
+ *
+ * this.multiply(TEN.pow(new BigDecimal(-n)))
+ *
+ * n may be negative, in which case the method returns
+ * the same result as movePointRight(-n).
+ *
+ * @param n The int specifying the number of places to
+ * move the decimal point leftwards.
+ * @return A BigDecimal derived from
+ * this, with the decimal point moved
+ * n places to the left.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal movePointLeft(int n){
+ function movePointLeft(n) {
+ //--com.ibm.icu.math.BigDecimal res;
+ var res;
+ // very little point in optimizing for shift of 0
+ res=this.clone(this);
+ res.exp=res.exp-n;
+ return res.finish(this.plainMC,false); // finish sets form and checks exponent
+ }
+
+ /**
+ * Returns a plain BigDecimal whose decimal point has
+ * been moved to the right by a specified number of positions.
+ * The parameter, n, specifies the number of positions to
+ * move the decimal point.
+ * That is, if n is 0 or positive, the number returned is
+ * given by:
+ *
+ * this.multiply(TEN.pow(new BigDecimal(n)))
+ *
+ * n may be negative, in which case the method returns
+ * the same result as movePointLeft(-n).
+ *
+ * @param n The int specifying the number of places to
+ * move the decimal point rightwards.
+ * @return A BigDecimal derived from
+ * this, with the decimal point moved
+ * n places to the right.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal movePointRight(int n){
+ function movePointRight(n) {
+ //--com.ibm.icu.math.BigDecimal res;
+ var res;
+ res=this.clone(this);
+ res.exp=res.exp+n;
+ return res.finish(this.plainMC,false);
+ }
+
+ /**
+ * Returns the scale of this BigDecimal.
+ * Returns a non-negative int which is the scale of the
+ * number. The scale is the number of digits in the decimal part of
+ * the number if the number were formatted without exponential
+ * notation.
+ *
+ * @return An int whose value is the scale of this
+ * BigDecimal.
+ * @stable ICU 2.0
+ */
+
+ //--public int scale(){
+ function scale() {
+ if (this.exp>=0)
+ return 0; // scale can never be negative
+ return -this.exp;
+ }
+
+ /**
+ * Returns a plain BigDecimal with a given scale.
+ * BigDecimal then trailing zeros will be added to the
+ * decimal part as necessary.
+ * BigDecimal then trailing digits
+ * will be removed, and in this case an
+ * ArithmeticException is thrown if any discarded digits
+ * are non-zero.
+ * MathContext.ROUND_UNNECESSARY.
+ *
+ * @param scale The int specifying the scale of the
+ * resulting BigDecimal.
+ * @return A plain BigDecimal with the given scale.
+ * @throws ArithmeticException if scale is negative.
+ * @throws ArithmeticException if reducing scale would discard
+ * non-zero digits.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal setScale(int scale){
+ //-- return setScale(scale,ROUND_UNNECESSARY);
+ //-- }
+
+ /**
+ * Returns a plain BigDecimal with a given scale.
+ * BigDecimal then trailing zeros will be added to the
+ * decimal part as necessary.
+ * BigDecimal then trailing digits
+ * will be removed, and the rounding mode given by the second
+ * parameter is used to determine if the remaining digits are
+ * affected by a carry.
+ * In this case, an IllegalArgumentException is thrown if
+ * round is not a valid rounding mode.
+ * round is MathContext.ROUND_UNNECESSARY,
+ * an ArithmeticException is thrown if any discarded
+ * digits are non-zero.
+ *
+ * @param scale The int specifying the scale of the
+ * resulting BigDecimal.
+ * @param round The int rounding mode to be used for
+ * the division (see the {@link MathContext} class).
+ * @return A plain BigDecimal with the given scale.
+ * @throws IllegalArgumentException if round is not a
+ * valid rounding mode.
+ * @throws ArithmeticException if scale is negative.
+ * @throws ArithmeticException if round is
+ * MathContext.ROUND_UNNECESSARY, and
+ * reducing scale would discard non-zero digits.
+ * @stable ICU 2.0
+ */
+
+ //--public com.ibm.icu.math.BigDecimal setScale(int scale,int round){
+ function setScale() {
+ var round;
+ if (setScale.arguments.length == 2)
+ {
+ round = setScale.arguments[1];
+ }
+ else if (setScale.arguments.length == 1)
+ {
+ round = this.ROUND_UNNECESSARY;
+ }
+ else
+ {
+ throw "setScale(): " + setScale.arguments.length + " given; expected 1 or 2";
+ }
+ var scale = setScale.arguments[0];
+ //--int ourscale;
+ var ourscale;
+ //--com.ibm.icu.math.BigDecimal res;
+ var res;
+ //--int padding=0;
+ var padding=0;
+ //--int newlen=0;
+ var newlen=0;
+ // at present this naughtily only checks the round value if it is
+ // needed (used), for speed
+ ourscale=this.scale();
+ if (ourscale==scale) // already correct scale
+ if (this.form==MathContext.prototype.PLAIN) // .. and form
+ return this;
+ res=this.clone(this); // need copy
+ if (ourscale<=scale)
+ { // simply zero-padding/changing form
+ // if ourscale is 0 we may have lots of 0s to add
+ if (ourscale==0)
+ padding=res.exp+scale;
+ else
+ padding=scale-ourscale;
+ res.mant=this.extend(res.mant,res.mant.length+padding);
+ res.exp=-scale; // as requested
+ }
+ else
+ {/* ourscale>scale: shortening, probably */
+ if (scale<0)
+ //--throw new java.lang.ArithmeticException("Negative scale:"+" "+scale);
+ throw "setScale(): Negative scale: " + scale;
+ // [round() will raise exception if invalid round]
+ newlen=res.mant.length-((ourscale-scale)); // [<=0 is OK]
+ res=res.round(newlen,round); // round to required length
+ // This could have shifted left if round (say) 0.9->1[.0]
+ // Repair if so by adding a zero and reducing exponent
+ if (res.exp!=(-scale))
+ {
+ res.mant=this.extend(res.mant,res.mant.length+1);
+ res.exp=res.exp-1;
+ }
+ }
+ res.form=MathContext.prototype.PLAIN; // by definition
+ return res;
+ }
+
+ /**
+ * Converts this BigDecimal to a short.
+ * If the BigDecimal has a non-zero decimal part or is
+ * out of the possible range for a short (16-bit signed
+ * integer) result then an ArithmeticException is thrown.
+ *
+ * @return A short equal in value to this.
+ * @throws ArithmeticException if this has a non-zero
+ * decimal part, or will not fit in a
+ * short.
+ * @stable ICU 2.0
+ */
+
+ //--public short shortValueExact(){
+ //-- int num;
+ //-- num=this.intValueExact(); // will check decimal part too
+ //-- if ((num>32767)|(num<(-32768)))
+ //-- throw new java.lang.ArithmeticException("Conversion overflow:"+" "+this.toString());
+ //-- return (short)num;
+ //-- }
+
+ /**
+ * Returns the sign of this BigDecimal, as an
+ * int.
+ * This returns the signum function value that represents the
+ * sign of this BigDecimal.
+ * That is, -1 if the BigDecimal is negative, 0 if it is
+ * numerically equal to zero, or 1 if it is positive.
+ *
+ * @return An int which is -1 if the
+ * BigDecimal is negative, 0 if it is
+ * numerically equal to zero, or 1 if it is positive.
+ * @stable ICU 2.0
+ */
+
+ //--public int signum(){
+ function signum() {
+ return this.ind; // [note this assumes values for ind.]
+ }
+
+ /**
+ * Converts this BigDecimal to a
+ * java.math.BigDecimal.
+ * BigDecimal were formatted as a plain number without
+ * any rounding or exponent and then the
+ * java.math.BigDecimal(java.lang.String) constructor
+ * were used to construct the result.
+ * com.ibm.icu.math version of the BigDecimal class.
+ * It would not be present in a java.math version.)
+ *
+ * @return The java.math.BigDecimal equal in value
+ * to this BigDecimal.
+ * @stable ICU 2.0
+ */
+
+ //--public java.math.BigDecimal toBigDecimal(){
+ //-- return new java.math.BigDecimal(this.unscaledValue(),this.scale());
+ //-- }
+
+ /**
+ * Converts this BigDecimal to a
+ * java.math.BigInteger.
+ * java.math.BigInteger equal in value
+ * to the integer part of this BigDecimal.
+ * @stable ICU 2.0
+ */
+
+ //--public java.math.BigInteger toBigInteger(){
+ //-- com.ibm.icu.math.BigDecimal res=null;
+ //-- int newlen=0;
+ //-- byte newmant[]=null;
+ //-- {/*select*/
+ //-- if ((exp>=0)&(form==com.ibm.icu.math.MathContext.PLAIN))
+ //-- res=this; // can layout simply
+ //-- else if (exp>=0)
+ //-- {
+ //-- res=clone(this); // safe copy
+ //-- res.form=(byte)com.ibm.icu.math.MathContext.PLAIN; // .. and request PLAIN
+ //-- }
+ //-- else{
+ //-- { // exp<0; scale to be truncated
+ //-- // we could use divideInteger, but we may as well be quicker
+ //-- if (((int)-this.exp)>=this.mant.length)
+ //-- res=ZERO; // all blows away
+ //-- else
+ //-- {
+ //-- res=clone(this); // safe copy
+ //-- newlen=res.mant.length+res.exp;
+ //-- newmant=new byte[newlen]; // [shorter]
+ //-- java.lang.System.arraycopy((java.lang.Object)res.mant,0,(java.lang.Object)newmant,0,newlen);
+ //-- res.mant=newmant;
+ //-- res.form=(byte)com.ibm.icu.math.MathContext.PLAIN;
+ //-- res.exp=0;
+ //-- }
+ //-- }
+ //-- }
+ //-- }
+ //-- return new BigInteger(new java.lang.String(res.layout()));
+ //-- }
+
+ /**
+ * Converts this BigDecimal to a
+ * java.math.BigInteger.
+ * java.math.BigInteger equal in value
+ * to the integer part of this BigDecimal.
+ * @throws ArithmeticException if this has a non-zero
+ * decimal part.
+ * @stable ICU 2.0
+ */
+
+ //--public java.math.BigInteger toBigIntegerExact(){
+ //-- /* test any trailing decimal part */
+ //-- if (exp<0)
+ //-- { // possible decimal part
+ //-- /* all decimal places must be 0; note exp<0 */
+ //-- if ((!(allzero(mant,mant.length+exp))))
+ //-- throw new java.lang.ArithmeticException("Decimal part non-zero:"+" "+this.toString());
+ //-- }
+ //-- return toBigInteger();
+ //-- }
+
+ /**
+ * Returns the BigDecimal as a character array.
+ * The result of this method is the same as using the
+ * sequence toString().toCharArray(), but avoids creating
+ * the intermediate String and char[]
+ * objects.
+ *
+ * @return The char[] array corresponding to this
+ * BigDecimal.
+ * @stable ICU 2.0
+ */
+
+ //--public char[] toCharArray(){
+ //-- return layout();
+ //-- }
+
+ /**
+ * Returns the BigDecimal as a String.
+ * This returns a String that exactly represents this
+ * BigDecimal, as defined in the decimal documentation
+ * (see {@link BigDecimal class header}).
+ * String will create a
+ * BigDecimal that is exactly equal to the original
+ * BigDecimal.
+ *
+ * @return The String exactly corresponding to this
+ * BigDecimal.
+ * @see #format(int, int)
+ * @see #format(int, int, int, int, int, int)
+ * @see #toCharArray()
+ * @stable ICU 2.0
+ */
+
+ //--public java.lang.String toString(){
+ function toString() {
+ return this.layout().join("");
+ }
+
+ /**
+ * Returns the number as a BigInteger after removing the
+ * scale.
+ * That is, the number is expressed as a plain number, any decimal
+ * point is then removed (retaining the digits of any decimal part),
+ * and the result is then converted to a BigInteger.
+ *
+ * @return The java.math.BigInteger equal in value to
+ * this BigDecimal multiplied by ten to the
+ * power of this.scale().
+ * @stable ICU 2.0
+ */
+
+ //--public java.math.BigInteger unscaledValue(){
+ //-- com.ibm.icu.math.BigDecimal res=null;
+ //-- if (exp>=0)
+ //-- res=this;
+ //-- else
+ //-- {
+ //-- res=clone(this); // safe copy
+ //-- res.exp=0; // drop scale
+ //-- }
+ //-- return res.toBigInteger();
+ //-- }
+
+ /**
+ * Translates a double to a BigDecimal.
+ * BigDecimal which is the decimal
+ * representation of the 64-bit signed binary floating point
+ * parameter. If the parameter is infinite, or is not a number (NaN),
+ * a NumberFormatException is thrown.
+ * num had been
+ * converted to a String using the
+ * Double.toString() method and the
+ * {@link #BigDecimal(java.lang.String)} constructor had then been used.
+ * This is typically not an exact conversion.
+ *
+ * @param dub The double to be translated.
+ * @return The BigDecimal equal in value to
+ * dub.
+ * @throws NumberFormatException if the parameter is infinite or
+ * not a number.
+ * @stable ICU 2.0
+ */
+
+ //--public static com.ibm.icu.math.BigDecimal valueOf(double dub){
+ //-- // Reminder: a zero double returns '0.0', so we cannot fastpath to
+ //-- // use the constant ZERO. This might be important enough to justify
+ //-- // a factory approach, a cache, or a few private constants, later.
+ //-- return new com.ibm.icu.math.BigDecimal((new java.lang.Double(dub)).toString());
+ //-- }
+
+ /**
+ * Translates a long to a BigDecimal.
+ * That is, returns a plain BigDecimal whose value is
+ * equal to the given long.
+ *
+ * @param lint The long to be translated.
+ * @return The BigDecimal equal in value to
+ * lint.
+ * @stable ICU 2.0
+ */
+
+ //--public static com.ibm.icu.math.BigDecimal valueOf(long lint){
+ //-- return valueOf(lint,0);
+ //-- }
+
+ /**
+ * Translates a long to a BigDecimal with a
+ * given scale.
+ * That is, returns a plain BigDecimal whose unscaled
+ * value is equal to the given long, adjusted by the
+ * second parameter, scale.
+ *
+ * (new BigDecimal(lint)).divide(TEN.pow(new BigDecimal(scale)))
+ *
+ * NumberFormatException is thrown if scale
+ * is negative.
+ *
+ * @param lint The long to be translated.
+ * @param scale The int scale to be applied.
+ * @return The BigDecimal equal in value to
+ * lint.
+ * @throws NumberFormatException if the scale is negative.
+ * @stable ICU 2.0
+ */
+
+ //--public static com.ibm.icu.math.BigDecimal valueOf(long lint,int scale){
+ //-- com.ibm.icu.math.BigDecimal res=null;
+ //-- {/*select*/
+ //-- if (lint==0)
+ //-- res=ZERO;
+ //-- else if (lint==1)
+ //-- res=ONE;
+ //-- else if (lint==10)
+ //-- res=TEN;
+ //-- else{
+ //-- res=new com.ibm.icu.math.BigDecimal(lint);
+ //-- }
+ //-- }
+ //-- if (scale==0)
+ //-- return res;
+ //-- if (scale<0)
+ //-- throw new java.lang.NumberFormatException("Negative scale:"+" "+scale);
+ //-- res=clone(res); // safe copy [do not mutate]
+ //-- res.exp=(int)-scale; // exponent is -scale
+ //-- return res;
+ //-- }
+
+ /* ---------------------------------------------------------------- */
+ /* Private methods */
+ /* ---------------------------------------------------------------- */
+
+ /*
+ C=A+(B*M)
+
+ Where M is in the range -9 through +9
+ =m){k=l;n++;continue a}if("."==m){0<=g&&this.bad("BigDecimal(): ",
+a);g=l-b;continue a}if("e"!=m&&"E"!=m){("0">m||"9"
=q?this.mant[l]=q-0:this.bad("BigDecimal(): ",a),m++;else for(b=n,l=0;0this.MaxExp)&&this.bad("BigDecimal(): ",a))}}function t(){var a;
+if(1==t.arguments.length)a=t.arguments[0];else if(0==t.arguments.length)a=this.plainMC;else throw"abs(): "+t.arguments.length+" arguments given; expected 0 or 1";return this.ind==this.isneg?this.negate(a):this.plus(a)}function z(){var a;if(2==z.arguments.length)a=z.arguments[1];else if(1==z.arguments.length)a=this.plainMC;else throw"add(): "+z.arguments.length+" arguments given; expected 1 or 2";var b=z.arguments[0],c,d,e,n,g,k,l,m=0;d=m=0;var m=null,q=m=0,p=0,r=0,t=0,s=0;a.lostDigits&&this.checkdigits(b,
+a.digits);c=this;if(0==c.ind&&a.form!=h.prototype.PLAIN)return b.plus(a);if(0==b.ind&&a.form!=h.prototype.PLAIN)return c.plus(a);d=a.digits;0
b.mant.length)return this.ind;if(c<=a.digits||0==a.digits){a=c;c=0;for(;0b.mant[c])return this.ind}return 0}}else{if(this.ind