Blender  V2.93
math_base_safe_inline.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #ifndef __MATH_BASE_SAFE_INLINE_C__
18 #define __MATH_BASE_SAFE_INLINE_C__
19 
20 #include "BLI_math_base_safe.h"
21 #include "BLI_utildefines.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 MINLINE float safe_divide(float a, float b)
28 {
29  return (b != 0.0f) ? a / b : 0.0f;
30 }
31 
32 MINLINE float safe_modf(float a, float b)
33 {
34  return (b != 0.0f) ? fmodf(a, b) : 0.0f;
35 }
36 
37 MINLINE float safe_logf(float a, float base)
38 {
39  if (UNLIKELY(a <= 0.0f || base <= 0.0f)) {
40  return 0.0f;
41  }
42  return safe_divide(logf(a), logf(base));
43 }
44 
45 MINLINE float safe_sqrtf(float a)
46 {
47  return sqrtf(MAX2(a, 0.0f));
48 }
49 
51 {
52  return (a > 0.0f) ? 1.0f / sqrtf(a) : 0.0f;
53 }
54 
55 MINLINE float safe_asinf(float a)
56 {
57  CLAMP(a, -1.0f, 1.0f);
58  return asinf(a);
59 }
60 
61 MINLINE float safe_acosf(float a)
62 {
63  CLAMP(a, -1.0f, 1.0f);
64  return acosf(a);
65 }
66 
67 MINLINE float safe_powf(float base, float exponent)
68 {
69  if (UNLIKELY(base < 0.0f && exponent != (int)exponent)) {
70  return 0.0f;
71  }
72  return powf(base, exponent);
73 }
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* __MATH_BASE_SAFE_INLINE_C__ */
#define MINLINE
#define MAX2(a, b)
#define UNLIKELY(x)
Group RGB to Bright Vector Camera CLAMP
#define logf(x)
#define powf(x, y)
#define asinf(x)
#define fmodf(x, y)
#define acosf(x)
#define sqrtf(x)
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)
static unsigned a[3]
Definition: RandGen.cpp:92