vector utils: isnan and isinf

* a vector which has least one NaN or INF member, is assumed not valid vector.
This commit is contained in:
Recep Aslantas
2018-04-06 22:57:24 +03:00
parent 967fb1afad
commit 58f0043417
2 changed files with 72 additions and 0 deletions

View File

@@ -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 */

View File

@@ -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 */