cglm
cglm copied to clipboard
Error in glm_sign()
glm_sign(), as ((val >> 31) - (-val >> 31)) fails if val is INT_MIN. In fact, it has undefinded behaviour (shifting signed 32-bit value by 31 bits).
Using shifts, or bitwise operations in general, on signed values is a bit iffy. It would be surprising if this function was so performance-critical that this kind of branchless hack is worth it. It would be more sensible to implement it the same way as glm_signf() later inthe same source file.
Hi @pm4gh ,
Thanks, any feedback would be awesome to find the sign of number.
It would be more sensible to implement it the same way as glm_signf() later inthe same source file.
yes it could be, we can update it to that way.
getting the sign bit of 32-bit integer is as simple as: return val&0x80000000 (1 if signed, 0 otherwise)
same apply for sp-fp.