Skip to content

Commit

Permalink
vector utils: isnan and isinf
Browse files Browse the repository at this point in the history
* a vector which has least one NaN or INF member, is assumed not valid vector.
  • Loading branch information
recp committed Apr 6, 2018
1 parent 967fb1a commit 58f0043
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions include/cglm/vec3-ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
36 changes: 36 additions & 0 deletions include/cglm/vec4-ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 58f0043

Please sign in to comment.