25# define UNLIKELY(x) __builtin_expect(!!(x), 0)
27# define UNLIKELY(x) (x)
53 if (f == 0.0f) [[unlikely]] {
56 if (f < 0.0f) [[unlikely]] {
64 if (d == 0.0) [[unlikely]] {
67 if (d < 0.0) [[unlikely]] {
68 return -
exp(
log(-d) / 3.0);
80 return (fac * target) + (1.0f - fac) * origin;
85 return (fac * target) + (1.0f - fac) * origin;
91 return range == 0 ? 0 : ((pos -
min) / range);
97 return range == 0 ? 0 : ((pos -
min) / range);
107 return (n & (n - 1)) == 0;
158#define _round_clamp_fl_impl(arg, ty, min, max) \
160 float r = floorf(arg + 0.5f); \
161 if (r <= float(min)) [[unlikely]] { \
164 if (r >= float(max)) [[unlikely]] { \
170#define _round_clamp_db_impl(arg, ty, min, max) \
172 double r = floor(arg + 0.5); \
173 if (r <= double(min)) [[unlikely]] { \
176 if (r >= double(max)) [[unlikely]] { \
182#define _round_fl_impl(arg, ty) \
184 return (ty)floorf(arg + 0.5f); \
186#define _round_db_impl(arg, ty) \
188 return (ty)floor(arg + 0.5); \
211#undef _round_clamp_fl_impl
212#undef _round_clamp_db_impl
216 return roundf(f * 0.5f) * 2.0f;
221 return (2 * a +
b) / (2 *
b);
232 return r ? d - ((a < 0) ^ (
b < 0)) : d;
237 return (a +
b - 1) /
b;
242 return (a +
b - 1) /
b;
257 return (i % n + n) % n;
262 return f - n *
floorf(f / n);
274 return (range != 0.0f) ? value - (range *
floorf((value -
min) / range)) :
min;
323 return (a <
b) ? a :
b;
327 return (a >
b) ? a :
b;
334 return min_ff(a,
b) - h * h * h * c * (1.0f / 6.0f);
345 else if (
x >= edge1) {
349 float t = (
x - edge0) / (edge1 - edge0);
350 result = (3.0f - 2.0f * t) * (t * t);
357 return (a <
b) ? a :
b;
361 return (a >
b) ? a :
b;
366 return (a <
b) ? a :
b;
370 return (
b < a) ? a :
b;
375 return (a <
b) ? a :
b;
379 return (
b < a) ? a :
b;
384 return (a <
b) ? a :
b;
388 return (
b < a) ? a :
b;
393 return (a <
b) ? a :
b;
397 return (
b < a) ? a :
b;
418 return fabsf(a -
b) <= max_diff;
425 const uint sign_bit = 0x80000000;
426 const uint infinity = 0x7f800000;
435 const uint a_sign = ua.i & sign_bit;
436 const uint b_sign = ub.i & sign_bit;
437 const uint a_abs = ua.i & ~sign_bit;
438 const uint b_abs = ub.i & ~sign_bit;
440 if (a_abs > infinity || b_abs > infinity) {
444 if (a_sign == b_sign) {
445 const uint min_abs = a_abs < b_abs ? a_abs : b_abs;
446 const uint max_abs = a_abs > b_abs ? a_abs : b_abs;
447 return max_abs - min_abs;
449 return a_abs + b_abs;
454 BLI_assert(max_ulps >= 0 && max_ulps < (1 << 22));
456 if (
fabsf(a -
b) <= max_diff) {
465 const float abs_diff =
fabsf(value1 - value2);
468 if (
fabsf(value2) < 1) {
469 return abs_diff > thresh;
472 return abs_diff > thresh *
fabsf(value2);
477 if (!isfinite(value)) {
490 else if (
v.f < -0.0f) {
502 if (!isfinite(value)) {
515 else if (
v.f < -0.0f) {
527 return (f < 0.0f) ? -1.0f : 1.0f;
565 return (f == 0.0f) ? 0 : int(
floor(log10(
fabs(f)))) + 1;
570 return (d == 0.0) ? 0 : int(
floor(log10(
fabs(d)))) + 1;
575 return int(log10(
double(i))) + 1;
581 return static_cast<unsigned char>(
582 ((val <= 0.0f) ? 0 : ((val > (1.0f - 0.5f / 255.0f)) ? 255 : ((255.0f * val) + 0.5f))));
587 return static_cast<unsigned short>((val >= 1.0f - 0.5f / 65535) ? 65535 :
589 (val * 65535.0f + 0.5f));
594 return static_cast<unsigned char>(((val) >= 65535 - 128) ? 255 : ((val) + 128) >> 8);
597#define unit_float_to_uchar_clamp_v3(v1, v2) \
599 (v1)[0] = unit_float_to_uchar_clamp((v2[0])); \
600 (v1)[1] = unit_float_to_uchar_clamp((v2[1])); \
601 (v1)[2] = unit_float_to_uchar_clamp((v2[2])); \
604#define unit_float_to_uchar_clamp_v4(v1, v2) \
606 (v1)[0] = unit_float_to_uchar_clamp((v2[0])); \
607 (v1)[1] = unit_float_to_uchar_clamp((v2[1])); \
608 (v1)[2] = unit_float_to_uchar_clamp((v2[2])); \
609 (v1)[3] = unit_float_to_uchar_clamp((v2[3])); \
float3x3 scale(float3x3 mat, float2 scale)
#define _round_clamp_fl_impl(arg, ty, min, max)
#define _round_fl_impl(arg, ty)
#define _round_db_impl(arg, ty)
#define _round_clamp_db_impl(arg, ty, min, max)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
MINLINE float min_ff(float a, float b)
MINLINE unsigned char round_db_to_uchar_clamp(double a)
MINLINE unsigned int round_fl_to_uint(float a)
MINLINE int round_fl_to_int_clamp(float a)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE unsigned long long max_ulul(unsigned long long a, unsigned long long b)
MINLINE double min_dd(double a, double b)
MINLINE unsigned long long min_ulul(unsigned long long a, unsigned long long b)
unsigned __int64 uint64_t
MINLINE short round_fl_to_short(float a)
MINLINE int mod_i(int i, int n)
MINLINE int compare_ff_relative(float a, float b, float max_diff, int max_ulps)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
MINLINE float wrapf(float value, float max, float min)
MINLINE unsigned char round_fl_to_uchar(float a)
MINLINE int round_fl_to_int(float a)
MINLINE int square_i(int a)
MINLINE int power_of_2_min_i(int n)
MINLINE int round_db_to_int_clamp(double a)
MINLINE double interpd(double target, double origin, double t)
MINLINE int integer_digits_i(int i)
MINLINE int power_of_2_max_i(int n)
MINLINE float fractf(float a)
MINLINE uint max_uu(uint a, uint b)
MINLINE int signum_i_ex(float a, float eps)
MINLINE int max_ii(int a, int b)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MINLINE bool compare_threshold_relative(float value1, float value2, float thresh)
MINLINE float cube_f(float a)
MINLINE uint ulp_diff_ff(float a, float b)
MINLINE unsigned int power_of_2_max_u(unsigned int x)
MINLINE float pow3f(float x)
MINLINE unsigned int log2_ceil_u(unsigned int x)
MINLINE float sqrtf_signed(float f)
MINLINE float pow4f(float x)
MINLINE double ratiod(double min, double max, double pos)
MINLINE float pow2f(float x)
MINLINE float increment_ulp(float value)
MINLINE int integer_digits_f(float f)
MINLINE size_t max_zz(size_t a, size_t b)
MINLINE int cube_i(int a)
MINLINE float pow5f(float x)
MINLINE int divide_round_i(int a, int b)
MINLINE uint64_t ceil_to_multiple_ul(uint64_t a, uint64_t b)
MINLINE uint64_t divide_ceil_ul(uint64_t a, uint64_t b)
MINLINE int signum_i(float a)
MINLINE float pingpongf(float value, float scale)
MINLINE float signf(float f)
MINLINE size_t min_zz(size_t a, size_t b)
MINLINE float power_of_2(float f)
MINLINE double max_dd(double a, double b)
MINLINE float sqrt3f(float f)
MINLINE float decrement_ulp(float value)
MINLINE float pow7f(float x)
MINLINE float smoothstep(float edge0, float edge1, float x)
MINLINE float compatible_signf(float f)
MINLINE double sqrt3d(double d)
MINLINE float smoothminf(float a, float b, float c)
MINLINE unsigned char unit_ushort_to_uchar(unsigned short val)
MINLINE unsigned int log2_floor_u(unsigned int x)
MINLINE unsigned short unit_float_to_ushort_clamp(float val)
MINLINE float ratiof(float min, float max, float pos)
MINLINE float max_ff(float a, float b)
MINLINE uint divide_ceil_u(uint a, uint b)
MINLINE float square_f(float a)
MINLINE unsigned char round_fl_to_uchar_clamp(float a)
MINLINE float interpf(float target, float origin, float t)
MINLINE float round_to_even(float f)
MINLINE int square_s(short a)
MINLINE uint ceil_to_multiple_u(uint a, uint b)
MINLINE short round_db_to_short_clamp(double a)
MINLINE int integer_digits_d(double d)
MINLINE int is_power_of_2_i(int n)
MINLINE int min_ii(int a, int b)
MINLINE int clamp_i(int value, int min, int max)
MINLINE int divide_floor_i(int a, int b)
MINLINE unsigned int square_uint(unsigned int a)
MINLINE int compare_ff(float a, float b, float max_diff)
MINLINE int round_db_to_int(double a)
MINLINE float floored_fmod(float f, float n)
MINLINE float clamp_f(float value, float min, float max)
MINLINE uint min_uu(uint a, uint b)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float