The isfinite()
function in C identifies if a number is finite. The declaration of isfinite()
is shown below:
int isfinite(float num);
OR:
int isfinite(double num);
OR:
int isfinite(long double num);
num
: the number checked to see if it is finiteThe isfinite()
function returns 1 if the number passed as a parameter is finite, and returns 0 otherwise.
To use the isfinite()
function, include the following library:
#include <math.h>
Consider the code snippet below, which demonstrates the use of the isfinite()
function:
#include<stdio.h>#include<math.h>int main() {float num1 = 1.0;float num2 = 0.0;int num3 = isfinite(num1/num2);if(num3==1){printf("%f / %f is finite \n", num1, num2);}else if(num3==0){printf("%f / %f is infinite \n", num1, num2);}int num4 = isfinite(num2/num1);if(num4==1){printf("%f / %f is finite \n", num2, num1);}else if(num4==0){printf("%f / %f is infinite \n", num2, num1);}int num5 = isfinite(INFINITY);if(num5==1){printf("INFINITY is finite \n");}else if(num5==0){printf("INFINITY is infinite \n");}return 0;}
isfinite()
function is used in line 8 to show that a division by zero is not finite.isfinite()
function is used in line 15 and a simple finite division is performed. The isfinite()
function returns 0, as the division is finite.isfinite()
function is used in line 22 to show that infinity is not finite.Free Resources