Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
guuzaa committed Mar 21, 2024
1 parent 57c24c4 commit c79bc77
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 34 deletions.
23 changes: 11 additions & 12 deletions examples/size.cc
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/include/bits.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <type_traits>

#include "internal/config.h"
#include "internal/bits.hh"
#include "internal/config.h"

#if NUMBERS_INTERNAL_CPLUSPLUS_LANG >= 202002L
#include <bit>
Expand Down
8 changes: 4 additions & 4 deletions src/include/integer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ class Integer {
return Integer(num_ * other.num_);
}

constexpr Integer operator%(const Integer<T> &other) const {
return Integer(num_ % other.num_);
}
constexpr Integer operator%(const Integer<T> &other) const { return Integer(num_ % other.num_); }

constexpr Integer abs() const noexcept(false) {
if (num_ == min_) {
Expand Down Expand Up @@ -505,7 +503,9 @@ struct hash<numbers::i64> {
// TODO hash collision
template <>
struct hash<numbers::i128> {
size_t operator()(const numbers::i128 &obj) const { return std::hash<numbers::int128>()(static_cast<numbers::int128>(obj)); }
size_t operator()(const numbers::i128 &obj) const {
return std::hash<numbers::int128>()(static_cast<numbers::int128>(obj));
}
};

} // namespace std
Expand Down
10 changes: 5 additions & 5 deletions src/include/internal/bits.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef NUMBERS_INTERNAL_BITS_HH
#define NUMBERS_INTERNAL_BITS_HH

#include <type_traits>
#include <limits>
#include <type_traits>

#if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
Expand Down Expand Up @@ -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
}
Expand All @@ -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<unsigned long>(x >> 32))) {
return 31 - result;
Expand Down
1 change: 0 additions & 1 deletion src/include/internal/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
#define NUMBERS_HAVE_BUILTIN(x) 0
#endif // __has_builtin


#endif
18 changes: 9 additions & 9 deletions src/include/uinteger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ class Uinteger {
return Uinteger(num_ * other.num_);
}

constexpr Uinteger operator%(const Uinteger<T> &other) const {
return Uinteger(num_ % other.num_);
}
constexpr Uinteger operator%(const Uinteger<T> &other) const { return Uinteger(num_ % other.num_); }

constexpr Uinteger operator-() const noexcept(false) {
if (num_ == min_) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -377,7 +375,7 @@ constexpr bool operator==(U lhs, Uinteger<T> rhs) noexcept {
return Uinteger<T>(lhs) == rhs;
}

template <typename U, typename T, typename = std::enable_if_t< std::is_convertible_v<U, T>>>
template <typename U, typename T, typename = std::enable_if_t<std::is_convertible_v<U, T>>>
constexpr bool operator>(U lhs, Uinteger<T> rhs) noexcept {
return Uinteger<T>(lhs) > rhs;
}
Expand Down Expand Up @@ -444,7 +442,9 @@ struct hash<numbers::u64> {
// TODO hash collision
template <>
struct hash<numbers::u128> {
size_t operator()(const numbers::u128 &obj) const { return std::hash<numbers::uint128>()(static_cast<numbers::uint128>(obj)); }
size_t operator()(const numbers::u128 &obj) const {
return std::hash<numbers::uint128>()(static_cast<numbers::uint128>(obj));
}
};

} // namespace std
Expand Down
2 changes: 1 addition & 1 deletion tests/uinteger/u128_overflow.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/uinteger/uinteger.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ TEST(UintegerTest, Hash) {

TEST(UintegerTest, UnorderedSet) {
std::unordered_set<u8> 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;
Expand Down

0 comments on commit c79bc77

Please sign in to comment.