Blender  V3.3
math_base_safe_inline.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #ifndef __MATH_BASE_SAFE_INLINE_C__
4 #define __MATH_BASE_SAFE_INLINE_C__
5 
6 #include "BLI_math_base_safe.h"
7 #include "BLI_utildefines.h"
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 MINLINE float safe_divide(float a, float b)
14 {
15  return (b != 0.0f) ? a / b : 0.0f;
16 }
17 
18 MINLINE float safe_modf(float a, float b)
19 {
20  return (b != 0.0f) ? fmodf(a, b) : 0.0f;
21 }
22 
23 MINLINE float safe_logf(float a, float base)
24 {
25  if (UNLIKELY(a <= 0.0f || base <= 0.0f)) {
26  return 0.0f;
27  }
28  return safe_divide(logf(a), logf(base));
29 }
30 
31 MINLINE float safe_sqrtf(float a)
32 {
33  return sqrtf(MAX2(a, 0.0f));
34 }
35 
37 {
38  return (a > 0.0f) ? 1.0f / sqrtf(a) : 0.0f;
39 }
40 
41 MINLINE float safe_asinf(float a)
42 {
43  CLAMP(a, -1.0f, 1.0f);
44  return asinf(a);
45 }
46 
47 MINLINE float safe_acosf(float a)
48 {
49  CLAMP(a, -1.0f, 1.0f);
50  return acosf(a);
51 }
52 
53 MINLINE float safe_powf(float base, float exponent)
54 {
55  if (UNLIKELY(base < 0.0f && exponent != (int)exponent)) {
56  return 0.0f;
57  }
58  return powf(base, exponent);
59 }
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif /* __MATH_BASE_SAFE_INLINE_C__ */
#define MINLINE
#define MAX2(a, b)
#define UNLIKELY(x)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
#define logf(x)
Definition: cuda/compat.h:105
#define powf(x, y)
Definition: cuda/compat.h:103
MINLINE float safe_sqrtf(float a)
MINLINE float safe_logf(float a, float base)
MINLINE float safe_acosf(float a)
MINLINE float safe_modf(float a, float b)
MINLINE float safe_powf(float base, float exponent)
MINLINE float safe_divide(float a, float b)
MINLINE float safe_asinf(float a)
MINLINE float safe_inverse_sqrtf(float a)
#define asinf(x)
Definition: metal/compat.h:221
#define fmodf(x, y)
Definition: metal/compat.h:230
#define acosf(x)
Definition: metal/compat.h:222
#define sqrtf(x)
Definition: metal/compat.h:243
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)