From ba032e2f4df5d6db504f343ad83c986f9a9e2233 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Thu, 6 Feb 2020 22:51:16 -0800 Subject: [PATCH] Added NAN, INF, and is_nan(). --- common.scad | 12 ++++++++++++ math.scad | 4 ++++ version.scad | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) 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)