Get the hyperbolic arc-cosine of a floating-point value in C#

To get the hyperbolic arc-cosine of a floating-point value in C#, you use the MathF.Acosh() method for float values or Math.Acosh() method for double values. The hyperbolic arc-cosine function returns the value whose hyperbolic cosine is the specified number.

Syntax

Following is the syntax for the hyperbolic arc-cosine methods −

// For float values
public static float Acosh(float x)

// For double values  
public static double Acosh(double x)

Parameters

  • x − A number representing a hyperbolic cosine, where x must be greater than or equal to 1.

Return Value

Returns the hyperbolic arc-cosine of the specified value. If the input is less than 1, the method returns NaN (Not a Number).

Example with Valid Input Values

When the input value is greater than or equal to 1, the method returns a valid result −

using System;

public class Demo {
   public static void Main() {
      float val1 = 5.1f;
      float val2 = 8.9f;
      double val3 = 1.0;
      double val4 = 2.5;
      
      Console.WriteLine("Angle (val1) = " + (MathF.Acosh(val1)));
      Console.WriteLine("Angle (val2) = " + (MathF.Acosh(val2)));
      Console.WriteLine("Angle (val3) = " + (Math.Acosh(val3)));
      Console.WriteLine("Angle (val4) = " + (Math.Acosh(val4)));
   }
}

The output of the above code is −

Angle (val1) = 2.312634
Angle (val2) = 2.876027
Angle (val3) = 0
Angle (val4) = 1.56679923144065

Example with Invalid Input Values

When the input value is less than 1, the method returns NaN

using System;

public class Demo {
   public static void Main() {
      float val1 = 0.1f;
      float val2 = 0.9f;
      double val3 = -1.5;
      
      Console.WriteLine("Angle (val1) = " + (MathF.Acosh(val1)));
      Console.WriteLine("Angle (val2) = " + (MathF.Acosh(val2)));
      Console.WriteLine("Angle (val3) = " + (Math.Acosh(val3)));
      
      // Check if result is NaN
      Console.WriteLine("Is val1 result NaN? " + float.IsNaN(MathF.Acosh(val1)));
   }
}

The output of the above code is −

Angle (val1) = NaN
Angle (val2) = NaN
Angle (val3) = NaN
Is val1 result NaN? True

Key Rules

  • The input value must be greater than or equal to 1 for a valid result.

  • For values less than 1, the method returns NaN.

  • Use MathF.Acosh() for float precision and Math.Acosh() for double precision.

  • The result is measured in radians.

Conclusion

The MathF.Acosh() and Math.Acosh() methods calculate the hyperbolic arc-cosine of a number. These methods require input values greater than or equal to 1, otherwise they return NaN to indicate an invalid operation.

Updated on: 2026-03-17T07:04:36+05:30

203 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements