1 | import { factory } from '../../utils/factory';
|
2 | import { deepMap } from '../../utils/collection';
|
3 | import { nearlyEqual } from '../../utils/number';
|
4 | import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual';
|
5 | import { ceilNumber } from '../../plain/number';
|
6 | var name = 'ceil';
|
7 | var dependencies = ['typed', 'config', 'round'];
|
8 | export var createCeil =
|
9 | /* #__PURE__ */
|
10 | factory(name, dependencies, function (_ref) {
|
11 | var typed = _ref.typed,
|
12 | config = _ref.config,
|
13 | round = _ref.round;
|
14 |
|
15 | /**
|
16 | * Round a value towards plus infinity
|
17 | * If `x` is complex, both real and imaginary part are rounded towards plus infinity.
|
18 | * For matrices, the function is evaluated element wise.
|
19 | *
|
20 | * Syntax:
|
21 | *
|
22 | * math.ceil(x)
|
23 | *
|
24 | * Examples:
|
25 | *
|
26 | * math.ceil(3.2) // returns number 4
|
27 | * math.ceil(3.8) // returns number 4
|
28 | * math.ceil(-4.2) // returns number -4
|
29 | * math.ceil(-4.7) // returns number -4
|
30 | *
|
31 | * const c = math.complex(3.2, -2.7)
|
32 | * math.ceil(c) // returns Complex 4 - 2i
|
33 | *
|
34 | * math.ceil([3.2, 3.8, -4.7]) // returns Array [4, 4, -4]
|
35 | *
|
36 | * See also:
|
37 | *
|
38 | * floor, fix, round
|
39 | *
|
40 | * @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
|
41 | * @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
42 | */
|
43 | var ceil = typed('ceil', {
|
44 | number: function number(x) {
|
45 | if (nearlyEqual(x, round(x), config.epsilon)) {
|
46 | return round(x);
|
47 | } else {
|
48 | return ceilNumber(x);
|
49 | }
|
50 | },
|
51 | Complex: function Complex(x) {
|
52 | return x.ceil();
|
53 | },
|
54 | BigNumber: function BigNumber(x) {
|
55 | if (bigNearlyEqual(x, round(x), config.epsilon)) {
|
56 | return round(x);
|
57 | } else {
|
58 | return x.ceil();
|
59 | }
|
60 | },
|
61 | Fraction: function Fraction(x) {
|
62 | return x.ceil();
|
63 | },
|
64 | 'Array | Matrix': function ArrayMatrix(x) {
|
65 | // deep map collection, skip zeros since ceil(0) = 0
|
66 | return deepMap(x, ceil, true);
|
67 | }
|
68 | });
|
69 | return ceil;
|
70 | }); |
\ | No newline at end of file |