From 58f004341706867d1c7af1ed1cbd8aea1cd7ac1f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 6 Apr 2018 22:57:24 +0300 Subject: [PATCH] vector utils: isnan and isinf * a vector which has least one NaN or INF member, is assumed not valid vector. --- include/cglm/vec3-ext.h | 36 ++++++++++++++++++++++++++++++++++++ include/cglm/vec4-ext.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index 99e778a..7890c33 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -160,4 +160,40 @@ glm_vec_min(vec3 v) { return min; } +/*! + * @brief check if all items are NaN (not a number) + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec_isnan(vec3 v) { + return !(isnan(v[0]) || isnan(v[1]) || isnan(v[2])); +} + +/*! + * @brief check if all items are INFINITY + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec_isinf(vec3 v) { + return !(isinf(v[0]) || isinf(v[1]) || isinf(v[2])); +} + +/*! + * @brief check if all items are valid number + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec_isvalid(vec3 v) { + return !glm_vec_isnan(v) && !glm_vec_isinf(v); +} + #endif /* cglm_vec3_ext_h */ diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index ca697af..c290477 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -174,5 +174,41 @@ glm_vec4_min(vec4 v) { return min; } +/*! + * @brief check if all items are NaN (not a number) + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec4_isnan(vec4 v) { + return !(isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3])); +} + +/*! + * @brief check if all items are INFINITY + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec4_isinf(vec4 v) { + return !(isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3])); +} + +/*! + * @brief check if all items are valid number + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec4_isvalid(vec4 v) { + return !glm_vec4_isnan(v) && !glm_vec4_isinf(v); +} + #endif /* cglm_vec4_ext_h */