Use a shorter/simpler license convention, stops the header taking so much space. Follow the SPDX license specification: https://spdx.org/licenses - C/C++/objc/objc++ - Python - Shell Scripts - CMake, GNUmakefile While most of the source tree has been included - `./extern/` was left out. - `./intern/cycles` & `./intern/atomic` are also excluded because they use different header conventions. doc/license/SPDX-license-identifiers.txt has been added to list SPDX all used identifiers. See P2788 for the script that automated these edits. Reviewed By: brecht, mont29, sergey Ref D14069
66 lines
1.1 KiB
C
66 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#ifndef __MATH_BASE_SAFE_INLINE_C__
|
|
#define __MATH_BASE_SAFE_INLINE_C__
|
|
|
|
#include "BLI_math_base_safe.h"
|
|
#include "BLI_utildefines.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
MINLINE float safe_divide(float a, float b)
|
|
{
|
|
return (b != 0.0f) ? a / b : 0.0f;
|
|
}
|
|
|
|
MINLINE float safe_modf(float a, float b)
|
|
{
|
|
return (b != 0.0f) ? fmodf(a, b) : 0.0f;
|
|
}
|
|
|
|
MINLINE float safe_logf(float a, float base)
|
|
{
|
|
if (UNLIKELY(a <= 0.0f || base <= 0.0f)) {
|
|
return 0.0f;
|
|
}
|
|
return safe_divide(logf(a), logf(base));
|
|
}
|
|
|
|
MINLINE float safe_sqrtf(float a)
|
|
{
|
|
return sqrtf(MAX2(a, 0.0f));
|
|
}
|
|
|
|
MINLINE float safe_inverse_sqrtf(float a)
|
|
{
|
|
return (a > 0.0f) ? 1.0f / sqrtf(a) : 0.0f;
|
|
}
|
|
|
|
MINLINE float safe_asinf(float a)
|
|
{
|
|
CLAMP(a, -1.0f, 1.0f);
|
|
return asinf(a);
|
|
}
|
|
|
|
MINLINE float safe_acosf(float a)
|
|
{
|
|
CLAMP(a, -1.0f, 1.0f);
|
|
return acosf(a);
|
|
}
|
|
|
|
MINLINE float safe_powf(float base, float exponent)
|
|
{
|
|
if (UNLIKELY(base < 0.0f && exponent != (int)exponent)) {
|
|
return 0.0f;
|
|
}
|
|
return powf(base, exponent);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __MATH_BASE_SAFE_INLINE_C__ */
|