sin function

dynamic sin(
  1. dynamic x
)

Returns the sine of a number in radians.

Example 1:

print(sin(math.pi / 2));  // Output: 1.0

Example 2:

var z = Complex(pi / 2, 0);
var z_sin = sin(z);

print(z_sin); // Output: 1.0 + 0.0i

Example 3:

print(sin(Matrix.identity(2))); // Output: [[1.0, 0.0], [0.0, 1.0]]

Implementation

dynamic sin(dynamic x) {
  if (x is num) {
    return math.sin(x);
  } else if (x is Complex) {
    // Using the identity: sin(a + bi) = sin(a)cosh(b) + i*cos(a)sinh(b)
    return x.sin();
  } else if (x is Matrix) {
    return MatrixFunctions(x).sin();
  } else {
    throw ArgumentError('Input should be either num or Complex');
  }
}