diff options
-rw-r--r-- | source/blender/blenlib/BLI_math_bits.h | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_bits_inline.c | 33 |
2 files changed, 39 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_bits.h b/source/blender/blenlib/BLI_math_bits.h index 876c0d92e31..1ac98a682d1 100644 --- a/source/blender/blenlib/BLI_math_bits.h +++ b/source/blender/blenlib/BLI_math_bits.h @@ -40,6 +40,12 @@ MINLINE unsigned short highest_order_bit_s(unsigned short n); MINLINE int count_bits_i(unsigned int n); #endif +MINLINE int float_as_int(float f); +MINLINE unsigned int float_as_uint(float f); +MINLINE float int_as_float(int i); +MINLINE float uint_as_float(unsigned int i); +MINLINE float xor_fl(float x, int y); + #if BLI_MATH_DO_INLINE #include "intern/math_bits_inline.c" #endif diff --git a/source/blender/blenlib/intern/math_bits_inline.c b/source/blender/blenlib/intern/math_bits_inline.c index 11ee6e7fa5b..82d7e2114c2 100644 --- a/source/blender/blenlib/intern/math_bits_inline.c +++ b/source/blender/blenlib/intern/math_bits_inline.c @@ -56,4 +56,37 @@ MINLINE int count_bits_i(unsigned int i) } #endif +MINLINE int float_as_int(float f) +{ + union { int i; float f; } u; + u.f = f; + return u.i; +} + +MINLINE unsigned int float_as_uint(float f) +{ + union { unsigned int i; float f; } u; + u.f = f; + return u.i; +} + +MINLINE float int_as_float(int i) +{ + union { int i; float f; } u; + u.i = i; + return u.f; +} + +MINLINE float uint_as_float(unsigned int i) +{ + union { unsigned int i; float f; } u; + u.i = i; + return u.f; +} + +MINLINE float xor_fl(float x, int y) +{ + return int_as_float(float_as_int(x) ^ y); +} + #endif /* __MATH_BITS_INLINE_C__ */ |