4#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_FLOAT_SIGN_HPP_
5#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_FLOAT_SIGN_HPP_
10#include "arene/base/compiler_support/diagnostics.hpp"
11#include "arene/base/constraints/constraints.hpp"
12#include "arene/base/stdlib_choice/enable_if.hpp"
13#include "arene/base/stdlib_choice/integral_constant.hpp"
26constexpr auto copysign(
float const magnitude,
float const sign)
noexcept ->
float {
27 return __builtin_copysignf(magnitude, sign);
34constexpr auto copysign(
double const magnitude,
double const sign)
noexcept ->
double {
35 return __builtin_copysign(magnitude, sign);
38namespace float_sign_detail {
41template <
typename T,
typename = constraints<>>
42class builtin_signbit_is_constexpr :
public std::false_type {};
47class builtin_signbit_is_constexpr<T, constraints<std::enable_if_t<(
static_cast<
void>(__builtin_signbit(T{})),
true)>>>
48 :
public std::true_type {};
53constexpr bool builtin_signbit_is_constexpr_v = builtin_signbit_is_constexpr<T>::value;
59template <
typename T, constraints<std::enable_if_t<builtin_signbit_is_constexpr_v<T>>> =
nullptr>
60constexpr auto signbit(T
const num)
noexcept ->
bool {
61 return __builtin_signbit(num);
65ARENE_IGNORE_ALL(
"-Wfloat-equal",
"Equality operand is guaranteed to be either exactly 1.0 or exactly -1.0");
71template <
typename T, constraints<std::enable_if_t<!builtin_signbit_is_constexpr_v<T>>> =
nullptr>
72constexpr auto signbit(T
const num)
noexcept ->
bool {
75 auto sign_carrier = ::arene::base::copysign(
static_cast<T>(1.0), num);
76 return sign_carrier ==
static_cast<T>(-1.0);
86constexpr auto signbit(
float const num)
noexcept ->
bool {
return float_sign_detail::signbit(num); }
91constexpr auto signbit(
double const num)
noexcept ->
bool {
return float_sign_detail::signbit(num); }
Definition array_exceptions_disabled.cpp:11
constexpr auto signbit(double const num) noexcept -> bool
Check the sign bit of a floating point number.
Definition float_sign.hpp:91
constexpr auto copysign(double const magnitude, double const sign) noexcept -> double
Return a number with the magnitude of the first operand and the sign of the second.
Definition float_sign.hpp:34
constexpr auto copysign(float const magnitude, float const sign) noexcept -> float
Return a number with the magnitude of the first operand and the sign of the second.
Definition float_sign.hpp:26
constexpr auto signbit(float const num) noexcept -> bool
Check the sign bit of a floating point number.
Definition float_sign.hpp:86
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10