Home » C++ programming language

acosh() function with example in C++

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

C++ acosh() function

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

Note: Value of the x should not be less than the 1, if arguments are less than 0, it returns a domain error (-nan).

Syntax of acosh() function:

    acosh(x);

Parameter(s): x – is the number/value whose nonnegative area hyperbolic cosine is calculated.

Return value: double – it returns double type value that is the nonnegative area hyperbolic cosine of the given number/value x.

Example:

    Input:
    float x = 2.45;
    
    Function call:
    acosh(x);    
    
    Output:
    1.54471

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

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

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

// main() section
int main()
{
    float x;
    
    x = 1.0;
    cout<<"acosh("<<x<<"): "<<acosh(x)<<endl;

    x = 10.23;
    cout<<"acosh("<<x<<"): "<<acosh(x)<<endl;    

    x = 2.45;
    cout<<"acosh("<<x<<"): "<<acosh(x)<<endl;    
    
    return 0;
}

Output

acosh(1): 0
acosh(10.23): 3.01607
acosh(2.45): 1.54471

Example with domain error

If we provide the value less than 1, it returns -nan.

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

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

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

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

    return 0;
}

Output

acosh(1): 0
acosh(0.25): -nan

Reference: C++ acosh() function




Comments and Discussions!

Load comments ↻






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