Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

acos — inverse cosine

The acos function from <math.h> computes the principal inverse cosine of a double argument. Its result is an angle in radians, not degrees.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <math.h>
double acos(double x);

acos(x) accepts a double and returns a double: the angle in [0, π] radians whose cosine is x. It inverts a suitably restricted cosine function; it does not compute the reciprocal 1 / cos(x).

The domain is [-1, 1]; an argument outside this interval causes a domain error. Validate input before calling and do not assume every implementation then returns NaN. The example uses the valid argument 0.5 and prints the result with six digits after the decimal separator.

Examples

#include <math.h>
#include <stdio.h>

int main(void)
{
    double x = 0.5;
    double angle = acos(x);
    printf("%.6f\n", angle);
    return 0;
}

Result

1.047198

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources