Blender  V3.3
util/math.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __UTIL_MATH_H__
5 #define __UTIL_MATH_H__
6 
7 /* Math
8  *
9  * Basic math functions on scalar and vector types. This header is used by
10  * both the kernel code when compiled as C++, and other C++ non-kernel code. */
11 
12 #ifndef __KERNEL_GPU__
13 # include <cmath>
14 #endif
15 
16 #ifdef __HIP__
17 # include <hip/hip_vector_types.h>
18 #endif
19 
20 #if !defined(__KERNEL_METAL__)
21 # include <float.h>
22 # include <math.h>
23 # include <stdio.h>
24 #endif /* !defined(__KERNEL_METAL__) */
25 
26 #include "util/types.h"
27 
29 
30 /* Float Pi variations */
31 
32 /* Division */
33 #ifndef M_PI_F
34 # define M_PI_F (3.1415926535897932f) /* pi */
35 #endif
36 #ifndef M_PI_2_F
37 # define M_PI_2_F (1.5707963267948966f) /* pi/2 */
38 #endif
39 #ifndef M_PI_4_F
40 # define M_PI_4_F (0.7853981633974830f) /* pi/4 */
41 #endif
42 #ifndef M_1_PI_F
43 # define M_1_PI_F (0.3183098861837067f) /* 1/pi */
44 #endif
45 #ifndef M_2_PI_F
46 # define M_2_PI_F (0.6366197723675813f) /* 2/pi */
47 #endif
48 #ifndef M_1_2PI_F
49 # define M_1_2PI_F (0.1591549430918953f) /* 1/(2*pi) */
50 #endif
51 #ifndef M_SQRT_PI_8_F
52 # define M_SQRT_PI_8_F (0.6266570686577501f) /* sqrt(pi/8) */
53 #endif
54 #ifndef M_LN_2PI_F
55 # define M_LN_2PI_F (1.8378770664093454f) /* ln(2*pi) */
56 #endif
57 
58 /* Multiplication */
59 #ifndef M_2PI_F
60 # define M_2PI_F (6.2831853071795864f) /* 2*pi */
61 #endif
62 #ifndef M_4PI_F
63 # define M_4PI_F (12.566370614359172f) /* 4*pi */
64 #endif
65 
66 /* Float sqrt variations */
67 #ifndef M_SQRT2_F
68 # define M_SQRT2_F (1.4142135623730950f) /* sqrt(2) */
69 #endif
70 #ifndef M_SQRT3_F
71 # define M_SQRT3_F (1.7320508075688772f) /* sqrt(3) */
72 #endif
73 #ifndef M_LN2_F
74 # define M_LN2_F (0.6931471805599453f) /* ln(2) */
75 #endif
76 #ifndef M_LN10_F
77 # define M_LN10_F (2.3025850929940457f) /* ln(10) */
78 #endif
79 
80 /* Scalar */
81 
82 #if !defined(__HIP__) && !defined(__KERNEL_ONEAPI__)
83 # ifdef _WIN32
84 ccl_device_inline float fmaxf(float a, float b)
85 {
86  return (a > b) ? a : b;
87 }
88 
89 ccl_device_inline float fminf(float a, float b)
90 {
91  return (a < b) ? a : b;
92 }
93 
94 # endif /* _WIN32 */
95 #endif /* __HIP__, __KERNEL_ONEAPI__ */
96 
97 #if !defined(__KERNEL_GPU__) || defined(__KERNEL_ONEAPI__)
98 # ifndef __KERNEL_ONEAPI__
99 using std::isfinite;
100 using std::isnan;
101 using std::sqrt;
102 # else
103 using sycl::sqrt;
104 # define isfinite(x) sycl::isfinite((x))
105 # define isnan(x) sycl::isnan((x))
106 # endif
107 
109 {
110  return (x > 0) ? x : -x;
111 }
112 
113 ccl_device_inline int max(int a, int b)
114 {
115  return (a > b) ? a : b;
116 }
117 
118 ccl_device_inline int min(int a, int b)
119 {
120  return (a < b) ? a : b;
121 }
122 
124 {
125  return (a > b) ? a : b;
126 }
127 
129 {
130  return (a < b) ? a : b;
131 }
132 
134 {
135  return (a > b) ? a : b;
136 }
137 
139 {
140  return (a < b) ? a : b;
141 }
142 
143 /* NOTE: On 64bit Darwin the `size_t` is defined as `unsigned long int` and `uint64_t` is defined
144  * as `unsigned long long`. Both of the definitions are 64 bit unsigned integer, but the automatic
145  * substitution does not allow to automatically pick function defined for `uint64_t` as it is not
146  * exactly the same type definition.
147  * Work this around by adding a templated function enabled for `size_t` type which will be used
148  * when there is no explicit specialization of `min()`/`max()` above. */
149 
150 template<class T>
151 ccl_device_inline typename std::enable_if_t<std::is_same_v<T, size_t>, T> max(T a, T b)
152 {
153  return (a > b) ? a : b;
154 }
155 
156 template<class T>
157 ccl_device_inline typename std::enable_if_t<std::is_same_v<T, size_t>, T> min(T a, T b)
158 {
159  return (a < b) ? a : b;
160 }
161 
162 ccl_device_inline float max(float a, float b)
163 {
164  return (a > b) ? a : b;
165 }
166 
167 ccl_device_inline float min(float a, float b)
168 {
169  return (a < b) ? a : b;
170 }
171 
172 ccl_device_inline double max(double a, double b)
173 {
174  return (a > b) ? a : b;
175 }
176 
177 ccl_device_inline double min(double a, double b)
178 {
179  return (a < b) ? a : b;
180 }
181 
182 /* These 2 guys are templated for usage with registers data.
183  *
184  * NOTE: Since this is CPU-only functions it is ok to use references here.
185  * But for other devices we'll need to be careful about this.
186  */
187 
188 template<typename T> ccl_device_inline T min4(const T &a, const T &b, const T &c, const T &d)
189 {
190  return min(min(a, b), min(c, d));
191 }
192 
193 template<typename T> ccl_device_inline T max4(const T &a, const T &b, const T &c, const T &d)
194 {
195  return max(max(a, b), max(c, d));
196 }
197 #endif /* __KERNEL_GPU__ */
198 
199 ccl_device_inline float min4(float a, float b, float c, float d)
200 {
201  return min(min(a, b), min(c, d));
202 }
203 
204 ccl_device_inline float max4(float a, float b, float c, float d)
205 {
206  return max(max(a, b), max(c, d));
207 }
208 
209 #if !defined(__KERNEL_METAL__)
210 /* Int/Float conversion */
211 
213 {
214  union {
215  uint ui;
216  int i;
217  } u;
218  u.ui = i;
219  return u.i;
220 }
221 
223 {
224  union {
225  uint ui;
226  int i;
227  } u;
228  u.i = i;
229  return u.ui;
230 }
231 
233 {
234  union {
235  uint i;
236  float f;
237  } u;
238  u.f = f;
239  return u.i;
240 }
241 
242 # ifndef __HIP__
244 {
245  union {
246  int i;
247  float f;
248  } u;
249  u.f = f;
250  return u.i;
251 }
252 
254 {
255  union {
256  int i;
257  float f;
258  } u;
259  u.i = i;
260  return u.f;
261 }
262 
264 {
265  union {
266  uint i;
267  float f;
268  } u;
269  u.f = f;
270  return u.i;
271 }
272 
274 {
275  union {
276  uint i;
277  float f;
278  } u;
279  u.i = i;
280  return u.f;
281 }
282 # endif
283 
285 {
286 # ifdef __KERNEL_SSE__
287  return int4(_mm_castps_si128(f.m128));
288 # else
289  return make_int4(
291 # endif
292 }
293 
295 {
296 # ifdef __KERNEL_SSE__
297  return float4(_mm_castsi128_ps(i.m128));
298 # else
299  return make_float4(
301 # endif
302 }
303 #endif /* !defined(__KERNEL_METAL__) */
304 
305 #if defined(__KERNEL_METAL__)
307 {
308  return isnan(f);
309 }
310 
312 {
313  return isfinite(f);
314 }
315 #else
317 {
318  return ((uint64_t)ptr) & 0xFFFFFFFF;
319 }
320 
322 {
323  return (((uint64_t)ptr) >> 32) & 0xFFFFFFFF;
324 }
325 
326 template<typename T> ccl_device_inline T *pointer_unpack_from_uint(const uint a, const uint b)
327 {
328  return (T *)(((uint64_t)b << 32) | a);
329 }
330 
332 {
333  return (a << 16) | b;
334 }
335 
337 {
338  return i >> 16;
339 }
340 
342 {
343  return i & 0xFFFF;
344 }
345 
346 /* Versions of functions which are safe for fast math. */
348 {
349  unsigned int x = __float_as_uint(f);
350  return (x << 1) > 0xff000000u;
351 }
352 
354 {
355  /* By IEEE 754 rule, 2*Inf equals Inf */
356  unsigned int x = __float_as_uint(f);
357  return (f == f) && (x == 0 || x == (1u << 31) || (f != 2.0f * f)) && !((x << 1) > 0xff000000u);
358 }
359 #endif
360 
362 {
363  return isfinite_safe(v) ? v : 0.0f;
364 }
365 
366 #if !defined(__KERNEL_METAL__)
367 ccl_device_inline int clamp(int a, int mn, int mx)
368 {
369  return min(max(a, mn), mx);
370 }
371 
372 ccl_device_inline float clamp(float a, float mn, float mx)
373 {
374  return min(max(a, mn), mx);
375 }
376 
377 ccl_device_inline float mix(float a, float b, float t)
378 {
379  return a + t * (b - a);
380 }
381 
382 ccl_device_inline float smoothstep(float edge0, float edge1, float x)
383 {
384  float result;
385  if (x < edge0)
386  result = 0.0f;
387  else if (x >= edge1)
388  result = 1.0f;
389  else {
390  float t = (x - edge0) / (edge1 - edge0);
391  result = (3.0f - 2.0f * t) * (t * t);
392  }
393  return result;
394 }
395 
396 #endif /* !defined(__KERNEL_METAL__) */
397 
398 #if defined(__KERNEL_CUDA__)
399 ccl_device_inline float saturatef(float a)
400 {
401  return __saturatef(a);
402 }
403 #elif !defined(__KERNEL_METAL__)
405 {
406  return clamp(a, 0.0f, 1.0f);
407 }
408 #endif /* __KERNEL_CUDA__ */
409 
411 {
412  return (int)f;
413 }
414 
416 {
417  return float_to_int(floorf(f));
418 }
419 
421 {
422  float f = floorf(x);
423  *i = float_to_int(f);
424  return x - f;
425 }
426 
428 {
429  return float_to_int(ceilf(f));
430 }
431 
433 {
434  return x - floorf(x);
435 }
436 
437 /* Adapted from `godot-engine` math_funcs.h. */
438 ccl_device_inline float wrapf(float value, float max, float min)
439 {
440  float range = max - min;
441  return (range != 0.0f) ? value - (range * floorf((value - min) / range)) : min;
442 }
443 
444 ccl_device_inline float pingpongf(float a, float b)
445 {
446  return (b != 0.0f) ? fabsf(fractf((a - b) / (b * 2.0f)) * b * 2.0f - b) : 0.0f;
447 }
448 
449 ccl_device_inline float smoothminf(float a, float b, float k)
450 {
451  if (k != 0.0f) {
452  float h = fmaxf(k - fabsf(a - b), 0.0f) / k;
453  return fminf(a, b) - h * h * h * k * (1.0f / 6.0f);
454  }
455  else {
456  return fminf(a, b);
457  }
458 }
459 
460 ccl_device_inline float signf(float f)
461 {
462  return (f < 0.0f) ? -1.0f : 1.0f;
463 }
464 
465 ccl_device_inline float nonzerof(float f, float eps)
466 {
467  if (fabsf(f) < eps)
468  return signf(f) * eps;
469  else
470  return f;
471 }
472 
473 /* `signum` function testing for zero. Matches GLSL and OSL functions. */
475 {
476  if (f == 0.0f) {
477  return 0.0f;
478  }
479  else {
480  return signf(f);
481  }
482 }
483 
485 {
486  float ff = f * f;
487  return (3.0f * ff - 2.0f * ff * f);
488 }
489 
490 ccl_device_inline int mod(int x, int m)
491 {
492  return (x % m + m) % m;
493 }
494 
496 {
497  return make_float3(a.x, a.y, 0.0f);
498 }
499 
501 {
502  return make_float3(a.x, a.y, a.z);
503 }
504 
506 {
507  return make_float4(a.x, a.y, a.z, 1.0f);
508 }
509 
511 {
512  return make_float4(a.x, a.y, a.z, w);
513 }
514 
515 ccl_device_inline float inverse_lerp(float a, float b, float x)
516 {
517  return (x - a) / (b - a);
518 }
519 
520 /* Cubic interpolation between b and c, a and d are the previous and next point. */
521 ccl_device_inline float cubic_interp(float a, float b, float c, float d, float x)
522 {
523  return 0.5f *
524  (((d + 3.0f * (b - c) - a) * x + (2.0f * a - 5.0f * b + 4.0f * c - d)) * x +
525  (c - a)) *
526  x +
527  b;
528 }
529 
531 
532 #include "util/math_int2.h"
533 #include "util/math_int3.h"
534 #include "util/math_int4.h"
535 
536 #include "util/math_float2.h"
537 #include "util/math_float3.h"
538 #include "util/math_float4.h"
539 #include "util/math_float8.h"
540 
541 #include "util/rect.h"
542 
544 
545 #if !defined(__KERNEL_METAL__)
546 /* Interpolation */
547 
548 template<class A, class B> A lerp(const A &a, const A &b, const B &t)
549 {
550  return (A)(a * ((B)1 - t) + b * t);
551 }
552 
553 #endif /* __KERNEL_METAL__ */
554 
555 /* Triangle */
556 
558  ccl_private const float3 &v2,
559  ccl_private const float3 &v3)
560 {
561  return len(cross(v3 - v2, v1 - v2)) * 0.5f;
562 }
563 
564 /* Orthonormal vectors */
565 
569 {
570 #if 0
571  if (fabsf(N.y) >= 0.999f) {
572  *a = make_float3(1, 0, 0);
573  *b = make_float3(0, 0, 1);
574  return;
575  }
576  if (fabsf(N.z) >= 0.999f) {
577  *a = make_float3(1, 0, 0);
578  *b = make_float3(0, 1, 0);
579  return;
580  }
581 #endif
582 
583  if (N.x != N.y || N.x != N.z)
584  *a = make_float3(N.z - N.y, N.x - N.z, N.y - N.x); //(1,1,1)x N
585  else
586  *a = make_float3(N.z - N.y, N.x + N.z, -N.y - N.x); //(-1,1,1)x N
587 
588  *a = normalize(*a);
589  *b = cross(N, *a);
590 }
591 
592 /* Color division */
593 
595 {
596  float x, y, z;
597 
598  x = (a.x != 0.0f) ? 1.0f / a.x : 0.0f;
599  y = (a.y != 0.0f) ? 1.0f / a.y : 0.0f;
600  z = (a.z != 0.0f) ? 1.0f / a.z : 0.0f;
601 
602  return make_float3(x, y, z);
603 }
604 
606 {
607  float x, y, z;
608 
609  x = (b.x != 0.0f) ? a.x / b.x : 0.0f;
610  y = (b.y != 0.0f) ? a.y / b.y : 0.0f;
611  z = (b.z != 0.0f) ? a.z / b.z : 0.0f;
612 
613  return make_float3(x, y, z);
614 }
615 
617 {
618  float x, y, z;
619 
620  x = (b.x != 0.0f) ? a.x / b.x : 0.0f;
621  y = (b.y != 0.0f) ? a.y / b.y : 0.0f;
622  z = (b.z != 0.0f) ? a.z / b.z : 0.0f;
623 
624  /* try to get gray even if b is zero */
625  if (b.x == 0.0f) {
626  if (b.y == 0.0f) {
627  x = z;
628  y = z;
629  }
630  else if (b.z == 0.0f) {
631  x = y;
632  z = y;
633  }
634  else
635  x = 0.5f * (y + z);
636  }
637  else if (b.y == 0.0f) {
638  if (b.z == 0.0f) {
639  y = x;
640  z = x;
641  }
642  else
643  y = 0.5f * (x + z);
644  }
645  else if (b.z == 0.0f) {
646  z = 0.5f * (x + y);
647  }
648 
649  return make_float3(x, y, z);
650 }
651 
652 /* Rotation of point around axis and angle */
653 
655 {
656  float costheta = cosf(angle);
657  float sintheta = sinf(angle);
658  float3 r;
659 
660  r.x = ((costheta + (1 - costheta) * axis.x * axis.x) * p.x) +
661  (((1 - costheta) * axis.x * axis.y - axis.z * sintheta) * p.y) +
662  (((1 - costheta) * axis.x * axis.z + axis.y * sintheta) * p.z);
663 
664  r.y = (((1 - costheta) * axis.x * axis.y + axis.z * sintheta) * p.x) +
665  ((costheta + (1 - costheta) * axis.y * axis.y) * p.y) +
666  (((1 - costheta) * axis.y * axis.z - axis.x * sintheta) * p.z);
667 
668  r.z = (((1 - costheta) * axis.x * axis.z - axis.y * sintheta) * p.x) +
669  (((1 - costheta) * axis.y * axis.z + axis.x * sintheta) * p.y) +
670  ((costheta + (1 - costheta) * axis.z * axis.z) * p.z);
671 
672  return r;
673 }
674 
675 /* NaN-safe math ops */
676 
678 {
679  return sqrtf(max(f, 0.0f));
680 }
681 
683 {
684 #if defined(__KERNEL_METAL__)
685  return (f > 0.0f) ? rsqrt(f) : 0.0f;
686 #else
687  return (f > 0.0f) ? 1.0f / sqrtf(f) : 0.0f;
688 #endif
689 }
690 
691 ccl_device float safe_asinf(float a)
692 {
693  return asinf(clamp(a, -1.0f, 1.0f));
694 }
695 
696 ccl_device float safe_acosf(float a)
697 {
698  return acosf(clamp(a, -1.0f, 1.0f));
699 }
700 
701 ccl_device float compatible_powf(float x, float y)
702 {
703 #ifdef __KERNEL_GPU__
704  if (y == 0.0f) /* x^0 -> 1, including 0^0 */
705  return 1.0f;
706 
707  /* GPU pow doesn't accept negative x, do manual checks here */
708  if (x < 0.0f) {
709  if (fmodf(-y, 2.0f) == 0.0f)
710  return powf(-x, y);
711  else
712  return -powf(-x, y);
713  }
714  else if (x == 0.0f)
715  return 0.0f;
716 #endif
717  return powf(x, y);
718 }
719 
720 ccl_device float safe_powf(float a, float b)
721 {
722  if (UNLIKELY(a < 0.0f && b != float_to_int(b)))
723  return 0.0f;
724 
725  return compatible_powf(a, b);
726 }
727 
728 ccl_device float safe_divide(float a, float b)
729 {
730  return (b != 0.0f) ? a / b : 0.0f;
731 }
732 
733 ccl_device float safe_logf(float a, float b)
734 {
735  if (UNLIKELY(a <= 0.0f || b <= 0.0f))
736  return 0.0f;
737 
738  return safe_divide(logf(a), logf(b));
739 }
740 
741 ccl_device float safe_modulo(float a, float b)
742 {
743  return (b != 0.0f) ? fmodf(a, b) : 0.0f;
744 }
745 
746 ccl_device_inline float sqr(float a)
747 {
748  return a * a;
749 }
750 
752 {
753  return sqr(sqr(sqr(sqr(a)) * a));
754 }
755 
757 {
758  return sqr(a * sqr(sqr(sqr(a)) * a));
759 }
760 
761 #ifdef __KERNEL_METAL__
762 ccl_device_inline float lgammaf(float x)
763 {
764  /* Nemes, GergÅ‘ (2010), "New asymptotic expansion for the Gamma function", Archiv der Mathematik
765  */
766  const float _1_180 = 1.0f / 180.0f;
767  const float log2pi = 1.83787706641f;
768  const float logx = log(x);
769  return (log2pi - logx +
770  x * (logx * 2.0f + log(x * sinh(1.0f / x) + (_1_180 / pow(x, 6.0f))) - 2.0f)) *
771  0.5f;
772 }
773 #endif
774 
775 ccl_device_inline float beta(float x, float y)
776 {
777  return expf(lgammaf(x) + lgammaf(y) - lgammaf(x + y));
778 }
779 
781 {
782  return __int_as_float(__float_as_int(x) ^ y);
783 }
784 
786 {
787  return bits * (1.0f / (float)0xFFFFFFFF);
788 }
789 
790 #if !defined(__KERNEL_GPU__)
791 # if defined(__GNUC__)
792 # define popcount(x) __builtin_popcount(x)
793 # else
795 {
796  /* TODO(Stefan): pop-count intrinsic for Windows with fallback for older CPUs. */
797  uint i = x & 0xaaaaaaaa;
798  i = i - ((i >> 1) & 0x55555555);
799  i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
800  i = (((i + (i >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
801  return i & 1;
802 }
803 # endif
804 #elif defined(__KERNEL_ONEAPI__)
805 # define popcount(x) sycl::popcount(x)
806 #elif defined(__KERNEL_HIP__)
807 /* Use popcll to support 64-bit wave for pre-RDNA AMD GPUs */
808 # define popcount(x) __popcll(x)
809 #elif !defined(__KERNEL_METAL__)
810 # define popcount(x) __popc(x)
811 #endif
812 
814 {
815 #if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
816  return __clz(x);
817 #elif defined(__KERNEL_METAL__)
818  return clz(x);
819 #elif defined(__KERNEL_ONEAPI__)
820  return sycl::clz(x);
821 #else
822  assert(x != 0);
823 # ifdef _MSC_VER
824  unsigned long leading_zero = 0;
825  _BitScanReverse(&leading_zero, x);
826  return (31 - leading_zero);
827 # else
828  return __builtin_clz(x);
829 # endif
830 #endif
831 }
832 
834 {
835 #if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
836  return (__ffs(x) - 1);
837 #elif defined(__KERNEL_METAL__)
838  return ctz(x);
839 #elif defined(__KERNEL_ONEAPI__)
840  return sycl::ctz(x);
841 #else
842  assert(x != 0);
843 # ifdef _MSC_VER
844  unsigned long ctz = 0;
845  _BitScanForward(&ctz, x);
846  return ctz;
847 # else
848  return __builtin_ctz(x);
849 # endif
850 #endif
851 }
852 
854 {
855 #if defined(__KERNEL_CUDA__) || defined(__KERNEL_OPTIX__) || defined(__KERNEL_HIP__)
856  return __ffs(x);
857 #elif defined(__KERNEL_METAL__)
858  return (x != 0) ? ctz(x) + 1 : 0;
859 #else
860 # ifdef _MSC_VER
861  return (x != 0) ? (32 - count_leading_zeros(x & (-x))) : 0;
862 # else
863  return __builtin_ffs(x);
864 # endif
865 #endif
866 }
867 
868 /* projections */
870 {
871  float len, u, v;
872  len = sqrtf(co.x * co.x + co.y * co.y);
873  if (len > 0.0f) {
874  u = (1.0f - (atan2f(co.x / len, co.y / len) / M_PI_F)) * 0.5f;
875  v = (co.z + 1.0f) * 0.5f;
876  }
877  else {
878  u = v = 0.0f;
879  }
880  return make_float2(u, v);
881 }
882 
884 {
885  float l = len(co);
886  float u, v;
887  if (l > 0.0f) {
888  if (UNLIKELY(co.x == 0.0f && co.y == 0.0f)) {
889  u = 0.0f; /* Otherwise domain error. */
890  }
891  else {
892  u = (1.0f - atan2f(co.x, co.y) / M_PI_F) / 2.0f;
893  }
894  v = 1.0f - safe_acosf(co.z / l) / M_PI_F;
895  }
896  else {
897  u = v = 0.0f;
898  }
899  return make_float2(u, v);
900 }
901 
902 /* Compares two floats.
903  * Returns true if their absolute difference is smaller than abs_diff (for numbers near zero)
904  * or their relative difference is less than ulp_diff ULPs.
905  * Based on
906  * https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
907  */
908 
909 ccl_device_inline bool compare_floats(float a, float b, float abs_diff, int ulp_diff)
910 {
911  if (fabsf(a - b) < abs_diff) {
912  return true;
913  }
914 
915  if ((a < 0.0f) != (b < 0.0f)) {
916  return false;
917  }
918 
919  return (abs(__float_as_int(a) - __float_as_int(b)) < ulp_diff);
920 }
921 
922 /* Calculate the angle between the two vectors a and b.
923  * The usual approach `acos(dot(a, b))` has severe precision issues for small angles,
924  * which are avoided by this method.
925  * Based on "Mangled Angles" from https://people.eecs.berkeley.edu/~wkahan/Mindless.pdf
926  */
928 {
929  return 2.0f * atan2f(len(a - b), len(a + b));
930 }
931 
932 /* Return value which is greater than the given one and is a power of two. */
934 {
935  return x == 0 ? 1 : 1 << (32 - count_leading_zeros(x));
936 }
937 
938 /* Return value which is lower than the given one and is a power of two. */
940 {
941  return x < 2 ? x : 1 << (31 - count_leading_zeros(x - 1));
942 }
943 
944 #ifndef __has_builtin
945 # define __has_builtin(v) 0
946 #endif
947 
948 /* Reverses the bits of a 32 bit integer. */
950 {
951  /* Use a native instruction if it exists. */
952 #if defined(__KERNEL_CUDA__)
953  return __brev(x);
954 #elif defined(__KERNEL_METAL__)
955  return reverse_bits(x);
956 #elif defined(__aarch64__) || defined(_M_ARM64)
957  /* Assume the rbit is always available on 64bit ARM architecture. */
958  __asm__("rbit %w0, %w1" : "=r"(x) : "r"(x));
959  return x;
960 #elif defined(__arm__) && ((__ARM_ARCH > 7) || __ARM_ARCH == 6 && __ARM_ARCH_ISA_THUMB >= 2)
961  /* This ARM instruction is available in ARMv6T2 and above.
962  * This 32-bit Thumb instruction is available in ARMv6T2 and above. */
963  __asm__("rbit %0, %1" : "=r"(x) : "r"(x));
964  return x;
965 #elif __has_builtin(__builtin_bitreverse32)
966  return __builtin_bitreverse32(x);
967 #else
968  /* Flip pairwise. */
969  x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1);
970  /* Flip pairs. */
971  x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2);
972  /* Flip nibbles. */
973  x = ((x & 0x0F0F0F0F) << 4) | ((x & 0xF0F0F0F0) >> 4);
974  /* Flip bytes. CPUs have an instruction for that, pretty fast one. */
975 # ifdef _MSC_VER
976  return _byteswap_ulong(x);
977 # elif defined(__INTEL_COMPILER)
978  return (uint32_t)_bswap((int)x);
979 # else
980  /* Assuming gcc or clang. */
981  return __builtin_bswap32(x);
982 # endif
983 #endif
984 }
985 
987 
988 #endif /* __UTIL_MATH_H__ */
typedef float(TangentPoint)[2]
sqrt(x)+1/max(0
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNLIKELY(x)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
float float4[4]
int int4[4]
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define A
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
int x
Definition: btConvexHull.h:149
int w
Definition: btConvexHull.h:149
int y
Definition: btConvexHull.h:149
int z
Definition: btConvexHull.h:149
#define ccl_device_forceinline
Definition: cuda/compat.h:35
#define logf(x)
Definition: cuda/compat.h:105
#define sinf(x)
Definition: cuda/compat.h:102
#define cosf(x)
Definition: cuda/compat.h:101
#define ccl_device
Definition: cuda/compat.h:32
#define expf(x)
Definition: cuda/compat.h:106
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_inline
Definition: cuda/compat.h:34
#define powf(x, y)
Definition: cuda/compat.h:103
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
int len
Definition: draw_manager.c:108
ccl_device_inline float3 pow(float3 v, float e)
Definition: math_float3.h:533
ccl_device_inline float3 log(float3 v)
Definition: math_float3.h:397
#define N
#define T
#define B
#define make_int4(x, y, z, w)
Definition: metal/compat.h:208
#define atan2f(x, y)
Definition: metal/compat.h:227
#define asinf(x)
Definition: metal/compat.h:221
#define fmaxf(x, y)
Definition: metal/compat.h:228
#define make_float2(x, y)
Definition: metal/compat.h:203
#define ceilf(x)
Definition: metal/compat.h:225
#define fminf(x, y)
Definition: metal/compat.h:229
#define fmodf(x, y)
Definition: metal/compat.h:230
#define floorf(x)
Definition: metal/compat.h:224
#define acosf(x)
Definition: metal/compat.h:222
#define make_float4(x, y, z, w)
Definition: metal/compat.h:205
#define fabsf(x)
Definition: metal/compat.h:219
#define sqrtf(x)
Definition: metal/compat.h:243
#define make_float3(x, y, z)
Definition: metal/compat.h:204
bool isfinite(uchar)
Definition: scene/image.cpp:31
static unsigned c
Definition: RandGen.cpp:83
static unsigned a[3]
Definition: RandGen.cpp:78
INLINE Rall1d< T, V, S > sinh(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:335
vec_base< T, 3 > cross(const vec_base< T, 3 > &a, const vec_base< T, 3 > &b)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
bool isnan(double i)
Definition: numeric.h:451
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
#define lgammaf(x)
const btScalar eps
Definition: poly34.cpp:11
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90
float z
float y
float x
ccl_device_inline float __uint_as_float(uint i)
Definition: util/math.h:273
ccl_device float safe_divide(float a, float b)
Definition: util/math.h:728
ccl_device_inline T * pointer_unpack_from_uint(const uint a, const uint b)
Definition: util/math.h:326
ccl_device_inline float inverse_lerp(float a, float b, float x)
Definition: util/math.h:515
ccl_device_inline uint __float_as_uint(float f)
Definition: util/math.h:263
ccl_device_inline float ensure_finite(float v)
Definition: util/math.h:361
ccl_device_inline int4 __float4_as_int4(float4 f)
Definition: util/math.h:284
ccl_device_inline int abs(int x)
Definition: util/math.h:108
ccl_device_inline float safe_sqrtf(float f)
Definition: util/math.h:677
ccl_device_inline uint uint16_unpack_from_uint_1(const uint i)
Definition: util/math.h:341
ccl_device_inline float pow22(float a)
Definition: util/math.h:756
ccl_device_inline int __float_as_int(float f)
Definition: util/math.h:243
ccl_device_inline int float_to_int(float f)
Definition: util/math.h:410
ccl_device_inline int ceil_to_int(float f)
Definition: util/math.h:427
ccl_device_inline float mix(float a, float b, float t)
Definition: util/math.h:377
ccl_device_inline float pow20(float a)
Definition: util/math.h:751
ccl_device_inline float compatible_signf(float f)
Definition: util/math.h:474
ccl_device_inline T min4(const T &a, const T &b, const T &c, const T &d)
Definition: util/math.h:188
ccl_device_inline float smoothstep(float edge0, float edge1, float x)
Definition: util/math.h:382
ccl_device_inline uint popcount(uint x)
Definition: util/math.h:794
ccl_device_inline uint count_leading_zeros(uint x)
Definition: util/math.h:813
ccl_device_inline float3 safe_divide_even_color(float3 a, float3 b)
Definition: util/math.h:616
CCL_NAMESPACE_END CCL_NAMESPACE_BEGIN A lerp(const A &a, const A &b, const B &t)
Definition: util/math.h:548
ccl_device_inline int mod(int x, int m)
Definition: util/math.h:490
ccl_device_inline float triangle_area(ccl_private const float3 &v1, ccl_private const float3 &v2, ccl_private const float3 &v3)
Definition: util/math.h:557
ccl_device float safe_modulo(float a, float b)
Definition: util/math.h:741
ccl_device_inline float sqr(float a)
Definition: util/math.h:746
ccl_device_inline float pingpongf(float a, float b)
Definition: util/math.h:444
ccl_device_inline uint pointer_pack_to_uint_1(T *ptr)
Definition: util/math.h:321
ccl_device_inline uint32_t reverse_integer_bits(uint32_t x)
Definition: util/math.h:949
ccl_device_inline uint count_trailing_zeros(uint x)
Definition: util/math.h:833
ccl_device_inline float saturatef(float a)
Definition: util/math.h:404
ccl_device_inline float inversesqrtf(float f)
Definition: util/math.h:682
ccl_device float safe_acosf(float a)
Definition: util/math.h:696
ccl_device float compatible_powf(float x, float y)
Definition: util/math.h:701
ccl_device_inline float3 safe_divide_color(float3 a, float3 b)
Definition: util/math.h:605
ccl_device_inline float smoothminf(float a, float b, float k)
Definition: util/math.h:449
ccl_device_inline float2 map_to_sphere(const float3 co)
Definition: util/math.h:883
ccl_device_inline uint uint16_pack_to_uint(const uint a, const uint b)
Definition: util/math.h:331
ccl_device_inline bool isfinite_safe(float f)
Definition: util/math.h:353
ccl_device_inline int min(int a, int b)
Definition: util/math.h:118
ccl_device_inline uint pointer_pack_to_uint_0(T *ptr)
Definition: util/math.h:316
ccl_device_inline float4 float3_to_float4(const float3 a)
Definition: util/math.h:505
ccl_device_inline float precise_angle(float3 a, float3 b)
Definition: util/math.h:927
ccl_device_inline float2 map_to_tube(const float3 co)
Definition: util/math.h:869
ccl_device_inline uint next_power_of_two(uint x)
Definition: util/math.h:933
ccl_device_inline float floorfrac(float x, ccl_private int *i)
Definition: util/math.h:420
ccl_device_inline T max4(const T &a, const T &b, const T &c, const T &d)
Definition: util/math.h:193
ccl_device_inline uint as_uint(int i)
Definition: util/math.h:222
ccl_device_inline float nonzerof(float f, float eps)
Definition: util/math.h:465
ccl_device float safe_powf(float a, float b)
Definition: util/math.h:720
ccl_device_inline uint prev_power_of_two(uint x)
Definition: util/math.h:939
ccl_device_inline float3 safe_invert_color(float3 a)
Definition: util/math.h:594
#define M_PI_F
Definition: util/math.h:34
ccl_device float safe_logf(float a, float b)
Definition: util/math.h:733
ccl_device_inline float fractf(float x)
Definition: util/math.h:432
ccl_device_inline bool compare_floats(float a, float b, float abs_diff, int ulp_diff)
Definition: util/math.h:909
ccl_device_inline int floor_to_int(float f)
Definition: util/math.h:415
ccl_device_inline bool isnan_safe(float f)
Definition: util/math.h:347
ccl_device_inline float beta(float x, float y)
Definition: util/math.h:775
ccl_device_inline uint uint16_unpack_from_uint_0(const uint i)
Definition: util/math.h:336
ccl_device_inline float3 float2_to_float3(const float2 a)
Definition: util/math.h:495
ccl_device_inline float signf(float f)
Definition: util/math.h:460
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)
Definition: util/math.h:566
ccl_device_inline float xor_signmask(float x, int y)
Definition: util/math.h:780
ccl_device_inline float cubic_interp(float a, float b, float c, float d, float x)
Definition: util/math.h:521
ccl_device_inline uint find_first_set(uint x)
Definition: util/math.h:853
ccl_device_inline float3 float4_to_float3(const float4 a)
Definition: util/math.h:500
ccl_device_inline int as_int(uint i)
Definition: util/math.h:212
ccl_device float bits_to_01(uint bits)
Definition: util/math.h:785
ccl_device_inline int max(int a, int b)
Definition: util/math.h:113
ccl_device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle)
Definition: util/math.h:654
ccl_device_inline float4 __int4_as_float4(int4 i)
Definition: util/math.h:294
ccl_device_inline float wrapf(float value, float max, float min)
Definition: util/math.h:438
ccl_device float safe_asinf(float a)
Definition: util/math.h:691
ccl_device_inline float smoothstepf(float f)
Definition: util/math.h:484
ccl_device_inline int clamp(int a, int mn, int mx)
Definition: util/math.h:367
ccl_device_inline float __int_as_float(int i)
Definition: util/math.h:253
PointerRNA * ptr
Definition: wm_files.c:3480