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.Atanh() Method in C# with Examples
The MathF.Atanh() method in C# returns the hyperbolic arc-tangent of a single-precision floating-point value. The hyperbolic arc-tangent is the inverse of the hyperbolic tangent function and is defined only for values in the range (-1, 1).
For values outside this range, the method returns NaN (Not a Number). The method is useful in mathematical calculations involving hyperbolic functions and inverse transformations.
Syntax
Following is the syntax −
public static float Atanh(float val);
Parameters
-
val − A single-precision floating-point number representing the hyperbolic tangent whose inverse is to be found. Must be in the range (-1, 1).
Return Value
The method returns a float representing the hyperbolic arc-tangent of the input value. Returns NaN if the input is outside the valid range (-1, 1).
Using MathF.Atanh() with Valid Range
Example
using System;
public class Demo {
public static void Main() {
float val1 = 0.5f;
float val2 = -0.8f;
float val3 = 0.0f;
Console.WriteLine("Atanh(0.5) = " + MathF.Atanh(val1));
Console.WriteLine("Atanh(-0.8) = " + MathF.Atanh(val2));
Console.WriteLine("Atanh(0.0) = " + MathF.Atanh(val3));
}
}
The output of the above code is −
Atanh(0.5) = 0.5493061 Atanh(-0.8) = -1.0986123 Atanh(0.0) = 0
Using MathF.Atanh() with Invalid Range
Example
using System;
public class Demo {
public static void Main() {
float val1 = 25f;
float val2 = -15f;
float val3 = 1.0f;
float val4 = -1.0f;
Console.WriteLine("Atanh(25) = " + MathF.Atanh(val1));
Console.WriteLine("Atanh(-15) = " + MathF.Atanh(val2));
Console.WriteLine("Atanh(1.0) = " + MathF.Atanh(val3));
Console.WriteLine("Atanh(-1.0) = " + MathF.Atanh(val4));
}
}
The output of the above code is −
Atanh(25) = NaN Atanh(-15) = NaN Atanh(1.0) = ? Atanh(-1.0) = -?
Common Use Cases
Example
using System;
public class Demo {
public static void Main() {
// Demonstrating relationship between Tanh and Atanh
float original = 0.7f;
float hyperbolicTangent = MathF.Tanh(original);
float inverseResult = MathF.Atanh(hyperbolicTangent);
Console.WriteLine("Original value: " + original);
Console.WriteLine("Tanh(" + original + ") = " + hyperbolicTangent);
Console.WriteLine("Atanh(" + hyperbolicTangent + ") = " + inverseResult);
Console.WriteLine("Values match: " + Math.Abs(original - inverseResult) < 0.0001f);
}
}
The output of the above code is −
Original value: 0.7 Tanh(0.7) = 0.6043677 Atanh(0.6043677) = 0.7000001 Values match: True
Conclusion
The MathF.Atanh() method calculates the hyperbolic arc-tangent of single-precision floating-point values. It only accepts values in the range (-1, 1), returning NaN for values outside this range and infinity for boundary values ±1.
