9#ifndef __MATH_BASE_INLINE_C__
10#define __MATH_BASE_INLINE_C__
25# define UNLIKELY(x) __builtin_expect(!!(x), 0)
27# define UNLIKELY(x) (x)
60 return (
float)(
exp(
log(f) / 3.0));
70 return -
exp(
log(-d) / 3.0);
84 return (fac * target) + (1.0f - fac) * origin;
89 return (fac * target) + (1.0f - fac) * origin;
94 float range = max -
min;
95 return range == 0 ? 0 : ((
pos -
min) / range);
100 double range = max -
min;
101 return range == 0 ? 0 : ((
pos -
min) / range);
107 return (x * (
b - a)) + a;
113 return (x * (
b - a)) + a;
123 return (n & (n - 1)) == 0;
186#define _round_clamp_fl_impl(arg, ty, min, max) \
188 float r = floorf(arg + 0.5f); \
189 if (UNLIKELY(r <= (float)min)) { \
192 else if (UNLIKELY(r >= (float)max)) { \
200#define _round_clamp_db_impl(arg, ty, min, max) \
202 double r = floor(arg + 0.5); \
203 if (UNLIKELY(r <= (double)min)) { \
206 else if (UNLIKELY(r >= (double)max)) { \
214#define _round_fl_impl(arg, ty) \
216 return (ty)floorf(arg + 0.5f); \
218#define _round_db_impl(arg, ty) \
220 return (ty)floor(arg + 0.5); \
264#undef _round_clamp_fl_impl
265#undef _round_clamp_db_impl
269 return roundf(f * 0.5f) * 2.0f;
274 return (2 * a +
b) / (2 *
b);
285 return r ? d - ((a < 0) ^ (
b < 0)) : d;
290 return (a +
b - 1) /
b;
295 return (a +
b - 1) /
b;
310 return (i % n + n) % n;
315 return f - n *
floorf(f / n);
326 float range = max -
min;
327 return (range != 0.0f) ? value - (range *
floorf((value -
min) / range)) :
min;
335 return fabsf(
fractf((value - scale) / (scale * 2.0f)) * scale * 2.0f - scale);
406 return (a <
b) ? a :
b;
410 return (a >
b) ? a :
b;
417 return min_ff(a,
b) - h * h * h * c * (1.0f / 6.0f);
430 else if (x >= edge1) {
434 float t = (x - edge0) / (edge1 - edge0);
435 result = (3.0f - 2.0f * t) * (t * t);
442 return (a <
b) ? a :
b;
446 return (a >
b) ? a :
b;
451 return (a <
b) ? a :
b;
455 return (
b < a) ? a :
b;
460 return (a <
b) ? a :
b;
464 return (
b < a) ? a :
b;
469 return (a <
b) ? a :
b;
473 return (
b < a) ? a :
b;
523 return (a <
b) ? a :
b;
527 return (
b < a) ? a :
b;
532 return (a <
b) ? a :
b;
536 return (
b < a) ? a :
b;
549 else if (value <
min) {
562 return fabsf(a -
b) <= max_diff;
569 const uint sign_bit = 0x80000000;
570 const uint infinity = 0x7f800000;
579 const uint a_sign = ua.i & sign_bit;
580 const uint b_sign = ub.i & sign_bit;
581 const uint a_abs = ua.i & ~sign_bit;
582 const uint b_abs = ub.i & ~sign_bit;
584 if (a_abs > infinity || b_abs > infinity) {
588 else if (a_sign == b_sign) {
589 const uint min_abs = a_abs < b_abs ? a_abs : b_abs;
590 const uint max_abs = a_abs > b_abs ? a_abs : b_abs;
591 return max_abs - min_abs;
594 return a_abs + b_abs;
600 BLI_assert(max_ulps >= 0 && max_ulps < (1 << 22));
602 if (
fabsf(a -
b) <= max_diff) {
611 const float abs_diff =
fabsf(value1 - value2);
614 if (
fabsf(value2) < 1) {
615 return abs_diff > thresh;
618 return abs_diff > thresh *
fabsf(value2);
623 return (f < 0.0f) ? -1.0f : 1.0f;
667 return (f == 0.0f) ? 0 : (
int)
floor(log10(
fabs(f))) + 1;
677 return (
int)log10((
double)i) + 1;
683 return (
unsigned char)((
684 (val <= 0.0f) ? 0 : ((val > (1.0f - 0.5f / 255.0f)) ? 255 : ((255.0f * val) + 0.5f))));
686#define unit_float_to_uchar_clamp(val) \
687 ((CHECK_TYPE_INLINE_NONCONST((val), float)), unit_float_to_uchar_clamp(val))
691 return (
unsigned short)((val >= 1.0f - 0.5f / 65535) ? 65535 :
693 (val * 65535.0f + 0.5f));
695#define unit_float_to_ushort_clamp(val) \
696 ((CHECK_TYPE_INLINE_NONCONST(val, float)), unit_float_to_ushort_clamp(val))
700 return (
unsigned char)(((val) >= 65535 - 128) ? 255 : ((val) + 128) >> 8);
702#define unit_ushort_to_uchar(val) \
703 ((CHECK_TYPE_INLINE_NONCONST(val, unsigned short)), unit_ushort_to_uchar(val))
705#define unit_float_to_uchar_clamp_v3(v1, v2) \
707 (v1)[0] = unit_float_to_uchar_clamp((v2[0])); \
708 (v1)[1] = unit_float_to_uchar_clamp((v2[1])); \
709 (v1)[2] = unit_float_to_uchar_clamp((v2[2])); \
712#define unit_float_to_uchar_clamp_v4(v1, v2) \
714 (v1)[0] = unit_float_to_uchar_clamp((v2[0])); \
715 (v1)[1] = unit_float_to_uchar_clamp((v2[1])); \
716 (v1)[2] = unit_float_to_uchar_clamp((v2[2])); \
717 (v1)[3] = unit_float_to_uchar_clamp((v2[3])); \
local_group_size(16, 16) .push_constant(Type b
pow(value.r - subtrahend, 2.0)") .do_static_compilation(true)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
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 unsigned short round_fl_to_ushort_clamp(float a)
MINLINE uint min_uu(uint a, uint b)
MINLINE float max_ffff(float a, float b, float c, float d)
MINLINE unsigned int round_db_to_uint_clamp(double a)
MINLINE unsigned int log2_ceil_u(unsigned int x)
MINLINE signed char round_fl_to_char(float a)
MINLINE int power_of_2_min_i(int n)
MINLINE double min_ddd(double a, double b, double c)
MINLINE int round_fl_to_int(float a)
MINLINE short round_db_to_short_clamp(double a)
MINLINE signed char round_db_to_char_clamp(double a)
MINLINE float max_ff(float a, float b)
MINLINE unsigned int cube_uint(unsigned int a)
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 short round_db_to_short(double a)
MINLINE int power_of_2_max_i(int n)
MINLINE float fractf(float a)
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 unsigned short round_fl_to_ushort(float a)
MINLINE float pow2f(float x)
MINLINE unsigned int round_fl_to_uint_clamp(float a)
MINLINE double square_d(double a)
#define unit_float_to_ushort_clamp(val)
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 double scalenormd(double a, double b, double x)
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 cube_s(short a)
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 short round_fl_to_short_clamp(float a)
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 unsigned int round_db_to_uint(double a)
#define unit_float_to_uchar_clamp(val)
MINLINE unsigned int power_of_2_min_u(unsigned int x)
MINLINE double min_dd(double a, double b)
MINLINE signed char round_fl_to_char_clamp(float a)
MINLINE float smoothminf(float a, float b, float c)
MINLINE float cube_f(float a)
MINLINE unsigned short round_db_to_ushort_clamp(double a)
MINLINE float scalenorm(float a, float b, float x)
MINLINE unsigned char round_fl_to_uchar_clamp(float a)
MINLINE double cube_d(double 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)
#define unit_ushort_to_uchar(val)
MINLINE double interpd(double target, double origin, double fac)
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 char min_cc(char a, char b)
MINLINE signed char round_db_to_char(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 int max_iii(int a, int b, int c)
MINLINE size_t clamp_z(size_t value, size_t min, size_t max)
MINLINE unsigned short round_db_to_ushort(double a)
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 int cube_uchar(unsigned char a)
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 int square_uchar(unsigned char a)
MINLINE float pow4f(float x)
MINLINE float sqrt3f(float f)
MINLINE char max_cc(char a, char b)
MINLINE float pow7f(float x)
MINLINE float wrapf(float value, float max, float min)
MINLINE unsigned char round_db_to_uchar(double a)
ccl_device_inline float2 floor(const float2 a)
ccl_device_inline float2 fabs(const float2 a)
ccl_device_inline float3 exp(float3 v)
ccl_device_inline float3 ceil(const float3 a)
ccl_device_inline float3 log(float3 v)
unsigned __int64 uint64_t