[Bf-blender-cvs] [7e37811] master: Math Lib: Add float/int conversion functions

Campbell Barton noreply at git.blender.org
Fri Aug 21 09:55:46 CEST 2015


Commit: 7e3781179e3eb37fdd1e8a65fcdfed898b8cf460
Author: Campbell Barton
Date:   Fri Aug 21 17:42:40 2015 +1000
Branches: master
https://developer.blender.org/rB7e3781179e3eb37fdd1e8a65fcdfed898b8cf460

Math Lib: Add float/int conversion functions

===================================================================

M	source/blender/blenlib/BLI_math_bits.h
M	source/blender/blenlib/intern/math_bits_inline.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_bits.h b/source/blender/blenlib/BLI_math_bits.h
index 876c0d9..1ac98a6 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 11ee6e7..82d7e21 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__ */




More information about the Bf-blender-cvs mailing list