diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-09-27 04:13:03 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-09-27 04:13:03 +0300 |
commit | 43b49130516db974c125d89919fe8ddc25cf4405 (patch) | |
tree | 0ed06e3090a10ef20ea4682edd2c3b61f5937624 /source/blender/blenlib/intern/math_base_inline.c | |
parent | 870dfb1b5aac1c5c4dbcce0f8318c11d229bf3ac (diff) |
Math Lib: Add non-clamped round_* functions
Replace iroundf with round_fl_to_int, add other types
Diffstat (limited to 'source/blender/blenlib/intern/math_base_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 37efe95791c..749c18fc0ce 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -184,11 +184,6 @@ MINLINE unsigned power_of_2_min_u(unsigned x) /* rounding and clamping */ -MINLINE int iroundf(float a) -{ - return (int)floorf(a + 0.5f); -} - #define _round_clamp_fl_impl(arg, ty, min, max) { \ float r = floorf(arg + 0.5f); \ if (UNLIKELY(r <= (float)min)) return (ty)min; \ @@ -203,6 +198,26 @@ MINLINE int iroundf(float a) else return (ty)r; \ } +#define _round_fl_impl(arg, ty) { return (ty)floorf(arg + 0.5f); } +#define _round_db_impl(arg, ty) { return (ty)floor(arg + 0.5); } + +MINLINE signed char round_fl_to_char(float a) { _round_fl_impl(a, signed char) } +MINLINE unsigned char round_fl_to_uchar(float a) { _round_fl_impl(a, unsigned char) } +MINLINE short round_fl_to_short(float a) { _round_fl_impl(a, short) } +MINLINE unsigned short round_fl_to_ushort(float a) { _round_fl_impl(a, unsigned short) } +MINLINE int round_fl_to_int(float a) { _round_fl_impl(a, int) } +MINLINE unsigned int round_fl_to_uint(float a) { _round_fl_impl(a, unsigned int) } + +MINLINE signed char round_db_to_char(double a) { _round_db_impl(a, signed char) } +MINLINE unsigned char round_db_to_uchar(double a) { _round_db_impl(a, unsigned char) } +MINLINE short round_db_to_short(double a) { _round_db_impl(a, short) } +MINLINE unsigned short round_db_to_ushort(double a) { _round_db_impl(a, unsigned short) } +MINLINE int round_db_to_int(double a) { _round_db_impl(a, int) } +MINLINE unsigned int round_db_to_uint(double a) { _round_db_impl(a, unsigned int) } + +#undef _round_fl_impl +#undef _round_db_impl + MINLINE signed char round_fl_to_char_clamp(float a) { _round_clamp_fl_impl(a, signed char, SCHAR_MIN, SCHAR_MAX) } MINLINE unsigned char round_fl_to_uchar_clamp(float a) { _round_clamp_fl_impl(a, unsigned char, 0, UCHAR_MAX) } MINLINE short round_fl_to_short_clamp(float a) { _round_clamp_fl_impl(a, short, SHRT_MIN, SHRT_MAX) } |