]> git.lizzy.rs Git - irrlicht.git/commitdiff
Replace some questionable math implementations
authorsfan5 <sfan5@live.de>
Sat, 23 Oct 2021 23:11:31 +0000 (01:11 +0200)
committersfan5 <sfan5@live.de>
Sat, 23 Oct 2021 23:23:06 +0000 (01:23 +0200)
fixes #76

include/irrMath.h

index 9ee3b273f4532b40d8566f56363a19f2478fe8e0..994f8cd200b1ece5d74113a4a9cd452006e374d8 100644 (file)
@@ -320,19 +320,17 @@ namespace core
 \r
        inline s32 s32_min(s32 a, s32 b)\r
        {\r
-               const s32 mask = (a - b) >> 31;\r
-               return (a & mask) | (b & ~mask);\r
+               return min_(a, b);\r
        }\r
 \r
        inline s32 s32_max(s32 a, s32 b)\r
        {\r
-               const s32 mask = (a - b) >> 31;\r
-               return (b & mask) | (a & ~mask);\r
+               return max_(a, b);\r
        }\r
 \r
        inline s32 s32_clamp (s32 value, s32 low, s32 high)\r
        {\r
-               return s32_min(s32_max(value,low), high);\r
+               return clamp(value, low, high);\r
        }\r
 \r
        /*\r
@@ -381,33 +379,6 @@ namespace core
        #endif\r
 #endif\r
 \r
-       //! conditional set based on mask and arithmetic shift\r
-       REALINLINE u32 if_c_a_else_b ( const s32 condition, const u32 a, const u32 b )\r
-       {\r
-               return ( ( -condition >> 31 ) & ( a ^ b ) ) ^ b;\r
-       }\r
-\r
-       //! conditional set based on mask and arithmetic shift\r
-       REALINLINE u16 if_c_a_else_b ( const s16 condition, const u16 a, const u16 b )\r
-       {\r
-               return ( ( -condition >> 15 ) & ( a ^ b ) ) ^ b;\r
-       }\r
-\r
-       //! conditional set based on mask and arithmetic shift\r
-       REALINLINE u32 if_c_a_else_0 ( const s32 condition, const u32 a )\r
-       {\r
-               return ( -condition >> 31 ) & a;\r
-       }\r
-\r
-       /*\r
-               if (condition) state |= m; else state &= ~m;\r
-       */\r
-       REALINLINE void setbit_cond ( u32 &state, s32 condition, u32 mask )\r
-       {\r
-               // 0, or any positive to mask\r
-               //s32 conmask = -condition >> 31;\r
-               state ^= ( ( -condition >> 31 ) ^ state ) & mask;\r
-       }\r
 \r
        // NOTE: This is not as exact as the c99/c++11 round function, especially at high numbers starting with 8388609\r
        //       (only low number which seems to go wrong is 0.49999997 which is rounded to 1)\r