From 598ab525da3df3fef2033c159c570688c7282a8f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 6 Mar 2020 17:18:10 +0100 Subject: Cleanup: Replace ABS/SQUARE/CUBE with function calls While it might be handy to have type-less functionality which is similar to how C++ math is implemented it can not be easily achieved with just preprocessor in a way which does not have side-effects on wrong usage. There macros where often used on a non-trivial expression, and there was at least one usage where it was causing an actual side effect/bug on Windows (see change around square_f(sh[index++]) in studiolight.c). For such cases it is handy to have a function which is guaranteed to have zero side-effects. The motivation behind actually removing the macros is that there is already a way to do similar calculation. Also, not having such macros is a way to guarantee that its usage is not changed in a way which have side-effects and that it's not used as an inspiration for cases where it should not be used. Differential Revision: https://developer.blender.org/D7051 --- source/blender/blenlib/intern/math_base_inline.c | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'source/blender/blenlib/intern/math_base_inline.c') diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index c0ee658d434..a293695154a 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -375,6 +375,72 @@ MINLINE float wrapf(float value, float max, float min) return (range != 0.0f) ? value - (range * floorf((value - min) / range)) : min; } +// Square. + +MINLINE int square_s(short a) +{ + return a * a; +} + +MINLINE int square_i(int a) +{ + return a * a; +} + +MINLINE unsigned int square_uint(unsigned int a) +{ + return a * a; +} + +MINLINE int square_uchar(unsigned char a) +{ + return a * a; +} + +MINLINE float square_f(float a) +{ + return a * a; +} + +MINLINE double square_d(double a) +{ + return a * a; +} + +// Cube. + +MINLINE int cube_s(short a) +{ + return a * a * a; +} + +MINLINE int cube_i(int a) +{ + return a * a * a; +} + +MINLINE unsigned int cube_uint(unsigned int a) +{ + return a * a * a; +} + +MINLINE int cube_uchar(unsigned char a) +{ + return a * a * a; +} + +MINLINE float cube_f(float a) +{ + return a * a * a; +} + +MINLINE double cube_d(double a) +{ + return a * a * a; +} + +// Min/max + MINLINE float min_ff(float a, float b) { return (a < b) ? a : b; -- cgit v1.2.3