From acda316c12f36991f9044ed94ee70c59d23efa7c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 16:18:50 +0300 Subject: [PATCH] get sign of float helper as -1, +1 and 0 * add clarification for zero input --- docs/source/util.rst | 17 ++++++++++++++++- include/cglm/util.h | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/source/util.rst b/docs/source/util.rst index 43a9d49..a9f4066 100644 --- a/docs/source/util.rst +++ b/docs/source/util.rst @@ -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 diff --git a/include/cglm/util.h b/include/cglm/util.h index 20b4c67..2a9ece7 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -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 *