Files
test/source/blender/blenlib/intern/math_base_safe_inline.c
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00

73 lines
1.3 KiB
C

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* 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_floored_modf(float a, float b)
{
return (b != 0.0f) ? a - floorf(a / b) * 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__ */