summaryrefslogtreecommitdiff
path: root/src/util/numeric.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/numeric.h')
-rw-r--r--src/util/numeric.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util/numeric.h b/src/util/numeric.h
index ccc9fbee4..74c1dfea6 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -249,6 +249,28 @@ int myrand_range(int min, int max);
Miscellaneous functions
*/
+inline u32 get_bits(u32 x, u32 pos, u32 len)
+{
+ u32 mask = (1 << len) - 1;
+ return (x >> pos) & mask;
+}
+
+inline void set_bits(u32 *x, u32 pos, u32 len, u32 val)
+{
+ u32 mask = (1 << len) - 1;
+ *x &= ~(mask << len);
+ *x |= (val & mask) << pos;
+}
+
+inline u32 calc_parity(u32 v)
+{
+ v ^= v >> 16;
+ v ^= v >> 8;
+ v ^= v >> 4;
+ v &= 0xf;
+ return (0x6996 >> v) & 1;
+}
+
u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed);
bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,