Added bx::signbit, and bx::copysign.

This commit is contained in:
Бранимир Караџић
2023-06-01 07:08:41 -07:00
parent ab308e57be
commit cab04a9e58
3 changed files with 61 additions and 4 deletions

View File

@@ -138,6 +138,24 @@ namespace bx
return float( (0.0f < _a) - (0.0f > _a) );
}
inline BX_CONSTEXPR_FUNC bool signbit(float _a)
{
#if BX_COMPILER_MSVC
return _signbit(_a);
#else
return __builtin_signbit(_a);
#endif // BX_COMPILER_MSVC
}
inline BX_CONSTEXPR_FUNC float copysign(float _value, float _sign)
{
#if BX_COMPILER_MSVC
return _copysign(_value, _sign);
#else
return __builtin_copysign(_value, _sign);
#endif // BX_COMPILER_MSVC
}
inline BX_CONSTEXPR_FUNC float abs(float _a)
{
return _a < 0.0f ? -_a : _a;

View File

@@ -174,10 +174,27 @@ namespace bx
///
/// @param[in] _a Value.
///
/// @returns -1 if `_a` less than zero, 0 if `_a` is equal to 0, or +1 if `_a` is greater than zero.
/// @returns -1 if `_a` is less than zero, 0 if `_a` is equal to 0, or +1 if `_a` is greater than zero.
///
BX_CONSTEXPR_FUNC float sign(float _a);
/// Returns `true` if the velue `_a` is negative.
///
/// @param[in] _a Value.
///
/// @returns `true` if `_a` is less than zero, otherwise returns `false`.
///
BX_CONSTEXPR_FUNC bool signbit(float _a);
/// Returns value with the magnitude `_value`, and the sign of `_sign`.
///
/// @param[in] _value Value.
/// @param[in] _sign Sign.
///
/// @returns Value with the magnitude `_value`, and the sign of `_sign`.
///
BX_CONSTEXPR_FUNC float copysign(float _value, float _sign);
/// Returns the absolute of _a.
///
BX_CONSTEXPR_FUNC float abs(float _a);