9#ifndef __MATH_BASE_INLINE_C__
10#define __MATH_BASE_INLINE_C__
24# define UNLIKELY(x) __builtin_expect(!!(x), 0)
26# define UNLIKELY(x) (x)
58 return (
float)(
exp(
log(f) / 3.0));
67 return -
exp(
log(-d) / 3.0);
79 return (fac * target) + (1.0f - fac) * origin;
84 return (fac * target) + (1.0f - fac) * origin;
90 return range == 0 ? 0 : ((
pos -
min) / range);
96 return range == 0 ? 0 : ((
pos -
min) / range);
106 return (n & (n - 1)) == 0;
157#define _round_clamp_fl_impl(arg, ty, min, max) \
159 float r = floorf(arg + 0.5f); \
160 if (UNLIKELY(r <= (float)min)) { \
163 if (UNLIKELY(r >= (float)max)) { \
169#define _round_clamp_db_impl(arg, ty, min, max) \
171 double r = floor(arg + 0.5); \
172 if (UNLIKELY(r <= (double)min)) { \
175 if (UNLIKELY(r >= (double)max)) { \
181#define _round_fl_impl(arg, ty) \
183 return (ty)floorf(arg + 0.5f); \
185#define _round_db_impl(arg, ty) \
187 return (ty)floor(arg + 0.5); \
210#undef _round_clamp_fl_impl
211#undef _round_clamp_db_impl
215 return roundf(f * 0.5f) * 2.0f;
220 return (2 * a +
b) / (2 *
b);
231 return r ? d - ((a < 0) ^ (
b < 0)) : d;
236 return (a +
b - 1) /
b;
241 return (a +
b - 1) /
b;
256 return (
i % n + n) % n;
261 return f - n *
floorf(f / n);
273 return (range != 0.0f) ? value - (range *
floorf((value -
min) / range)) :
min;
281 return fabsf(
fractf((value - scale) / (scale * 2.0f)) * scale * 2.0f - scale);
322 return (a <
b) ? a :
b;
326 return (a >
b) ? a :
b;
333 return min_ff(a,
b) - h * h * h * c * (1.0f / 6.0f);
344 else if (
x >= edge1) {
348 float t = (
x - edge0) / (edge1 - edge0);
349 result = (3.0f - 2.0f * t) * (t * t);
356 return (a <
b) ? a :
b;
360 return (a >
b) ? a :
b;
365 return (a <
b) ? a :
b;
369 return (
b < a) ? a :
b;
374 return (a <
b) ? a :
b;
378 return (
b < a) ? a :
b;
383 return (a <
b) ? a :
b;
387 return (
b < a) ? a :
b;
433 return (a <
b) ? a :
b;
437 return (
b < a) ? a :
b;
458 return fabsf(a -
b) <= max_diff;
465 const uint sign_bit = 0x80000000;
466 const uint infinity = 0x7f800000;
475 const uint a_sign = ua.i & sign_bit;
476 const uint b_sign = ub.i & sign_bit;
477 const uint a_abs = ua.i & ~sign_bit;
478 const uint b_abs = ub.i & ~sign_bit;
480 if (a_abs > infinity || b_abs > infinity) {
484 if (a_sign == b_sign) {
485 const uint min_abs = a_abs < b_abs ? a_abs : b_abs;
486 const uint max_abs = a_abs > b_abs ? a_abs : b_abs;
487 return max_abs - min_abs;
489 return a_abs + b_abs;
494 BLI_assert(max_ulps >= 0 && max_ulps < (1 << 22));
496 if (
fabsf(a -
b) <= max_diff) {
505 const float abs_diff =
fabsf(value1 - value2);
508 if (
fabsf(value2) < 1) {
509 return abs_diff > thresh;
512 return abs_diff > thresh *
fabsf(value2);
517 if (!isfinite(value)) {
530 else if (
v.f < -0.0f) {
542 if (!isfinite(value)) {
555 else if (
v.f < -0.0f) {
567 return (f < 0.0f) ? -1.0f : 1.0f;
605 return (f == 0.0f) ? 0 : (int)
floor(log10(
fabs(f))) + 1;
610 return (d == 0.0) ? 0 : (int)
floor(log10(
fabs(d))) + 1;
615 return (
int)log10((
double)
i) + 1;
621 return (
unsigned char)((
622 (val <= 0.0f) ? 0 : ((val > (1.0f - 0.5f / 255.0f)) ? 255 : ((255.0f * val) + 0.5f))));
627 return (
unsigned short)((val >= 1.0f - 0.5f / 65535) ? 65535 :
629 (val * 65535.0f + 0.5f));
634 return (
unsigned char)(((val) >= 65535 - 128) ? 255 : ((val) + 128) >> 8);
637#define unit_float_to_uchar_clamp_v3(v1, v2) \
639 (v1)[0] = unit_float_to_uchar_clamp((v2[0])); \
640 (v1)[1] = unit_float_to_uchar_clamp((v2[1])); \
641 (v1)[2] = unit_float_to_uchar_clamp((v2[2])); \
644#define unit_float_to_uchar_clamp_v4(v1, v2) \
646 (v1)[0] = unit_float_to_uchar_clamp((v2[0])); \
647 (v1)[1] = unit_float_to_uchar_clamp((v2[1])); \
648 (v1)[2] = unit_float_to_uchar_clamp((v2[2])); \
649 (v1)[3] = unit_float_to_uchar_clamp((v2[3])); \
ATTR_WARN_UNUSED_RESULT const BMVert * v
unsigned long long int uint64_t
MINLINE int round_fl_to_int_clamp(float a)
MINLINE unsigned char round_fl_to_uchar(float a)
MINLINE float max_fff(float a, float b, float c)
MINLINE uint ceil_to_multiple_u(uint a, uint b)
MINLINE double max_ddd(double a, double b, double c)
#define _round_clamp_fl_impl(arg, ty, min, max)
MINLINE uint min_uu(uint a, uint b)
MINLINE float max_ffff(float a, float b, float c, float d)
MINLINE float decrement_ulp(const float value)
MINLINE unsigned int log2_ceil_u(unsigned int x)
MINLINE int power_of_2_min_i(int n)
MINLINE int round_fl_to_int(float a)
MINLINE short round_db_to_short_clamp(double a)
MINLINE float max_ff(float a, float b)
MINLINE size_t min_zz(size_t a, size_t b)
MINLINE int min_ii(int a, int b)
MINLINE uint divide_ceil_u(uint a, uint b)
MINLINE unsigned char unit_ushort_to_uchar(unsigned short val)
MINLINE int power_of_2_max_i(int n)
MINLINE int compare_ff(float a, float b, const float max_diff)
MINLINE float power_of_2(float val)
MINLINE float min_ffff(float a, float b, float c, float d)
MINLINE unsigned int power_of_2_max_u(unsigned int x)
MINLINE uint max_uu(uint a, uint b)
MINLINE bool compare_threshold_relative(const float value1, const float value2, const float thresh)
#define _round_fl_impl(arg, ty)
MINLINE int cube_i(int a)
#define _round_db_impl(arg, ty)
MINLINE float pow2f(float x)
MINLINE double ratiod(double min, double max, double pos)
MINLINE float clamp_f(float value, float min, float max)
MINLINE int divide_floor_i(int a, int b)
MINLINE float min_ff(float a, float b)
MINLINE size_t max_zz(size_t a, size_t b)
MINLINE unsigned long long min_ulul(unsigned long long a, unsigned long long b)
MINLINE unsigned long long max_ulul(unsigned long long a, unsigned long long b)
MINLINE int integer_digits_d(const double d)
MINLINE int square_i(int a)
MINLINE float floored_fmod(const float f, const float n)
MINLINE float pow5f(float x)
MINLINE int max_ii(int a, int b)
MINLINE short round_fl_to_short(float a)
MINLINE uint64_t divide_ceil_ul(uint64_t a, uint64_t b)
MINLINE double min_dd(double a, double b)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
MINLINE float smoothminf(float a, float b, float c)
MINLINE float cube_f(float a)
MINLINE unsigned char round_fl_to_uchar_clamp(float a)
MINLINE int min_iii(int a, int b, int c)
MINLINE int divide_round_i(int a, int b)
MINLINE int integer_digits_f(const float f)
MINLINE int integer_digits_i(const int i)
MINLINE int mod_i(int i, int n)
MINLINE double interpd(double target, double origin, double fac)
MINLINE unsigned short unit_float_to_ushort_clamp(float val)
MINLINE float square_f(float a)
MINLINE unsigned int round_fl_to_uint(float a)
MINLINE float pingpongf(float value, float scale)
MINLINE float interpf(float target, float origin, float fac)
MINLINE float sqrtf_signed(float f)
MINLINE double max_dd(double a, double b)
MINLINE uint ulp_diff_ff(float a, float b)
MINLINE int round_db_to_int_clamp(double a)
MINLINE int is_power_of_2_i(int n)
MINLINE float pow3f(float x)
MINLINE int compare_ff_relative(float a, float b, const float max_diff, const int max_ulps)
MINLINE double sqrt3d(double d)
MINLINE int round_db_to_int(double a)
MINLINE int max_iiii(int a, int b, int c, int d)
MINLINE float min_fff(float a, float b, float c)
MINLINE int signum_i_ex(float a, float eps)
MINLINE int min_iiii(int a, int b, int c, int d)
MINLINE unsigned int log2_floor_u(unsigned int x)
MINLINE float signf(float f)
MINLINE float increment_ulp(const float value)
MINLINE int max_iii(int a, int b, int c)
MINLINE int clamp_i(int value, int min, int max)
MINLINE int signum_i(float a)
MINLINE float ratiof(float min, float max, float pos)
MINLINE float smoothstep(float edge0, float edge1, float x)
MINLINE float round_to_even(float f)
#define _round_clamp_db_impl(arg, ty, min, max)
MINLINE unsigned int square_uint(unsigned int a)
MINLINE int square_s(short a)
MINLINE uint64_t ceil_to_multiple_ul(uint64_t a, uint64_t b)
MINLINE float compatible_signf(float f)
MINLINE unsigned char round_db_to_uchar_clamp(double a)
MINLINE float pow4f(float x)
MINLINE float sqrt3f(float f)
MINLINE float pow7f(float x)
MINLINE float wrapf(float value, float max, float min)
ccl_device_inline float2 fabs(const float2 a)