How to determine if float numbers x and y are unordered (one or both are NaN) in C

1 Answer

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

int main(void)
{
    printf("isunordered(NAN, NAN)       = %d\n", isunordered(NAN, NAN));
    printf("isunordered(NAN, 1.0)       = %d\n", isunordered(NAN, 1.0));
    printf("isunordered(1.0, NAN)       = %d\n", isunordered(1.0, NAN));
    printf("isunordered(1.0, 0.0)       = %d\n", isunordered(1.0, 0.0));
    printf("isunordered(1.0, -983474.0) = %d\n", isunordered(1.0, -983474.0));
}




/*
run:

isunordered(NAN, NAN)       = 1
isunordered(NAN, 1.0)       = 1
isunordered(1.0, NAN)       = 1
isunordered(1.0, 0.0)       = 0
isunordered(1.0, -983474.0) = 0

*/

 



answered Feb 11, 2023 by avibootz
...