Added NAN, INF, and is_nan().

This commit is contained in:
Revar Desmera 2020-02-06 22:51:16 -08:00
parent 28f07a997f
commit ba032e2f4d
3 changed files with 17 additions and 1 deletions

View file

@ -73,6 +73,18 @@ function is_int(n) = is_num(n) && n == round(n);
function is_integer(n) = is_num(n) && n == round(n);
// Function: is_nan()
// Usage:
// is_nan(x);
// Description:
// Returns true if a given value `x` is nan, a floating point value representing "not a number".
// This test is far more complicated than it should be, because while arguable correct, the tests
// `is_num(nan)` and `nan==nan` both returns false.
function is_nan(x) =
!is_num(x) && !is_undef(x) && !is_string(x) &&
!is_list(x) && !(x<=INF) && is_undef(x[0]);
// Section: Handling `undef`s.

View file

@ -14,6 +14,10 @@ PHI = (1+sqrt(5))/2; // The golden ratio phi.
EPSILON = 1e-9; // A really small value useful in comparing FP numbers. ie: abs(a-b)<EPSILON
INF = 1/0; // The value `inf`, useful for comparisons.
NAN = acos(2); // The value `nan`, useful for comparisons.
// Section: Simple math

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,116];
BOSL_VERSION = [2,0,117];
// Section: BOSL Library Version Functions