UNPKG

1.75 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createSin = void 0;
7
8var _factory = require("../../utils/factory");
9
10var _collection = require("../../utils/collection");
11
12var name = 'sin';
13var dependencies = ['typed'];
14var createSin = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
15 var typed = _ref.typed;
16
17 /**
18 * Calculate the sine of a value.
19 *
20 * For matrices, the function is evaluated element wise.
21 *
22 * Syntax:
23 *
24 * math.sin(x)
25 *
26 * Examples:
27 *
28 * math.sin(2) // returns number 0.9092974268256813
29 * math.sin(math.pi / 4) // returns number 0.7071067811865475
30 * math.sin(math.unit(90, 'deg')) // returns number 1
31 * math.sin(math.unit(30, 'deg')) // returns number 0.5
32 *
33 * const angle = 0.2
34 * math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number ~1
35 *
36 * See also:
37 *
38 * cos, tan
39 *
40 * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
41 * @return {number | BigNumber | Complex | Array | Matrix} Sine of x
42 */
43 var sin = typed(name, {
44 number: Math.sin,
45 Complex: function Complex(x) {
46 return x.sin();
47 },
48 BigNumber: function BigNumber(x) {
49 return x.sin();
50 },
51 Unit: function Unit(x) {
52 if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
53 throw new TypeError('Unit in function sin is no angle');
54 }
55
56 return sin(x.value);
57 },
58 'Array | Matrix': function ArrayMatrix(x) {
59 // deep map collection, skip zeros since sin(0) = 0
60 return (0, _collection.deepMap)(x, sin, true);
61 }
62 });
63 return sin;
64});
65exports.createSin = createSin;
\No newline at end of file