get sign of float helper as -1, +1 and 0

* add clarification for zero input
This commit is contained in:
Recep Aslantas
2018-04-02 16:18:50 +03:00
parent 54c44ff224
commit acda316c12
2 changed files with 32 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ Table of contents (click to go):
Functions:
1. :c:func:`glm_sign`
#. :c:func:`glm_signf`
#. :c:func:`glm_rad`
#. :c:func:`glm_deg`
#. :c:func:`glm_make_rad`
@@ -27,7 +28,9 @@ Functions documentation
.. c:function:: int glm_sign(int val)
| returns sign of 32 bit integer as +1 or -1
| returns sign of 32 bit integer as +1, -1, 0
| **Important**: It returns 0 for zero input
Parameters:
| *[in]* **val** an integer
@@ -35,6 +38,18 @@ Functions documentation
Returns:
sign of given number
.. c:function:: float glm_signf(float val)
| returns sign of 32 bit integer as +1.0, -1.0, 0.0
| **Important**: It returns 0.0f for zero input
Parameters:
| *[in]* **val** a float
Returns:
sign of given number
.. c:function:: float glm_rad(float deg)
| convert degree to radians

View File

@@ -21,7 +21,9 @@
#include "common.h"
/*!
* @brief get sign of 32 bit integer as +1 or -1
* @brief get sign of 32 bit integer as +1, -1, 0
*
* Important: It returns 0 for zero input
*
* @param val integer value
*/
@@ -31,6 +33,19 @@ glm_sign(int val) {
return ((val >> 31) - (-val >> 31));
}
/*!
* @brief get sign of 32 bit float as +1, -1, 0
*
* Important: It returns 0 for zero/NaN input
*
* @param val float value
*/
CGLM_INLINE
float
glm_signf(float val) {
return (val > 0.0f) - (val < 0.0f);
}
/*!
* @brief convert degree to radians
*