Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to use isfinite() function to determine if a float has finite value in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>
#include <float.h>

// Return 1 = finite, ​0​ = infinite

int main(void)
{
    printf("isfinite(NAN)      = %d\n", isfinite(NAN));
    printf("isfinite(INFINITY) = %d\n", isfinite(INFINITY));
    printf("isfinite(0.0)      = %d\n", isfinite(0.0));
    printf("isfinite(3.14)     = %d\n", isfinite(3.14));
    printf("isfinite(DBL_MIN)  = %d\n", isfinite(DBL_MIN));
    printf("isfinite(989.123)  = %d\n", isfinite(989.123));
    printf("isfinite(1.0)      = %d\n", isfinite(1.0));
    printf("isfinite(exp(700)) = %d\n", isfinite(exp(700)));
}




/*
run:

isfinite(NAN)      = 0
isfinite(INFINITY) = 0
isfinite(0.0)      = 1
isfinite(3.14)     = 1
isfinite(DBL_MIN)  = 1
isfinite(989.123)  = 1
isfinite(1.0)      = 1
isfinite(exp(700)) = 1

*/

 



answered Feb 11, 2023 by avibootz
...