What is the atanh() function in D?

Overview

The atanh() function returns the inverse hyperbolic tangent of a number.

The equation below shows the mathematical representation of the atanh() function:

atanh(x)=12ln(1+x1x)atanh(x)=\frac {1}{2}ln(\frac {1+x}{1-x})

Note: std.math is required for this function.

Syntax

atanh(number)
//number can be real, float, or double.

Parameter

This function requires a number as a parameter.

Note: The parameter should be between -1 and 1.

Return value

The atanh() function returns the inverse hyperbolic tangent of a number that is sent as a parameter.

Example

The code below shows the use of the atanh() function in D.

import core.stdc.stdio;
import std.stdio;
//header required for function
import std.math;
int main() {
//positive number
writeln("The value of atanh(0.5) :", atanh(0.5));
// negative number
writeln("The value of atanh(-0.5) :", atanh(-0.5));
//-1
writeln("The value of atanh(-1.0): ",atanh(-1.0) );
//1
writeln("The value of atanh(1.0): ",atanh(1.0) );
// >1
writeln("The value of atanh(2.0): ",atanh(2.0) );
// <-1
writeln("The value of atanh(-2.0): ",atanh(-2.0) );
return 0;
}

Explanation

  • Line 4: We add the std.math header required for atanh() function.
  • Line 8: We use atanh() to calculate the inverse hyperbolic tangent of the positive number (-1< number <1).
  • Line 11: We use atanh() to calculate the inverse hyperbolic tangent of the negative number (-1< number <1).
  • Line 14: We use atanh() to calculate the inverse hyperbolic tangent of -1.
  • Line 17: We use atanh() to calculate the inverse hyperbolic tangent of 1.
  • Line 20: We use atanh() to calculate the inverse hyperbolic tangent of number>1.
  • Line 23: We use atanh() to inverse the hyperbolic tangent of number<-1.

Free Resources