VOOZH about

URL: https://www.geeksforgeeks.org/cpp/isinf-function-in-c/

⇱ isinf() function in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

isinf() function in C++

Last Updated : 26 Jun, 2023

This function is defined in <cmath.h> .The isinf() function is use to determine whether the given number is infinity or not i.e positive infinity or negative infinity both. This function returns 1 if the given number is infinite otherwise this function returns zero. 

Syntax:

bool isinf( float arg );

or

bool isinf( double arg );

or

bool isinf( long double arg );

Parameter: This function takes a mandatory parameter x which represents the given floating point value. 

Return: This function returns 1 if the given number is infinite else return zero.

Time Complexity: O(1)
Auxiliary Space: O(1)

Below programs illustrate the isinf() function in C++: 

Example 1:- To show infinite case which returns 1 

Output:
isinf(6.0/0.0) is = 1
isinf(-1.2/0.0) is = 1

Explanation: In example 1 the floating point number represents infinity that's why function returns 1. 

Example 2:- To show non-infinite case which returns 0 

Output:
isinf(0.0) is = 0
isinf(sqrt(-1.0)) is = 0

Exception: In example 2 the given floating point number is not representing infinity that's why function returns zero.

Comment
Article Tags: