1 | import Decimal from 'decimal.js';
|
2 | import { factory } from '../../utils/factory.js';
|
3 | import { deepMap } from '../../utils/collection.js';
|
4 | import { nearlyEqual } from '../../utils/number.js';
|
5 | import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual.js';
|
6 | import { ceilNumber } from '../../plain/number/index.js';
|
7 | import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js';
|
8 | import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js';
|
9 | var name = 'ceil';
|
10 | var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
|
11 | export var createCeil = factory(name, dependencies, (_ref) => {
|
12 | var {
|
13 | typed,
|
14 | config,
|
15 | round,
|
16 | matrix,
|
17 | equalScalar
|
18 | } = _ref;
|
19 | var algorithm11 = createAlgorithm11({
|
20 | typed,
|
21 | equalScalar
|
22 | });
|
23 | var algorithm14 = createAlgorithm14({
|
24 | typed
|
25 | });
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | return typed('ceil', {
|
65 | number: function number(x) {
|
66 | if (nearlyEqual(x, round(x), config.epsilon)) {
|
67 | return round(x);
|
68 | } else {
|
69 | return ceilNumber(x);
|
70 | }
|
71 | },
|
72 | 'number, number': function numberNumber(x, n) {
|
73 | if (nearlyEqual(x, round(x, n), config.epsilon)) {
|
74 | return round(x, n);
|
75 | } else {
|
76 | var [number, exponent] = "".concat(x, "e").split('e');
|
77 | var result = Math.ceil(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
78 | [number, exponent] = "".concat(result, "e").split('e');
|
79 | return Number("".concat(number, "e").concat(Number(exponent) - n));
|
80 | }
|
81 | },
|
82 | Complex: function Complex(x) {
|
83 | return x.ceil();
|
84 | },
|
85 | 'Complex, number': function ComplexNumber(x, n) {
|
86 | return x.ceil(n);
|
87 | },
|
88 | BigNumber: function BigNumber(x) {
|
89 | if (bigNearlyEqual(x, round(x), config.epsilon)) {
|
90 | return round(x);
|
91 | } else {
|
92 | return x.ceil();
|
93 | }
|
94 | },
|
95 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, n) {
|
96 | if (bigNearlyEqual(x, round(x, n), config.epsilon)) {
|
97 | return round(x, n);
|
98 | } else {
|
99 | return x.toDecimalPlaces(n.toNumber(), Decimal.ROUND_CEIL);
|
100 | }
|
101 | },
|
102 | Fraction: function Fraction(x) {
|
103 | return x.ceil();
|
104 | },
|
105 | 'Fraction, number': function FractionNumber(x, n) {
|
106 | return x.ceil(n);
|
107 | },
|
108 | 'Array | Matrix': function ArrayMatrix(x) {
|
109 |
|
110 | return deepMap(x, this, true);
|
111 | },
|
112 | 'Array | Matrix, number': function ArrayMatrixNumber(x, n) {
|
113 |
|
114 | return deepMap(x, i => this(i, n), true);
|
115 | },
|
116 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
117 | return algorithm11(x, y, this, false);
|
118 | },
|
119 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
120 | return algorithm14(x, y, this, false);
|
121 | },
|
122 | 'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
123 |
|
124 | return algorithm14(matrix(y), x, this, true).valueOf();
|
125 | }
|
126 | });
|
127 | }); |
\ | No newline at end of file |