[MIRROR] Protect against floating-point inaccuracy in log() [MDB IGNORE] (#13600)

* Protect against floating-point inaccuracy in log() (#66875)

This was causing issues with indexing icon slots (the main user of TOBITSHIFT). See BeeStation/BeeStation-Hornet#6842 for more details.
Probably fixes #66197 and fixes #65652. (In all my tests, I could never get anything to show in suit_storage, whereas those bugs are reporting intermittent issues.)
Originally made for BeeStation/BeeStation-Hornet#6842 (which also affects TG).

* Protect against floating-point inaccuracy in log()

Co-authored-by: David Walker <d0sboots@gmail.com>
This commit is contained in:
SkyratBot
2022-05-14 07:24:18 -07:00
committed by GitHub
co-authored by David Walker
parent 5de534a80a
commit 7806934960
+2 -1
View File
@@ -117,7 +117,8 @@
#define TORADIANS(degrees) ((degrees) * 0.0174532925)
/// Gets shift x that would be required the bitflag (1<<x)
#define TOBITSHIFT(bit) ( log(2, bit) )
/// We need the round because log has floating-point inaccuracy, and if we undershoot at all on list indexing we'll get the wrong index.
#define TOBITSHIFT(bit) ( round(log(2, bit), 1) )
// Will filter out extra rotations and negative rotations
// E.g: 540 becomes 180. -180 becomes 180.