C# Math Acos() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

In C#, Math.Acos(d) is the inverse of cosine (arccosine). You give it a number between -1 and 1, and it returns the angle in radians whose cosine is that number. Math.Acos(-1) is Math.PI, a half turn.

If Cos() answers "how far right is the clock hand at this angle?", Acos answers "which angle gives this position?". The answer is always from 0 to Math.PI (0 to 180 degrees). A well-known use is finding the angle between two vectors from their dot product. The input must be between -1 and 1.

This is a static member of the static class System.Math. You call it with the class name, such as Math.Acos(...). There is no Math object to create. All the work is done by the method you call, and it never changes your variables. Acos is in every .NET version. It takes a double and returns the angle in radians.

Syntax

Pass a number from -1 to 1. The answer is an angle in radians from 0 to pi.

C#
double a = Math.Acos(1);        // 0
double b = Math.Acos(0);        // 1.5707963267948966 (pi / 2)
double c = Math.Acos(-1);       // 3.141592653589793 (pi)
double degrees = Math.Acos(0.5) * 180 / Math.PI;   // about 60
CallWhat it does
Math.Acos(1)Returns 0.
Math.Acos(0)Returns about 1.5708 (pi / 2, or 90 degrees).
Math.Acos(-1)Returns about 3.1416 (pi, or 180 degrees).
Math.Acos(2)Returns NaN. No angle has a cosine of 2.

The answer is in radians. Multiply by 180 / Math.PI for degrees. When the input comes from other calculations (like a dot product divided by two lengths), rounding can push it just outside -1 to 1, so use Math.Clamp(value, -1, 1) first. The method never throws.

Library declarations
C#
public static double Acos(double d);

Parameters

ParameterDescription
dRequired. A number from -1 to 1 (the cosine value).

Return Value

Return ValueDescription
doubleThe angle in radians, from 0 to Math.PI. NaN if d is below -1, above 1, or NaN.

C# Examples

Example 1 — Acos of Key Values

Print the angle in radians for a few cosine values, rounded to 4 decimals.

C#
using System;
using System.Globalization;

class Program {
    static string R(double value) {
        return Math.Round(value, 4).ToString(CultureInfo.InvariantCulture);
    }

    static void Main() {
        Console.WriteLine(R(Math.Acos(1)));
        Console.WriteLine(R(Math.Acos(0)));
        Console.WriteLine(R(Math.Acos(-1)));
        Console.WriteLine(R(Math.Acos(0.5)));
    }
}

How It Works

  1. Cosine 1. The cosine is 1 when the hand has not moved, so the angle is 0.
  2. Cosine 0. The hand points straight up: a quarter turn, about 1.5708 radians.
  3. Cosine -1. The hand points left: a half turn, which is pi, about 3.1416. This is the top edge of the answer range.
  4. Cosine 0.5. The angle is 60 degrees, one third of a half turn, about 1.0472 radians.

Example 2 — Angle Between Two Vectors

Use the dot product and the lengths of two vectors, clamp the ratio, and convert the answer to degrees.

C#
using System;

class Program {
    static double AngleDegrees(double ax, double ay, double bx, double by) {
        double dot = ax * bx + ay * by;
        double lengths = Math.Sqrt(ax * ax + ay * ay) * Math.Sqrt(bx * bx + by * by);
        double cosine = Math.Clamp(dot / lengths, -1, 1);
        return Math.Round(Math.Acos(cosine) * 180 / Math.PI, 2);
    }

    static void Main() {
        Console.WriteLine(AngleDegrees(1, 0, 1, 1));
        Console.WriteLine(AngleDegrees(0, 1, 1, 0));
        Console.WriteLine(AngleDegrees(1, 0, -1, 0));
    }
}

How It Works

  1. The formula. The cosine of the angle between two vectors is their dot product divided by the product of their lengths. Acos turns that cosine back into an angle.
  2. Clamp. Rounding can make the ratio slightly bigger than 1 or smaller than -1. Math.Clamp keeps it in the legal range so Acos never returns NaN by accident.
  3. 45 and 90 degrees. The vectors (1, 0) and (1, 1) are 45 degrees apart. The vectors (0, 1) and (1, 0) are at right angles, 90 degrees.
  4. Opposite directions. (1, 0) and (-1, 0) point opposite ways, so the angle is a half turn, 180 degrees.

Example 3 — Larger Angles and Out-of-Range Input

See an angle past 90 degrees, a value outside -1 to 1, and the link between Acos and Asin.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        Console.WriteLine(Math.Round(Math.Acos(-0.5) * 180 / Math.PI, 2));
        Console.WriteLine(Math.Acos(1.2));

        double sum = Math.Acos(0.3) + Math.Asin(0.3);
        Console.WriteLine(Math.Round(sum, 6).ToString(CultureInfo.InvariantCulture));
    }
}

How It Works

  1. Beyond 90 degrees. A negative cosine means the hand points left of centre. Acos(-0.5) is 120 degrees, which is more than a quarter turn. This is where Acos differs from Asin, which stops at 90.
  2. Out of range. A cosine cannot be 1.2, so Math.Acos(1.2) returns NaN.
  3. A neat link. For any value from -1 to 1, Acos(x) + Asin(x) is always pi / 2, a quarter turn.
  4. The result. Pi / 2 is 1.5707963..., which rounds to 1.570796 at 6 decimal places.

Frequently Asked Questions

It returns the angle in radians whose cosine is the given number, from 0 to pi. Math.Acos(0) is about 1.5708 (pi / 2). The input must be from -1 to 1.
Compute cosine = dot / (lengthA * lengthB), clamp it to -1 to 1, then use Math.Acos(cosine). Multiply by 180 / Math.PI for degrees.
The input is outside -1 to 1, or it is NaN. Rounding errors can push a value like 1 to 1.0000000000000002. Use Math.Clamp(value, -1, 1) before calling.
From 0 to Math.PI radians (0 to 180 degrees).
No. Math is a static class, so you call Math.Acos(...) straight on the class name. You cannot write new Math(), and there is no variable to keep.

Next: Acosh()

Return the inverse hyperbolic cosine: the non-negative number whose Cosh is the input.

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.

8 people found this page helpful