![]() |
Bitwise confusion
-1 >> 1 returns -1 instead of 2147483647.
Meanwhile, 1 << 31 returns -2147483648. I'm trying to make a more efficient function for returning sign. In a mathematical sense, you can return val!=0?val/abs(val):0 in a piecewise sense, you can do: if (val > 0) return 1; if (val < 0) return -1; return 0; But really, all I need to do is test the value of the highest bit. Maybe a getSign function wouldn't be a bad idea because the bitwise ops don't preserve sign consistently. Also, i = 1; i <<= 1; is giving me i as 0 instead of 2. However, i = 1; i = i << 1; works. |
I'm pretty sure <<= isn't a valid operator. >_>
|
There was a bug with the shiftleft-assign, it was actually doing a shiftright-assign. Thanks for reporting, a new version of the npcserver will be uploaded soon.
Need to check the bit-operation to improve the compatibility with C-code. |
| All times are GMT +2. The time now is 11:07 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.