48#if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
49# define _USE_MATH_DEFINES
58# define M_PI 3.14159265358979323846
61# define M_PI_2 1.57079632679489661923
64# define M_PI_4 0.78539816339744830962
67# define M_SQRT2 1.41421356237309504880
70# define M_SQRT1_2 0.70710678118654752440
73# define M_SQRT3 1.73205080756887729352
76# define M_SQRT1_3 0.57735026918962576450
79# define M_1_PI 0.318309886183790671538
82# define M_E 2.7182818284590452354
85# define M_LOG2E 1.4426950408889634074
88# define M_LOG10E 0.43429448190325182765
91# define M_LN2 0.69314718055994530942
94# define M_LN10 2.30258509299404568402
98# define NAN_FLT __builtin_nanf("")
101# define NAN_FLT (*((float *)(&NAN_INT)))
104#if BLI_MATH_DO_INLINE
108#ifdef BLI_MATH_GCC_WARN_PRAGMA
109# pragma GCC diagnostic push
110# pragma GCC diagnostic ignored "-Wredundant-decls"
372#ifdef BLI_MATH_GCC_WARN_PRAGMA
373# pragma GCC diagnostic pop
381# define BLI_ASSERT_UNIT_EPSILON 0.0002f
382# define BLI_ASSERT_UNIT_EPSILON_DB 0.0002
388# define BLI_ASSERT_UNIT_V3(v) \
390 const float _test_unit = len_squared_v3(v); \
391 BLI_assert(!(fabsf(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \
392 !(fabsf(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \
396# define BLI_ASSERT_UNIT_V3_DB(v) \
398 const double _test_unit = len_squared_v3_db(v); \
399 BLI_assert(!(fabs(_test_unit - 1.0) >= BLI_ASSERT_UNIT_EPSILON_DB) || \
400 !(fabs(_test_unit) >= BLI_ASSERT_UNIT_EPSILON_DB)); \
404# define BLI_ASSERT_UNIT_V2(v) \
406 const float _test_unit = len_squared_v2(v); \
407 BLI_assert(!(fabsf(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON) || \
408 !(fabsf(_test_unit) >= BLI_ASSERT_UNIT_EPSILON)); \
412# define BLI_ASSERT_UNIT_QUAT(q) \
414 const float _test_unit = dot_qtqt(q, q); \
415 BLI_assert(!(fabsf(_test_unit - 1.0f) >= BLI_ASSERT_UNIT_EPSILON * 10) || \
416 !(fabsf(_test_unit) >= BLI_ASSERT_UNIT_EPSILON * 10)); \
420# define BLI_ASSERT_ZERO_M3(m) \
422 BLI_assert(dot_vn_vn((const float *)m, (const float *)m, 9) != 0.0); \
426# define BLI_ASSERT_ZERO_M4(m) \
428 BLI_assert(dot_vn_vn((const float *)m, (const float *)m, 16) != 0.0); \
431# define BLI_ASSERT_UNIT_M3(m) \
433 BLI_ASSERT_UNIT_V3((m)[0]); \
434 BLI_ASSERT_UNIT_V3((m)[1]); \
435 BLI_ASSERT_UNIT_V3((m)[2]); \
439# define BLI_ASSERT_UNIT_V2(v) (void)(v)
440# define BLI_ASSERT_UNIT_V3(v) (void)(v)
441# define BLI_ASSERT_UNIT_V3_DB(v) (void)(v)
442# define BLI_ASSERT_UNIT_QUAT(v) (void)(v)
443# define BLI_ASSERT_ZERO_M3(m) (void)(m)
444# define BLI_ASSERT_ZERO_M4(m) (void)(m)
445# define BLI_ASSERT_UNIT_M3(m) (void)(m)
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 int integer_digits_f(float f)
MINLINE uint ceil_to_multiple_u(uint a, uint b)
MINLINE double max_ddd(double a, double b, double c)
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)
int pow_i(int base, int exp)
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 int integer_digits_d(double d)
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 int cube_i(int a)
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)
MINLINE double ratiod(double min, double max, double pos)
MINLINE float clamp_f(float value, float min, float max)
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 int cube_s(short a)
MINLINE int square_i(int a)
MINLINE short round_fl_to_short_clamp(float a)
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)
MINLINE unsigned int power_of_2_min_u(unsigned int x)
MINLINE double min_dd(double a, double b)
float floor_power_of_10(float f)
MINLINE signed char round_fl_to_char_clamp(float a)
MINLINE float cube_f(float a)
MINLINE int integer_digits_i(int i)
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 float floored_fmod(float f, float n)
MINLINE int divide_round_i(int a, int b)
MINLINE int mod_i(int i, int n)
MINLINE float power_of_2(float f)
MINLINE float square_f(float a)
MINLINE unsigned int round_fl_to_uint(float a)
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 double sqrt3d(double d)
MINLINE float interpf(float target, float origin, float t)
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 double interpd(double target, double origin, double t)
MINLINE float signf(float f)
MINLINE int max_iii(int a, int b, int c)
float ceil_power_of_10(float f)
MINLINE bool compare_threshold_relative(float value1, float value2, float thresh)
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 round_to_even(float f)
double double_round(double x, int ndigits)
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 int compare_ff_relative(float a, float b, float max_diff, int max_ulps)
MINLINE unsigned char round_db_to_uchar_clamp(double a)
MINLINE int square_uchar(unsigned char a)
MINLINE int compare_ff(float a, float b, float max_diff)
MINLINE float pow4f(float x)
MINLINE float sqrt3f(float f)
MINLINE char max_cc(char a, char b)
MINLINE float pow7f(float x)
MINLINE unsigned char round_db_to_uchar(double a)
local_group_size(16, 16) .push_constant(Type b
ccl_device_inline float3 exp(float3 v)
unsigned __int64 uint64_t