UNPKG

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