Description

Calculates the cosine of an angle (in radians). The result will be between -1 and 1.

Syntax

Use the following function to calculate the cosine of a given angle in radians:

cos(rad)

Parameters

The function admits the following parameter:

rad: The angle in radians. Allowed data types: float.

Returns

The function returns the cosine of the angle. Data type: double.

Example Code

float angle = (2.0 / 3.0) * M_PI;  // in radians
double res = 0;

void setup() {
  Serial.begin(9600);

  res = cos(angle);

  Serial.print("The angle cosine is: ");
  Serial.println(res);
}

void loop() {
}

See also