diff --git a/common.scad b/common.scad index 2761025..a888cc8 100644 --- a/common.scad +++ b/common.scad @@ -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. diff --git a/math.scad b/math.scad index ab977a6..f6b4c2d 100644 --- a/math.scad +++ b/math.scad @@ -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)