Home » C++ programming language

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 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.

Example:

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

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

// 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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.