In C#, Math.Acosh(d) is the inverse hyperbolic cosine. It undoes Cosh(): if Cosh(x) is d, then Acosh(d) is x. Math.Acosh(1) is 0 and Math.Acosh(2) is about 1.317.
Recall that Cosh makes a "U" that never goes below 1. So the inverse only exists for inputs of 1 or more. An input below 1 has no answer, and you get NaN. A "U" has two sides, so there are really two answers (plus and minus). Acosh always returns the non-negative one.
This is a static member of the static class System.Math. You call it with the class name, such as Math.Acosh(...). There is no Math object to create. All the work is done by the method you call, and it never changes your variables. Math.Acosh was added in .NET Core 3.0. It is not in classic .NET Framework.
Syntax
Pass a number that is at least 1. The answer is a double of 0 or more.
C#
double a = Math.Acosh(1); // 0
double b = Math.Acosh(2); // 1.3169578969248166
double c = Math.Acosh(0.5); // NaN (input below 1)
Call
What it does
Math.Acosh(1)
Returns 0.
Math.Acosh(2)
Returns about 1.317.
Math.Acosh(0.5)
Returns NaN. Cosh is never below 1.
Math.Acosh(double.PositiveInfinity)
Returns Infinity.
The input must be 1 or more. Anything smaller (and negative numbers) gives NaN, without an exception. The result is never negative. Rounding in earlier calculations can produce an input like 0.9999999999999999, so clamp with Math.Max(value, 1) if that could happen.
Library declarations
C#
public static double Acosh(double d);
Parameters
Parameter
Description
d
Required. A double that is 1 or more.
Return Value
Return Value
Description
double
The non-negative number x such that Cosh(x) equals d. NaN if d is below 1 or NaN. Infinity for positive infinity.
C# Examples
Example 1 — Acosh of a Few Numbers
Print Acosh for 1, 2, 10, and 1.5, 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.Acosh(1)));
Console.WriteLine(R(Math.Acosh(2)));
Console.WriteLine(R(Math.Acosh(10)));
Console.WriteLine(R(Math.Acosh(1.5)));
}
}
Output
0
1.317
2.9932
0.9624
How It Works
One.Cosh(0) is 1, so Acosh(1) is 0. This is the smallest legal input.
Two. You need Cosh of about 1.317 to reach 2. The text shows 1.317 because the helper drops the trailing zero from 1.3170.
Ten. The answer grows slowly, about 2.9932.
One and a half. Between 1 and 2, the answer is about 0.9624.
Example 2 — Acosh Reverses Cosh
Apply Cosh and then Acosh, and see the starting number returned. Note what happens for a negative start.
C#
using System;
using System.Globalization;
class Program {
static string R(double value) {
return Math.Round(value, 6).ToString(CultureInfo.InvariantCulture);
}
static void Main() {
foreach (double x in new double[] { 0.5, 2, 3, -2 }) {
double locked = Math.Cosh(x);
Console.WriteLine(R(Math.Acosh(locked)));
}
}
}
Output
0.5
2
3
2
How It Works
Lock with Cosh.Cosh(x) is always 1 or more, which is exactly the input range Acosh accepts.
Unlock with Acosh. For 0.5, 2, and 3, you get the starting number back, apart from a tiny rounding error that the helper hides.
The negative start.Cosh(-2) equals Cosh(2), so there is no way to know the start was negative.
Always non-negative. That is why the last line prints 2, not -2. Acosh returns the plus side only.
Example 3 — Inputs Below 1 Give NaN
See the NaN results for inputs below 1, the zero at 1, and a safe clamp.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Math.Acosh(0.5));
Console.WriteLine(Math.Acosh(-1));
Console.WriteLine(Math.Acosh(1));
double slightlyLow = 0.99;
Console.WriteLine(double.IsNaN(Math.Acosh(slightlyLow)));
Console.WriteLine(Math.Acosh(Math.Max(slightlyLow, 1)));
}
}
Output
NaN
NaN
0
True
0
How It Works
Below 1.Cosh never gives 0.5, so Math.Acosh(0.5) has no answer and returns NaN.
Negative. A negative input is below 1 as well, so Acosh(-1) is NaN.
The edge.Acosh(1) is exactly 0. The method does not throw at the edge of the range.
Detect and fix.double.IsNaN detects the bad result. Math.Max(slightlyLow, 1) lifts the input to 1, which gives 0.
Frequently Asked Questions
It returns the inverse hyperbolic cosine for inputs of 1 or more. Math.Acosh(1) is 0 and Math.Acosh(2) is about 1.317.
The input is below 1 (or NaN). Cosh never produces a value below 1, so no answer exists. Clamp the input with Math.Max(value, 1) if rounding may push it just under 1.
It was added in .NET Core 3.0, so it is in modern .NET. It is not in classic .NET Framework.
Cosh is symmetric, so both x and -x give the same Cosh value. Acosh returns the non-negative one of the two.
No. Math is a static class, so you call Math.Acosh(...) straight on the class name. You cannot write new Math(), and there is no variable to keep.