Skip to content

Instantly share code, notes, and snippets.

@xiaom
Created February 23, 2012 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaom/1895894 to your computer and use it in GitHub Desktop.
Save xiaom/1895894 to your computer and use it in GitHub Desktop.
float point exception
// see http://www.johndcook.com/IEEE_exceptions_in_cpp.html for details
bool IsNumber(double x)
{
// This looks like it should always be true,
// but it's false if x is a NaN.
return (x == x);
}
#include <float.h>
bool IsFiniteNumber(double x)
{
return (x <= DBL_MAX && x >= -DBL_MAX);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment