C acos() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, acos() returns the angle whose cosine is x. The angle is in radians, from 0 to π. acos(1) is 0, and acos(0) is π/2.

You pass one double. It must be from -1 to 1. The result is a double in radians, not degrees. Include <math.h>.

Syntax

Pass a cosine from -1 to 1. Start with this call.

C
acos(0.0);
CallWhat it does
acos(0.0)Returns π/2, the angle whose cosine is 0.

Include <math.h>. On GCC, link with -lm. The result is radians.

Library declarations
C
double acos(double x);
float acosf(float x);
long double acosl(long double x);

Parameters

ParameterDescription
xRequired. A cosine from -1 to 1.

Return Value

Return ValueDescription
RadiansThe angle from 0 to π whose cosine is x.
NaNReturned when x is outside -1 to 1.

C Examples

Example 1 — Common acos Values

Print radians for a few cosine inputs in the valid domain.

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

int main(void) {
    printf("acos(1)   = %.4f\n", acos(1.0));
    printf("acos(0)   = %.4f\n", acos(0.0));
    printf("acos(0.5) = %.4f\n", acos(0.5));
    printf("acos(-1)  = %.4f\n", acos(-1.0));

    return 0;
}

How It Works

  1. Include math.h. Declares acos; link with -lm on GCC.
  2. Endpoints. acos(1) is 0; acos(-1) is π.
  3. Middle values. acos(0) is π/2; acos(0.5) is π/3.
  4. Units are radians. These numbers are not degrees until you convert.

Example 2 — Convert Radians to Degrees

Multiply by 180 / π when you want a degree reading.

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

int main(void) {
    double x = 0.5;
    double rad = acos(x);
    double pi = acos(-1.0);
    double deg = rad * 180.0 / pi;

    printf("acos(%.1f) = %.4f rad\n", x, rad);
    printf("          = %.2f deg\n", deg);

    return 0;
}

How It Works

  1. Get radians first. acos(0.5) ≈ 1.0472.
  2. Get π portably. acos(-1.0) equals π without needing M_PI.
  3. Scale to degrees. Multiply by 180.0 / pi → 60.
  4. Keep rad for math. Pass radians into cos/sin; use degrees only for display.

Example 3 — Portable π with acos(-1)

A common ISO-friendly way to define π when M_PI is missing.

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

int main(void) {
    const double PI = acos(-1.0);

    printf("PI ≈ %.10f\n", PI);
    printf("cos(PI/3) ≈ %.4f\n", cos(PI / 3.0));

    return 0;
}

How It Works

  1. Ask for acos(-1). That angle is exactly π radians.
  2. Store as a constant. Reuse PI for conversions and trig.
  3. Check with cos. cos(π/3) should be about 0.5.
  4. Inverse pair. cos and acos undo each other on the valid domain.

Frequently Asked Questions

acos() returns the angle, in radians, whose cosine is x. acos(1) is 0 and acos(0) is π/2.
x is required. It is a double from -1 to 1.
A double in radians, from 0 to π. If x is outside -1 to 1, the result is NaN.
Include <math.h>. On GCC, link with -lm.
No. The result is radians. Multiply by 180/π when you want degrees.

Next: acosh()

Compute the inverse hyperbolic cosine.

acosh() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful