Skip to content

Commit

Permalink
feat(add): support int128 + - * / (#10)
Browse files Browse the repository at this point in the history
* try to support i128 add

* try to adopt int128 & uint128 from abseil-cpp 

* add int128 add test

* add int128 mul test

* support int128 div operation
  • Loading branch information
guuzaa authored Feb 24, 2024
1 parent a6442e3 commit d5b3ef8
Show file tree
Hide file tree
Showing 15 changed files with 1,328 additions and 117 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set(THIRD_PARTY_INCLUDE_DIR

include_directories(${SRC_INCLUDE_DIR} ${THIRD_PARTY_INCLUDE_DIR})

# add_subdirectory(src)
add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(third_party)
add_subdirectory(test)
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_subdirectory(numbers)

add_library(numbers_lib STATIC ${ALL_OBJECT_FILES})

find_package(Threads REQUIRED)
Expand Down
39 changes: 39 additions & 0 deletions src/include/bits.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef NUMBERS_BITS_HH
#define NUMBERS_BITS_HH

#include <type_traits>

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

#if NUMBERS_INTERNAL_CPLUSPLUS_LANG >= 202002L
#include <bit>
#endif

// check if the compiler supports <bit> header
#if defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L

using std::countl_one;
using std::countl_zero;

#else

// Counting functions
//
// While these functions are typically constexpr, on some platforms, they may
// not be marked as constexpr due to constraints of the compiler/available
// intrinsics.
template <class T>
inline typename std::enable_if<std::is_unsigned_v<T>, int>::type countl_zero(T x) noexcept {
return numbers_internal::count_leading_zeroes(x);
}

template <class T>
inline typename std::enable_if<std::is_unsigned_v<T>, int>::type countl_one(T x) noexcept {
// Avoid integer promotion to a wider type
return countl_zero(static_cast<T>(~x));
}

#endif

#endif
Loading

0 comments on commit d5b3ef8

Please sign in to comment.