Skip to content

Commit

Permalink
Correct docs and namespaces and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Nov 29, 2023
1 parent fb005a5 commit 0ac2b71
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 93 deletions.
42 changes: 3 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,9 @@ This preprocessor switch was motivated by the discussion in
By default, the preprocessor switch `WIDE_INTEGER_HAS_CLZ_LIMB_OPTIMIZATIONS`
is not defined and CLZ-limb optimizations are default-_disabled_.

### C++14, 17, 20 `constexpr` support
### C++14, 17, 20, 23 and beyond `constexpr` support

When using C++20 `uintwide_t` supports compile-time
When using C++14 and beyond, `uintwide_t` supports compile-time
`constexpr` construction and evaluation of results
of binary arithmetic, comparison operators
and various elementary functions.
Expand All @@ -797,7 +797,7 @@ and its subsequent `return` of the value zero
```cpp
#include <math/wide_integer/uintwide_t.h>

// Use (at least) a C++20 compiler for this example.
// Use (at least) a C++14 compiler for this example.

using uint256_t = ::math::wide_integer::uintwide_t<256U>;
using uint512_t = ::math::wide_integer::uintwide_t<512U>;
Expand All @@ -823,42 +823,6 @@ auto main() -> int
}
```
The so-called `constexpr`-_ness_ of `uintwide_t` has been checked on GCC 10 and up,
clang 10 and up (with `-std=c++20`) and VC 14.2 (with `/std:c++latest`),
also for various embedded compilers such as `avr-gcc` 10 and up,
`arm-non-eabi-gcc` 10 and up, and more. In addition,
some compilations using compilers having less modern standards
such as C++14, 17, 2a have also been checked
for `constexpr` usage of `uintwide_t`. If you have an older
compiler, you might have to check the compiler's
ability to obtain the entire benefit of `constexpr` with `uintwide_t`.
If full `constexpr` compliance is not available or its
availability is unknown, the preprocessor symbols below can be useful.
These symbols are defined or set directly within the header(s)
of the wide_integer library.
```cpp
WIDE_INTEGER_CONSTEXPR
WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST
```

The preprocessor symbol `WIDE_INTEGER_CONSTEXPR` acts as either
a synonym for `constexpr` or expands to nothing depending on
whether the availability of `constexpr` support has been automatically
detected or not.
The preprocessor symbol `WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST`
has the value of `0` or `1`, where `1` indicates that `uintwide_t`
values qualified with `WIDE_INTEGER_CONSTEXPR` are actually
compile-time constant (i.e., `constexpr`).

Detection of availability of `constexpr` support is implemented
[with preprocessor queries in uintwide_t.h](https://github.com/ckormanyos/wide-integer/blob/4ad2cb5e96acc0b326c8fc2bbb74546dc90053ef/math/wide_integer/uintwide_t.h#L36).
These complicated proprocessor queries are not complete (in the sense of
detecting all world-wide compiler/target systems). If you have
a specific compiler/target system needing `constexpr` detection,
please feel free to contact me directly so that this can be implemented.

### Signed integer support
Signed big integers are also supported in the wide_integer library.
Expand Down
2 changes: 1 addition & 1 deletion boost/multiprecision/uintwide_t_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
WIDE_INTEGER_CONSTEXPR auto operator=(const std::string& str_rep) -> uintwide_t_backend& { m_value = representation_type(str_rep); return *this; }
WIDE_INTEGER_CONSTEXPR auto operator=(const char* char_ptr) -> uintwide_t_backend& { m_value = representation_type(char_ptr); return *this; }

WIDE_INTEGER_CONSTEXPR auto swap(uintwide_t_backend& other) -> void
WIDE_INTEGER_CONSTEXPR auto swap(uintwide_t_backend& other) noexcept -> void
{
m_value.representation().swap(other.m_value.representation());
}
Expand Down
50 changes: 25 additions & 25 deletions math/wide_integer/uintwide_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,19 @@
private:
iterator_type current; // NOLINT(readability-identifier-naming)

friend inline constexpr auto operator< (const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current > y.current); }
friend inline constexpr auto operator<=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current >= y.current); }
friend inline constexpr auto operator==(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current == y.current); }
friend inline constexpr auto operator!=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current != y.current); }
friend inline constexpr auto operator>=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current <= y.current); }
friend inline constexpr auto operator> (const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current < y.current); }
friend constexpr auto operator< (const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current > y.current); }
friend constexpr auto operator<=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current >= y.current); }
friend constexpr auto operator==(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current == y.current); }
friend constexpr auto operator!=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current != y.current); }
friend constexpr auto operator>=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current <= y.current); }
friend constexpr auto operator> (const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current < y.current); }

friend inline constexpr auto operator-(const reverse_iterator& x, const reverse_iterator& y) -> typename reverse_iterator::difference_type
friend constexpr auto operator-(const reverse_iterator& x, const reverse_iterator& y) -> typename reverse_iterator::difference_type
{
return (y.current - x.current);
}

