Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
MathF.Acosh() Method in C# with Examples
The MathF.Acosh() method in C# returns the hyperbolic arc-cosine (inverse hyperbolic cosine) of a floating-point value. This method is part of the MathF class, which provides mathematical functions for float values with better performance than the double-precision Math class.
The hyperbolic arc-cosine is defined for values greater than or equal to 1. For values less than 1, the method returns NaN (Not a Number).
Syntax
Following is the syntax for the MathF.Acosh() method −
public static float Acosh(float val);
Parameters
- val − A floating-point number representing the hyperbolic cosine value. Must be greater than or equal to 1 for a valid result.
Return Value
Returns a float value representing the hyperbolic arc-cosine of the input. Returns NaN if the input is less than 1, PositiveInfinity if the input is PositiveInfinity, and NaN if the input is NaN.
Example with Invalid Input (Less Than 1)
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;
Console.WriteLine("Acosh(0.1) = " + MathF.Acosh(val1));
Console.WriteLine("Acosh(0.9) = " + MathF.Acosh(val2));
Console.WriteLine("Is NaN: " + float.IsNaN(MathF.Acosh(val1)));
}
}
The output of the above code is −
Acosh(0.1) = NaN Acosh(0.9) = NaN Is NaN: True
Example with Valid Input (Greater Than or Equal to 1)
When the input value is greater than or equal to 1, the method returns the hyperbolic arc-cosine −
using System;
public class Demo {
public static void Main() {
float val1 = 1.0f;
float val2 = 5.1f;
float val3 = 8.9f;
Console.WriteLine("Acosh(1.0) = " + MathF.Acosh(val1));
Console.WriteLine("Acosh(5.1) = " + MathF.Acosh(val2));
Console.WriteLine("Acosh(8.9) = " + MathF.Acosh(val3));
}
}
The output of the above code is −
Acosh(1.0) = 0 Acosh(5.1) = 2.312634 Acosh(8.9) = 2.876027
Example with Special Values
Testing the method with special floating-point values −
using System;
public class Demo {
public static void Main() {
Console.WriteLine("Acosh(+?) = " + MathF.Acosh(float.PositiveInfinity));
Console.WriteLine("Acosh(NaN) = " + MathF.Acosh(float.NaN));
Console.WriteLine("Acosh(-1) = " + MathF.Acosh(-1.0f));
}
}
The output of the above code is −
Acosh(+?) = ? Acosh(NaN) = NaN Acosh(-1) = NaN
Common Use Cases
The MathF.Acosh() method is commonly used in mathematical calculations involving hyperbolic functions, physics simulations, and engineering applications where inverse hyperbolic cosine calculations are required with single-precision floating-point accuracy.
Conclusion
The MathF.Acosh() method calculates the hyperbolic arc-cosine of float values. It requires input values greater than or equal to 1 to return valid results, otherwise it returns NaN. This method is useful for mathematical computations requiring single-precision inverse hyperbolic cosine calculations.
