1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | var _get = require('babel-runtime/helpers/get')['default'];
|
6 |
|
7 | var _inherits = require('babel-runtime/helpers/inherits')['default'];
|
8 |
|
9 | var _createClass = require('babel-runtime/helpers/create-class')['default'];
|
10 |
|
11 | var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
|
12 |
|
13 | var GlobalBigNumber = require('bignumber.js');
|
14 | var BigNumber = GlobalBigNumber.another({
|
15 | ROUNDING_MODE: GlobalBigNumber.ROUND_HALF_UP,
|
16 | DECIMAL_PLACES: 40
|
17 | });
|
18 |
|
19 | var Value = require('./value').Value;
|
20 | var bluzelleUnits = new BigNumber(1e6);
|
21 |
|
22 | var XPAValue = (function (_Value) {
|
23 | _inherits(XPAValue, _Value);
|
24 |
|
25 | function XPAValue(value) {
|
26 | _classCallCheck(this, XPAValue);
|
27 |
|
28 | _get(Object.getPrototypeOf(XPAValue.prototype), 'constructor', this).call(this, value);
|
29 | if (this._value.dp() > 6) {
|
30 | throw new Error('Value has more than 6 digits of precision past the decimal point, ' + 'an IOUValue may be being cast to an XPAValue');
|
31 | }
|
32 | }
|
33 |
|
34 | _createClass(XPAValue, [{
|
35 | key: 'multiply',
|
36 | value: function multiply(multiplicand) {
|
37 | if (multiplicand instanceof XPAValue) {
|
38 | return _get(Object.getPrototypeOf(XPAValue.prototype), 'multiply', this).call(this, new XPAValue(multiplicand._value.times(bluzelleUnits)));
|
39 | }
|
40 | return _get(Object.getPrototypeOf(XPAValue.prototype), 'multiply', this).call(this, multiplicand);
|
41 | }
|
42 | }, {
|
43 | key: 'divide',
|
44 | value: function divide(divisor) {
|
45 | if (divisor instanceof XPAValue) {
|
46 | return _get(Object.getPrototypeOf(XPAValue.prototype), 'divide', this).call(this, new XPAValue(divisor._value.times(bluzelleUnits)));
|
47 | }
|
48 | return _get(Object.getPrototypeOf(XPAValue.prototype), 'divide', this).call(this, divisor);
|
49 | }
|
50 | }, {
|
51 | key: 'negate',
|
52 | value: function negate() {
|
53 | return new XPAValue(this._value.neg());
|
54 | }
|
55 | }, {
|
56 | key: '_canonicalize',
|
57 | value: function _canonicalize(value) {
|
58 | if (value.isNaN()) {
|
59 | throw new Error('Invalid result');
|
60 | }
|
61 | return new XPAValue(value.round(6, BigNumber.ROUND_DOWN));
|
62 | }
|
63 | }, {
|
64 | key: 'equals',
|
65 | value: function equals(comparator) {
|
66 | return comparator instanceof XPAValue && this._value.equals(comparator._value);
|
67 | }
|
68 | }]);
|
69 |
|
70 | return XPAValue;
|
71 | })(Value);
|
72 |
|
73 | exports.XPAValue = XPAValue; |
\ | No newline at end of file |