friend inline constexpr auto operator+(typename reverse_iterator::difference_type n, const reverse_iterator& x) -> reverse_iterator
friend constexpr auto operator+(typename reverse_iterator::difference_type n, const reverse_iterator& x) -> reverse_iterator
{
return reverse_iterator(x.current - n);
}
Expand Down Expand Up @@ -654,7 +654,7 @@
WIDE_INTEGER_NODISCARD static constexpr auto max_size() -> size_type { return N; }

template<typename T2>
constexpr auto swap(array<T2, N>& y) -> void
constexpr auto swap(array<T2, N>& y) noexcept -> void
{
swap_ranges_unsafe(begin(), end(), y.begin());
}
Expand Down Expand Up @@ -723,7 +723,7 @@
}

template<typename T, size_t N >
constexpr auto swap(array<T, N>& x, array<T, N>& y) -> void
constexpr auto swap(array<T, N>& x, array<T, N>& y) noexcept -> void
{
swap_ranges_unsafe(x.begin(), x.end(), y.begin());
}
Expand Down Expand Up @@ -1857,32 +1857,32 @@
};

template<typename UnsignedIntegralType>
inline WIDE_INTEGER_CONSTEXPR auto lsb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type;
WIDE_INTEGER_CONSTEXPR auto lsb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type;

template<typename UnsignedIntegralType>
inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type;
WIDE_INTEGER_CONSTEXPR auto msb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type;

template<>
inline WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint32_t>(const std::uint32_t& u) -> unsigned_fast_type;
WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint32_t>(const std::uint32_t& u) -> unsigned_fast_type;

template<>
inline WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint16_t>(const std::uint16_t& u) -> unsigned_fast_type;
WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint16_t>(const std::uint16_t& u) -> unsigned_fast_type;

template<>
inline WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint8_t>(const std::uint8_t& u) -> unsigned_fast_type;
WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint8_t>(const std::uint8_t& u) -> unsigned_fast_type;

// Use a local implementation of string copy.
template<typename DestinationIterator,
typename SourceIterator>
inline WIDE_INTEGER_CONSTEXPR auto strcpy_unsafe(DestinationIterator dst, SourceIterator src) -> DestinationIterator
WIDE_INTEGER_CONSTEXPR auto strcpy_unsafe(DestinationIterator dst, SourceIterator src) -> DestinationIterator
{
while((*dst++ = *src++) != '\0') { ; } // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)

return dst;
}

