20 #include <type_traits> 59 TEST_F(ConstexprMathTest, constexpr_abs_unsigned) {
66 TEST_F(ConstexprMathTest, constexpr_abs_signed_positive) {
73 TEST_F(ConstexprMathTest, constexpr_abs_signed_negative) {
80 TEST_F(ConstexprMathTest, constexpr_abs_float_positive) {
81 constexpr
auto v = 17.5f;
87 TEST_F(ConstexprMathTest, constexpr_abs_float_negative) {
88 constexpr
auto v = -17.5f;
94 TEST_F(ConstexprMathTest, constexpr_abs_double_positive) {
95 constexpr
auto v = 17.5;
101 TEST_F(ConstexprMathTest, constexpr_abs_double_negative) {
102 constexpr
auto v = -17.5;
108 TEST_F(ConstexprMathTest, constexpr_log2_1) {
109 constexpr
auto v = 1ull;
115 TEST_F(ConstexprMathTest, constexpr_log2_2) {
116 constexpr
auto v = 2ull;
122 TEST_F(ConstexprMathTest, constexpr_log2_64) {
123 constexpr
auto v = 64ull;
129 TEST_F(ConstexprMathTest, constexpr_log2_ceil_1) {
130 constexpr
auto v = 1ull;
136 TEST_F(ConstexprMathTest, constexpr_log2_ceil_2) {
137 constexpr
auto v = 2ull;
143 TEST_F(ConstexprMathTest, constexpr_log2_ceil_3) {
144 constexpr
auto v = 3ull;
150 TEST_F(ConstexprMathTest, constexpr_log2_ceil_63) {
151 constexpr
auto v = 63ull;
157 TEST_F(ConstexprMathTest, constexpr_log2_ceil_64) {
158 constexpr
auto v = 64ull;
166 constexpr
auto roundable = 20ull;
167 constexpr
auto round = 6ull;
172 constexpr
auto roundable = -20ll;
173 constexpr
auto round = 6ll;
178 constexpr
auto roundable = -20ll;
179 constexpr
auto round = 0ll;
200 TEST_F(ConstexprMathTest, constexpr_find_last_set_examples) {
215 TEST_F(ConstexprMathTest, constexpr_find_last_set_all_64_adjacents) {
217 constexpr
auto const bits = std::numeric_limits<type>::digits;
219 for (
size_t i = 0;
i < bits; ++
i) {
226 TEST_F(ConstexprMathTest, constexpr_find_last_set_all_8_reference) {
228 for (
size_t i = 0;
i < 256u; ++
i) {
234 TEST_F(ConstexprMathTest, constexpr_find_first_set_examples) {
249 TEST_F(ConstexprMathTest, constexpr_find_first_set_all_64_adjacent) {
251 constexpr
auto const bits = std::numeric_limits<type>::digits;
253 for (
size_t i = 0;
i < bits; ++
i) {
259 TEST_F(ConstexprMathTest, constexpr_find_first_set_all_8_reference) {
261 for (
size_t i = 0;
i < 256u; ++
i) {
374 template <
class F,
class...
Args>
376 [](...) {}((
f(std::forward<Args>(args)), 0)...);
380 template <
typename Src,
typename Dst>
383 constexpr
auto kQuietNaN = std::numeric_limits<Src>::quiet_NaN();
384 constexpr
auto kSignalingNaN = std::numeric_limits<Src>::signaling_NaN();
385 constexpr
auto kPositiveInf = std::numeric_limits<Src>::infinity();
386 constexpr
auto kNegativeInf = -kPositiveInf;
398 EXPECT_EQ(0, folly::constexpr_clamp_cast<Dst>(kQuietNaN));
399 EXPECT_EQ(0, folly::constexpr_clamp_cast<Dst>(kSignalingNaN));
402 EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kPositiveInf));
403 EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(kNegativeInf));
406 EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(Src(kDstMax) * 1.001));
407 EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(Src(kDstMin) * 1.001));
410 EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(0)));
411 EXPECT_EQ(Dst(123), folly::constexpr_clamp_cast<Dst>(Src(123)));
415 template <
typename Src,
typename Dst>
425 EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(0)));
426 EXPECT_EQ(Dst(123), folly::constexpr_clamp_cast<Dst>(Src(123)));
430 EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(-123)));
433 if (
sizeof(Src) >
sizeof(Dst)) {
435 EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kSrcMax));
439 EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(kSrcMin));
444 sizeof(Src) ==
sizeof(Dst)) {
446 EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kSrcMax));
constexpr std::size_t constexpr_find_first_set(T t)
constexpr auto kUInt64Max
#define ASSERT_GE(val1, val2)
constexpr std::size_t constexpr_find_last_set(T const t)
void for_each_argument(F &&f, Args &&...args)
constexpr T constexpr_add_overflow_clamped(T a, T b)
constexpr std::enable_if< std::is_integral< Src >::value, Dst >::type constexpr_clamp_cast(Src src)
#define ASSERT_EQ(val1, val2)
BitIterator< BaseIter > findFirstSet(BitIterator< BaseIter >, BitIterator< BaseIter >)
TEST_F(TestInfoTest, Names)
constexpr To round(std::chrono::duration< Rep, Period > const &d)
#define EXPECT_EQ(val1, val2)
constexpr T constexpr_min(T a)
static std::enable_if< std::is_floating_point< Src >::value, void >::type run_constexpr_clamp_cast_test(Src, Dst)
#define ASSERT_LE(val1, val2)
constexpr T constexpr_log2(T t)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
constexpr T constexpr_max(T a)
constexpr auto constexpr_abs(T t) -> decltype(detail::constexpr_abs_helper< T >::go(t))
constexpr T constexpr_pow(T base, std::size_t exp)
constexpr T constexpr_sub_overflow_clamped(T a, T b)
constexpr unsigned int findLastSet(T const v)
static const char *const value
#define EXPECT_TRUE(condition)
constexpr T constexpr_log2_ceil(T t)
constexpr T const & constexpr_clamp(T const &v, T const &lo, T const &hi, Less less)
constexpr T constexpr_ceil(T t, T round)
#define EXPECT_FALSE(condition)