From c79bc77241cd6c8d424a3a38bec84172c4d3d5f8 Mon Sep 17 00:00:00 2001 From: guza Date: Thu, 21 Mar 2024 21:05:06 +0800 Subject: [PATCH] format code --- examples/size.cc | 23 +++++++++++------------ src/include/bits.hh | 2 +- src/include/integer.hh | 8 ++++---- src/include/internal/bits.hh | 10 +++++----- src/include/internal/config.h | 1 - src/include/uinteger.hh | 18 +++++++++--------- tests/uinteger/u128_overflow.test.cc | 2 +- tests/uinteger/uinteger.test.cc | 2 +- 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/examples/size.cc b/examples/size.cc index 5c7bd68..29eadfa 100644 --- a/examples/size.cc +++ b/examples/size.cc @@ -1,18 +1,17 @@ #include "numbers.h" -int main(int argc, char const *argv[]) -{ +int main(int argc, char const *argv[]) { std::cout << "==== size example ==== \n"; - std::cout << "sizeof(numbers::i8) = "<< sizeof(numbers::i8) << '\n'; - std::cout << "sizeof(numbers::i16) = "<< sizeof(numbers::i16) << '\n'; - std::cout << "sizeof(numbers::i32) = "<< sizeof(numbers::i32) << '\n'; - std::cout << "sizeof(numbers::i64) = "<< sizeof(numbers::i64) << '\n'; - std::cout << "sizeof(numbers::i128) = "<< sizeof(numbers::i128) << '\n'; + std::cout << "sizeof(numbers::i8) = " << sizeof(numbers::i8) << '\n'; + std::cout << "sizeof(numbers::i16) = " << sizeof(numbers::i16) << '\n'; + std::cout << "sizeof(numbers::i32) = " << sizeof(numbers::i32) << '\n'; + std::cout << "sizeof(numbers::i64) = " << sizeof(numbers::i64) << '\n'; + std::cout << "sizeof(numbers::i128) = " << sizeof(numbers::i128) << '\n'; - std::cout << "sizeof(numbers::u8) = "<< sizeof(numbers::u8) << '\n'; - std::cout << "sizeof(numbers::u16) = "<< sizeof(numbers::u16) << '\n'; - std::cout << "sizeof(numbers::u32) = "<< sizeof(numbers::u32) << '\n'; - std::cout << "sizeof(numbers::u64) = "<< sizeof(numbers::u64) << '\n'; - std::cout << "sizeof(numbers::u128) = "<< sizeof(numbers::u128) << '\n'; + std::cout << "sizeof(numbers::u8) = " << sizeof(numbers::u8) << '\n'; + std::cout << "sizeof(numbers::u16) = " << sizeof(numbers::u16) << '\n'; + std::cout << "sizeof(numbers::u32) = " << sizeof(numbers::u32) << '\n'; + std::cout << "sizeof(numbers::u64) = " << sizeof(numbers::u64) << '\n'; + std::cout << "sizeof(numbers::u128) = " << sizeof(numbers::u128) << '\n'; return 0; } diff --git a/src/include/bits.hh b/src/include/bits.hh index ee72e58..b63d85d 100644 --- a/src/include/bits.hh +++ b/src/include/bits.hh @@ -3,8 +3,8 @@ #include -#include "internal/config.h" #include "internal/bits.hh" +#include "internal/config.h" #if NUMBERS_INTERNAL_CPLUSPLUS_LANG >= 202002L #include diff --git a/src/include/integer.hh b/src/include/integer.hh index ac0da20..7b1e484 100644 --- a/src/include/integer.hh +++ b/src/include/integer.hh @@ -140,9 +140,7 @@ class Integer { return Integer(num_ * other.num_); } - constexpr Integer operator%(const Integer &other) const { - return Integer(num_ % other.num_); - } + constexpr Integer operator%(const Integer &other) const { return Integer(num_ % other.num_); } constexpr Integer abs() const noexcept(false) { if (num_ == min_) { @@ -505,7 +503,9 @@ struct hash { // TODO hash collision template <> struct hash { - size_t operator()(const numbers::i128 &obj) const { return std::hash()(static_cast(obj)); } + size_t operator()(const numbers::i128 &obj) const { + return std::hash()(static_cast(obj)); + } }; } // namespace std diff --git a/src/include/internal/bits.hh b/src/include/internal/bits.hh index 47d65bd..50c5993 100644 --- a/src/include/internal/bits.hh +++ b/src/include/internal/bits.hh @@ -1,8 +1,8 @@ #ifndef NUMBERS_INTERNAL_BITS_HH #define NUMBERS_INTERNAL_BITS_HH -#include #include +#include #if defined(_MSC_VER) && !defined(__clang__) #include @@ -39,11 +39,11 @@ inline int count_leading_zeroes32(uint32_t x) { if (x >> 8) { zeroes -= 8; x >>= 8; - } + } if (x >> 4) { zeroes -= 4; x >>= 4; - } + } return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[x] + zeroes; #endif } @@ -62,14 +62,14 @@ inline int count_leading_zeroes64(uint64_t x) { static_assert(sizeof(unsigned long long) == sizeof(x), "__builtin_clzll does not take 64-bit argument"); return x == 0 ? 64 : __builtin_clzll(x); #elif defined(__MSC_VER) && !defined(__clang__) && (defined(_M_X64) || defined(_M_ARM64)) -// MSVC doesn't have __builtin_clzll. Use _BitScanReverse64 + // MSVC doesn't have __builtin_clzll. Use _BitScanReverse64 unsigned long result = 0; if (_BitScanReverse64(&result, x)) { return 63 - result; } return 64; #elif defined(__MSC_VER) && !defined(__clang__) -// MSVC doesn't have __builtin_clzll. Compose two calls to _BitScanReverse + // MSVC doesn't have __builtin_clzll. Compose two calls to _BitScanReverse unsigned long result = 0; if ((x >> 32) && _BitScanReverse(&result, static_cast(x >> 32))) { return 31 - result; diff --git a/src/include/internal/config.h b/src/include/internal/config.h index c933583..184d4e7 100644 --- a/src/include/internal/config.h +++ b/src/include/internal/config.h @@ -9,5 +9,4 @@ #define NUMBERS_HAVE_BUILTIN(x) 0 #endif // __has_builtin - #endif diff --git a/src/include/uinteger.hh b/src/include/uinteger.hh index 6b88f2d..cc423ca 100644 --- a/src/include/uinteger.hh +++ b/src/include/uinteger.hh @@ -138,9 +138,7 @@ class Uinteger { return Uinteger(num_ * other.num_); } - constexpr Uinteger operator%(const Uinteger &other) const { - return Uinteger(num_ % other.num_); - } + constexpr Uinteger operator%(const Uinteger &other) const { return Uinteger(num_ % other.num_); } constexpr Uinteger operator-() const noexcept(false) { if (num_ == min_) { @@ -285,10 +283,10 @@ class Uinteger { constexpr bool div_overflow(T a, T b) const noexcept { return false; } constexpr bool mul_overflow_helper(T a, T b) const { - if (a == 0 || b == 0) { - return false; - } - return (max_ / a) < b; + if (a == 0 || b == 0) { + return false; + } + return (max_ / a) < b; } constexpr bool mul_overflow(T a, T b) const { @@ -377,7 +375,7 @@ constexpr bool operator==(U lhs, Uinteger rhs) noexcept { return Uinteger(lhs) == rhs; } -template >> +template >> constexpr bool operator>(U lhs, Uinteger rhs) noexcept { return Uinteger(lhs) > rhs; } @@ -444,7 +442,9 @@ struct hash { // TODO hash collision template <> struct hash { - size_t operator()(const numbers::u128 &obj) const { return std::hash()(static_cast(obj)); } + size_t operator()(const numbers::u128 &obj) const { + return std::hash()(static_cast(obj)); + } }; } // namespace std diff --git a/tests/uinteger/u128_overflow.test.cc b/tests/uinteger/u128_overflow.test.cc index 98a6fe6..edaad4d 100644 --- a/tests/uinteger/u128_overflow.test.cc +++ b/tests/uinteger/u128_overflow.test.cc @@ -263,7 +263,7 @@ TEST(u128OverflowTest, DivThrow) { numbers::u128 b = 456; numbers::u128 c = 789; - EXPECT_NO_THROW(a / b); + EXPECT_NO_THROW(a / b); EXPECT_NO_THROW(b / a); EXPECT_NO_THROW(a / c); diff --git a/tests/uinteger/uinteger.test.cc b/tests/uinteger/uinteger.test.cc index f2d3455..13a797f 100644 --- a/tests/uinteger/uinteger.test.cc +++ b/tests/uinteger/uinteger.test.cc @@ -784,7 +784,7 @@ TEST(UintegerTest, Hash) { TEST(UintegerTest, UnorderedSet) { std::unordered_set s8; - size_t cnt = 0; + size_t cnt = 0; for (u8 i = u8::MIN; i < u8::MAX; i = i.saturating_add(19)) { s8.insert(i); ++cnt;