// Use a local implementation of string length.
inline WIDE_INTEGER_CONSTEXPR auto strlen_unsafe(const char* p_str) -> unsigned_fast_type
WIDE_INTEGER_CONSTEXPR auto strlen_unsafe(const char* p_str) -> unsigned_fast_type
{
auto str_len_count = static_cast<unsigned_fast_type>(UINT8_C(0));

Expand Down Expand Up @@ -6011,7 +6011,7 @@
#endif // !defined(WIDE_INTEGER_DISABLE_FLOAT_INTEROP)

template<typename UnsignedIntegralType>
inline WIDE_INTEGER_CONSTEXPR auto lsb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type
WIDE_INTEGER_CONSTEXPR auto lsb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type
{
// Compile-time checks.
static_assert(( std::is_integral<UnsignedIntegralType>::value
Expand Down Expand Up @@ -6041,7 +6041,7 @@
}

template<typename UnsignedIntegralType>
inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type
WIDE_INTEGER_CONSTEXPR auto msb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type
{
// Compile-time checks.
static_assert(( std::is_integral<UnsignedIntegralType>::value
Expand Down Expand Up @@ -6076,7 +6076,7 @@
}

template<>
inline WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint32_t>(const std::uint32_t& u) -> unsigned_fast_type
WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint32_t>(const std::uint32_t& u) -> unsigned_fast_type
{
auto r = static_cast<unsigned_fast_type>(UINT8_C(0));
auto x = static_cast<std::uint_fast32_t>(u);
Expand All @@ -6092,7 +6092,7 @@
}

template<>
inline WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint16_t>(const std::uint16_t& u) -> unsigned_fast_type
WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint16_t>(const std::uint16_t& u) -> unsigned_fast_type
{
auto r = static_cast<unsigned_fast_type>(UINT8_C(0));
auto x = static_cast<std::uint_fast16_t>(u);
Expand All @@ -6107,7 +6107,7 @@
}

template<>
inline WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint8_t>(const std::uint8_t& u) -> unsigned_fast_type
WIDE_INTEGER_CONSTEXPR auto msb_helper<std::uint8_t>(const std::uint8_t& u) -> unsigned_fast_type
{
auto r = static_cast<unsigned_fast_type>(UINT8_C(0));
auto x = static_cast<std::uint_fast8_t>(u);
Expand Down Expand Up @@ -6139,7 +6139,7 @@
typename LimbType,
typename AllocatorType,
const bool IsSigned>
inline WIDE_INTEGER_CONSTEXPR auto lsb(const uintwide_t<Width2, LimbType, AllocatorType, IsSigned>& x) -> unsigned_fast_type
WIDE_INTEGER_CONSTEXPR auto lsb(const uintwide_t<Width2, LimbType, AllocatorType, IsSigned>& x) -> unsigned_fast_type
{
// Calculate the position of the least-significant bit.
// Use a linear search starting from the least significant limbs.
Expand Down Expand Up @@ -6849,14 +6849,14 @@
result_type param_a; // NOLINT(readability-identifier-naming)
result_type param_b; // NOLINT(readability-identifier-naming)

friend inline constexpr auto operator==(const param_type& lhs,
friend constexpr auto operator==(const param_type& lhs,
const param_type& rhs) -> bool
{
return ( (lhs.param_a == rhs.param_a)
&& (lhs.param_b == rhs.param_b));
}

friend inline constexpr auto operator!=(const param_type& lhs,
friend constexpr auto operator!=(const param_type& lhs,
const param_type& rhs) -> bool
{
return ( (lhs.param_a != rhs.param_a)
Expand Down
10 changes: 5 additions & 5 deletions test/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace detail {

template <class T>
inline typename std::enable_if<!(boost::multiprecision::detail::is_unsigned<T>::value || boost::multiprecision::is_unsigned_number<T>::value), T>::type
typename std::enable_if<!(boost::multiprecision::detail::is_unsigned<T>::value || boost::multiprecision::is_unsigned_number<T>::value), T>::type
abs(const T& a)
{
return a < 0 ? -a : a;
Expand Down Expand Up @@ -107,19 +107,19 @@ enum
};

template <class T>
inline T epsilon_of(const T&)
T epsilon_of(const T&)
{
static_assert(std::numeric_limits<T>::is_specialized, "No numeric_limits support");
return std::numeric_limits<T>::is_integer ? static_cast<T>(1) : std::numeric_limits<T>::epsilon();
}

template <class T>
inline int digits_of(const T&)
int digits_of(const T&)
{
return std::numeric_limits<T>::is_specialized ? std::numeric_limits<T>::digits10 + 3 : std::numeric_limits<long double>::digits10 + 3;
}

inline std::ostream& report_where(const char* file, int line, const char* function)
std::ostream& report_where(const char* file, int line, const char* function)
{
if (function)
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "In function: " << function << std::endl;
Expand All @@ -129,7 +129,7 @@ inline std::ostream& report_where(const char* file, int line, const char* functi

#define BOOST_MP_REPORT_WHERE report_where(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION)

inline void report_severity(int severity)
void report_severity(int severity)
{
if (severity == error_on_fail)
++boost::detail::test_errors();
Expand Down
20 changes: 10 additions & 10 deletions test/test_arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct is_checked_cpp_int : public std::integral_constant<bool, false>
// for __int128 and/or __float128:
//
template <class T>
inline const char* name_of()
const char* name_of()
{
return typeid(T).name();
}
Expand All @@ -46,12 +46,12 @@ inline const char* name_of()
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
template <>
inline const char* name_of<__int128>()
const char* name_of<__int128>()
{
return "__int128";
}
template <>
inline const char* name_of<unsigned __int128>()
const char* name_of<unsigned __int128>()
{
return "unsigned __int128";
}
Expand All @@ -61,7 +61,7 @@ inline const char* name_of<unsigned __int128>()
#endif
#ifdef BOOST_HAS_FLOAT128
//template <>
//inline const char* name_of<__float128>()
//const char* name_of<__float128>()
//{
// return "__float128";
//}
Expand Down Expand Up @@ -557,12 +557,12 @@ void test_signed_integer_ops(const std::integral_constant<bool, false>&)
}

template <class Real>
inline Real negate_if_signed(Real r, const std::integral_constant<bool, true>&)
Real negate_if_signed(Real r, const std::integral_constant<bool, true>&)
{
return -r;
}
template <class Real>
inline Real negate_if_signed(Real r, const std::integral_constant<bool, false>&)
Real negate_if_signed(Real r, const std::integral_constant<bool, false>&)
{
return r;
}
Expand Down Expand Up @@ -1959,7 +1959,7 @@ void test_mixed(const std::integral_constant<bool, false>&)
}

template <class Real>
inline bool check_is_nan(const Real& val, const std::integral_constant<bool, true>&)
bool check_is_nan(const Real& val, const std::integral_constant<bool, true>&)
{
#ifndef BOOST_MP_STANDALONE
return (boost::math::isnan)(val);
Expand All @@ -1969,17 +1969,17 @@ inline bool check_is_nan(const Real& val, const std::integral_constant<bool, tru
#endif
}
template <class Real>
inline bool check_is_nan(const Real&, const std::integral_constant<bool, false>&)
bool check_is_nan(const Real&, const std::integral_constant<bool, false>&)
{
return false;
}
template <class Real>
inline Real negate_value(const Real& val, const std::integral_constant<bool, true>&)
Real negate_value(const Real& val, const std::integral_constant<bool, true>&)
{
return -val;
}
template <class Real>
inline Real negate_value(const Real& val, const std::integral_constant<bool, false>&)
Real negate_value(const Real& val, const std::integral_constant<bool, false>&)
{
return val;
}
Expand Down
Loading

0 comments on commit 0ac2b71

Please sign in to comment.