UNPKG

2.17 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createFloor = void 0;
7
8var _factory = require("../../utils/factory");
9
10var _collection = require("../../utils/collection");
11
12var _number = require("../../utils/number");
13
14var _nearlyEqual = require("../../utils/bignumber/nearlyEqual");
15
16var name = 'floor';
17var dependencies = ['typed', 'config', 'round'];
18var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
19 var typed = _ref.typed,
20 config = _ref.config,
21 round = _ref.round;
22
23 /**
24 * Round a value towards minus infinity.
25 * For matrices, the function is evaluated element wise.
26 *
27 * Syntax:
28 *
29 * math.floor(x)
30 *
31 * Examples:
32 *
33 * math.floor(3.2) // returns number 3
34 * math.floor(3.8) // returns number 3
35 * math.floor(-4.2) // returns number -5
36 * math.floor(-4.7) // returns number -5
37 *
38 * const c = math.complex(3.2, -2.7)
39 * math.floor(c) // returns Complex 3 - 3i
40 *
41 * math.floor([3.2, 3.8, -4.7]) // returns Array [3, 3, -5]
42 *
43 * See also:
44 *
45 * ceil, fix, round
46 *
47 * @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
48 * @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
49 */
50 var floor = typed('floor', {
51 number: function number(x) {
52 if ((0, _number.nearlyEqual)(x, round(x), config.epsilon)) {
53 return round(x);
54 } else {
55 return Math.floor(x);
56 }
57 },
58 Complex: function Complex(x) {
59 return x.floor();
60 },
61 BigNumber: function BigNumber(x) {
62 if ((0, _nearlyEqual.nearlyEqual)(x, round(x), config.epsilon)) {
63 return round(x);
64 } else {
65 return x.floor();
66 }
67 },
68 Fraction: function Fraction(x) {
69 return x.floor();
70 },
71 'Array | Matrix': function ArrayMatrix(x) {
72 // deep map collection, skip zeros since floor(0) = 0
73 return (0, _collection.deepMap)(x, floor, true);
74 }
75 });
76 return floor;
77});
78exports.createFloor = createFloor;
\No newline at end of file