×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

atanh() function with example in C++

C++ atanh() function: Here, we are going to learn about the atanh() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on April 28, 2019

C++ atanh() function

atanh() function is a library function of cmath header, it is used to find the area hyperbolic tangent of the given value, it accepts a number (x) and returns the area hyperbolic tangent of x.

Note: Value of the x should be between -1 to +1, else it may return domain error (nan), and for the value -1 and +1, it may return pole error inf)

Syntax

Syntax of atanh() function:

atanh(x);

Parameter(s)

x – is the number/value whose area hyperbolic tangent is calculated.

Return value

double – it returns double type value that is the area hyperbolic tangent of the given number/value x.

Sample Input and Output

Input:
float x = 0.25;
    
Function call:
atanh(x);    
    
Output:
0.255413

Example

// C++ code to demonstrate the example of 
// atanh() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float x;
    
    x = -0.25;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;

    x = -0.99;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;    

    x = 0.25;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;    

    x = 0.99;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;        
    
    return 0;
}

Output

atanh(-0.25): -0.255413
atanh(-0.99): -2.64665
atanh(0.25): 0.255413
atanh(0.99): 2.64665

Example with domain, pole errors

// C++ code to demonstrate the example of 
// atanh() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float x;
    
    //no error with this input value
    x = -0.25;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;

    //no error with this input value
    x = 0.25;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;

    //pole error with this input value
    x = -1;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;

    //pole error with this input value
    x = 1;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;        

    //domain error with this input value
    x = -1.5;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;        

    //domain error with this input value
    x = 1.5;
    cout<<"atanh("<<x<<"): "<<atanh(x)<<endl;        
    
    return 0;
}

Output

atanh(-0.25): -0.255413
atanh(0.25): 0.255413
atanh(-1): -inf
atanh(1): inf
atanh(-1.5): -nan
atanh(1.5): -nan

Reference: C++ atanh() function



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.