Created
January 19, 2014 20:19
-
-
Save ztmr/8510487 to your computer and use it in GitHub Desktop.
Inf and NaN values handling in C.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* $Id: $ | |
* | |
* Module: inf -- description | |
* Created: 18-DEC-2007 19:17 | |
* Author: tmr | |
*/ | |
#define INF (1.0 / 0.0) | |
#define NAN (0.0 / 0.0) | |
#define IS_INF(x) ((double) (x) == (INF)) | |
#define IS_NINF(x) (IS_INF (-(x))) | |
#define IS_NAN(x) ((double) (x) == (NAN)) | |
int main (int argc, char * argv []) { | |
printf ("IS_INF (+INF) -> %d\n", IS_INF (+INF)); | |
printf ("IS_INF (-INF) -> %d\n", IS_INF (-INF)); | |
printf ("IS_INF ( 0) -> %d\n", IS_INF ( 0)); | |
printf ("IS_NINF (+INF) -> %d\n", IS_NINF (+INF)); | |
printf ("IS_NINF (-INF) -> %d\n", IS_NINF (-INF)); | |
printf ("IS_NINF ( 0) -> %d\n", IS_NINF ( 0)); | |
printf ("IS_NAN (+NAN) -> %d\n", IS_NAN (+NAN)); | |
printf ("IS_NAN (-NAN) -> %d\n", IS_NAN (-NAN)); | |
printf ("IS_NAN ( 0) -> %d\n", IS_NAN ( 0)); | |
printf ("+INF > 0 -> %d\n", +INF > 0); | |
printf ("+INF < 0 -> %d\n", +INF < 0); | |
printf ("-INF > 0 -> %d\n", -INF > 0); | |
printf ("-INF < 0 -> %d\n", -INF < 0); | |
printf ("+NAN > 0 -> %d\n", +NAN > 0); | |
printf ("+NAN < 0 -> %d\n", +NAN < 0); | |
printf ("-NAN > 0 -> %d\n", -NAN > 0); | |
printf ("-NAN < 0 -> %d\n", -NAN < 0); | |
return (0); | |
} | |
// vim: fdm=syntax:fdn=1:tw=74:ts=2:syn=c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment