mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
get sign of float helper as -1, +1 and 0
* add clarification for zero input
This commit is contained in:
@@ -13,6 +13,7 @@ Table of contents (click to go):
|
|||||||
Functions:
|
Functions:
|
||||||
|
|
||||||
1. :c:func:`glm_sign`
|
1. :c:func:`glm_sign`
|
||||||
|
#. :c:func:`glm_signf`
|
||||||
#. :c:func:`glm_rad`
|
#. :c:func:`glm_rad`
|
||||||
#. :c:func:`glm_deg`
|
#. :c:func:`glm_deg`
|
||||||
#. :c:func:`glm_make_rad`
|
#. :c:func:`glm_make_rad`
|
||||||
@@ -27,7 +28,9 @@ Functions documentation
|
|||||||
|
|
||||||
.. c:function:: int glm_sign(int val)
|
.. 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:
|
Parameters:
|
||||||
| *[in]* **val** an integer
|
| *[in]* **val** an integer
|
||||||
@@ -35,6 +38,18 @@ Functions documentation
|
|||||||
Returns:
|
Returns:
|
||||||
sign of given number
|
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)
|
.. c:function:: float glm_rad(float deg)
|
||||||
|
|
||||||
| convert degree to radians
|
| convert degree to radians
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
#include "common.h"
|
#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
|
* @param val integer value
|
||||||
*/
|
*/
|
||||||
@@ -31,6 +33,19 @@ glm_sign(int val) {
|
|||||||
return ((val >> 31) - (-val >> 31));
|
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
|
* @brief convert degree to radians
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user