Skip to content

Commit

Permalink
Merge pull request #336 from ckormanyos/handle_issue_335
Browse files Browse the repository at this point in the history
Handle issue 335
  • Loading branch information
ckormanyos authored Nov 8, 2022
2 parents 60f2551 + 48d6a3e commit b3f4aac
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CodeQL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: gcc-native-for-codeql
run: |
echo "build application on the command line"
g++ -finline-functions -m64 -O3 -Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wundef -Wunused-parameter -Wuninitialized -Wunreachable-code -Winit-self -Wzero-as-null-pointer-constant -std=c++14 -DWIDE_INTEGER_HAS_LIMB_TYPE_UINT64 -I. -I../boost-root -pthread -lpthread test/test.cpp test/test_uintwide_t_boost_backend.cpp test/test_uintwide_t_edge_cases.cpp test/test_uintwide_t_examples.cpp test/test_uintwide_t_float_convert.cpp test/test_uintwide_t_int_convert.cpp test/test_uintwide_t_n_base.cpp test/test_uintwide_t_n_binary_ops_base.cpp test/test_uintwide_t_spot_values.cpp examples/example000_numeric_limits.cpp examples/example000a_builtin_convert.cpp examples/example001_mul_div.cpp examples/example001a_div_mod.cpp examples/example002_shl_shr.cpp examples/example003_sqrt.cpp examples/example003a_cbrt.cpp examples/example004_rootk_pow.cpp examples/example005_powm.cpp examples/example005a_pow_factors_of_p99.cpp examples/example006_gcd.cpp examples/example007_random_generator.cpp examples/example008_miller_rabin_prime.cpp examples/example008a_miller_rabin_prime.cpp examples/example009_timed_mul.cpp examples/example009a_timed_mul_4_by_4.cpp examples/example009b_timed_mul_8_by_8.cpp examples/example010_uint48_t.cpp examples/example011_uint24_t.cpp examples/example012_rsa_crypto.cpp -o wide_integer.exe
g++ -fno-exceptions -fno-rtti -finline-functions -m64 -O3 -Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wundef -Wunused-parameter -Wuninitialized -Wunreachable-code -Winit-self -Wzero-as-null-pointer-constant -std=c++14 -DWIDE_INTEGER_HAS_LIMB_TYPE_UINT64 -I. -I../boost-root -pthread -lpthread test/test.cpp test/test_uintwide_t_boost_backend.cpp test/test_uintwide_t_edge_cases.cpp test/test_uintwide_t_examples.cpp test/test_uintwide_t_float_convert.cpp test/test_uintwide_t_int_convert.cpp test/test_uintwide_t_n_base.cpp test/test_uintwide_t_n_binary_ops_base.cpp test/test_uintwide_t_spot_values.cpp examples/example000_numeric_limits.cpp examples/example000a_builtin_convert.cpp examples/example001_mul_div.cpp examples/example001a_div_mod.cpp examples/example002_shl_shr.cpp examples/example003_sqrt.cpp examples/example003a_cbrt.cpp examples/example004_rootk_pow.cpp examples/example005_powm.cpp examples/example005a_pow_factors_of_p99.cpp examples/example006_gcd.cpp examples/example007_random_generator.cpp examples/example008_miller_rabin_prime.cpp examples/example008a_miller_rabin_prime.cpp examples/example009_timed_mul.cpp examples/example009a_timed_mul_4_by_4.cpp examples/example009b_timed_mul_8_by_8.cpp examples/example010_uint48_t.cpp examples/example011_uint24_t.cpp examples/example012_rsa_crypto.cpp -o wide_integer.exe
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
Expand Down
30 changes: 27 additions & 3 deletions .github/workflows/wide_integer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ jobs:
git submodule update --init libs/multiprecision
./bootstrap.bat
./b2 headers
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: 14.2
Expand All @@ -553,7 +553,7 @@ jobs:
git submodule update --init libs/multiprecision
./bootstrap.bat
./b2 headers
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: 14.3
Expand All @@ -580,7 +580,7 @@ jobs:
git submodule update --init libs/multiprecision
./bootstrap.bat
./b2 headers
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: 14.3
Expand Down Expand Up @@ -743,3 +743,27 @@ jobs:
echo "ls -la ./test_uintwide_t_boost_backend_via_test_arithmetic.exe"
ls -la ./test_uintwide_t_boost_backend_via_test_arithmetic.exe
./test_uintwide_t_boost_backend_via_test_arithmetic.exe
gcc-clang-xtra:
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
standard: [ c++20, c++2b ]
compiler: [ g++-12, clang++-14 ]
suite: [ test_uintwide_t_xtra_from_issue_335 ]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: update-tools
run: sudo apt install g++-12 clang-14
- name: gcc-clang-xtra
run: |
echo "compile ./${{ matrix.suite }}.exe"
${{ matrix.compiler }} -v
${{ matrix.compiler }} -finline-functions -m64 -O3 -Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wundef -Wunused-parameter -Wuninitialized -Wunreachable-code -Winit-self -Wzero-as-null-pointer-constant -std=${{ matrix.standard }} -DWIDE_INTEGER_DISABLE_PRIVATE_CLASS_DATA_MEMBERS -I. test/${{ matrix.suite }}.cpp -o ${{ matrix.suite }}.exe
ls -la ./${{ matrix.suite }}.exe
./${{ matrix.suite }}.exe
2 changes: 0 additions & 2 deletions .tidy/make/make_tidy_02_files.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,3 @@ FILES_PRJ = $(PATH_SRC)/test/test_uintwide_t_boost_backend \
$(PATH_SRC)/examples/example010_uint48_t \
$(PATH_SRC)/examples/example011_uint24_t \
$(PATH_SRC)/examples/example012_rsa_crypto

#$(PATH_SRC)/test/test \
34 changes: 17 additions & 17 deletions .tidy/make/make_tidy_03_flags.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ ifneq ($(MY_STD),)
STD := $(MY_STD)
endif

CXX_FLAGS = $(CC) \
-march=native \
-mtune=native \
-O3 \
-Wall \
-Wextra \
-Wconversion \
-Wsign-conversion \
CXX_FLAGS = $(CC) \
-march=native \
-mtune=native \
-O3 \
-Wall \
-Wextra \
-Wconversion \
-Wsign-conversion \
-std=$(STD)

C_DEFINES = WIDE_INTEGER_HAS_MUL_8_BY_8_UNROLL

C_INCLUDES = $(PATH_SRC) \
C_INCLUDES = $(PATH_SRC) \
$(BOOST_ROOT_FOR_TIDY)

C_DEFINES :=$(addprefix -D,$(C_DEFINES))
C_INCLUDES :=$(addprefix -I,$(C_INCLUDES))


TIDY_CHECKS = "*, \
-readability-identifier-length, \
-altera-struct-pack-align, \
-altera-unroll-loops, \
-fuchsia-*, \
TIDY_CHECKS = "*, \
-readability-identifier-length, \
-altera-struct-pack-align, \
-altera-unroll-loops, \
-fuchsia-*, \
-llvmlibc-*"

TIDY_FLAGS = --extra-arg-before=--driver-mode=g++ \
--header-filter=uintwide_t \
-warnings-as-errors=* \
TIDY_FLAGS = --extra-arg-before=--driver-mode=g++ \
--header-filter=uintwide_t \
-warnings-as-errors=* \
-checks=$(TIDY_CHECKS)
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ enabled or disabled at compile time with the compiler switches:
#define WIDE_INTEGER_NAMESPACE
#define WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR
#define WIDE_INTEGER_TEST_REPRESENTATION_AS_STD_LIST
#define WIDE_INTEGER_DISABLE_PRIVATE_CLASS_DATA_MEMBERS
```
When working with even the most tiny microcontroller systems,
Expand Down Expand Up @@ -486,7 +487,7 @@ for instance,
```

places all parts of the wide-integer implementation and its details
within the prepended outer namespace `something_unique` ---
within the prepended outer namespace `something_unique` -
as in

```cpp
Expand Down Expand Up @@ -545,6 +546,21 @@ the macro `WIDE_INTEGER_DISABLE_WIDE_INTEGER_CONSTEXPR` will also
be defined automatically because `std::list` is incompatible
with some or most of wide-integer's `constexpr`-ness.

```cpp
#define WIDE_INTEGER_DISABLE_PRIVATE_CLASS_DATA_MEMBERS
```

This optional macro can be used to switch `uintwide_t`'s
data member access from _private_ to _public_. This allows the
`uintwide_t` class to be used as a so-called _structured_ class,
such as is needed for constant-valued template parameters
in the sense of C++20's `constexpr`-ness.

Making private data members public is unusual for some designs.
So the preprocessor switch `WIDE_INTEGER_DISABLE_PRIVATE_CLASS_DATA_MEMBERS`
is not defined (i.e., not set) by default. This ensures that
`uintwide_t`'s data members remain private by default.

## Detailed examples

We will now present various straightforward detailed examples.
Expand Down
5 changes: 5 additions & 0 deletions math/wide_integer/uintwide_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -2742,7 +2742,9 @@
);
}

#if !defined(WIDE_INTEGER_DISABLE_PRIVATE_CLASS_DATA_MEMBERS)
private:
#endif
representation_type
values // NOLINT(readability-identifier-naming)
{
Expand All @@ -2751,6 +2753,9 @@
typename representation_type::allocator_type()
};

#if defined(WIDE_INTEGER_DISABLE_PRIVATE_CLASS_DATA_MEMBERS)
private:
#endif
friend auto ::test_uintwide_t_edge::test_various_isolated_edge_cases() -> bool;

explicit constexpr uintwide_t(const representation_type& other_rep)
Expand Down
173 changes: 86 additions & 87 deletions test/test_uintwide_t_spot_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,92 +11,6 @@
#include <math/wide_integer/uintwide_t.h>
#include <test/test_uintwide_t.h>

namespace exercise_bad_string_input
{
auto test_uintwide_t_spot_values_exercise_bad_string_input() -> bool
{
#if defined WIDE_INTEGER_NAMESPACE
using local_uint128_t = WIDE_INTEGER_NAMESPACE::math::wide_integer::uint128_t;
#else
using local_uint128_t = ::math::wide_integer::uint128_t;
#endif

WIDE_INTEGER_CONSTEXPR local_uint128_t u("bad-string-input");

const bool result_bad_string_input_is_ok = (u == (std::numeric_limits<local_uint128_t>::max)());

#if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)
static_assert(u == (std::numeric_limits<local_uint128_t>::max)(), "Error: Reaction to bad string input is not OK");
#endif

return result_bad_string_input_is_ok;
}
} // namespace exercise_bad_string_input

namespace exercise_pow_zero_one_two
{
auto test_uintwide_t_spot_values_exercise_pow_zero_one_two() -> bool
{
#if defined WIDE_INTEGER_NAMESPACE
using local_uint128_t = WIDE_INTEGER_NAMESPACE::math::wide_integer::uint128_t;
#else
using local_uint128_t = ::math::wide_integer::uint128_t;
#endif

WIDE_INTEGER_CONSTEXPR local_uint128_t u(UINT64_C(9999999978787878));

using std::pow;

WIDE_INTEGER_CONSTEXPR local_uint128_t u0 = pow(u, 0);
WIDE_INTEGER_CONSTEXPR local_uint128_t u1 = pow(u, 1);
WIDE_INTEGER_CONSTEXPR local_uint128_t u2 = pow(u, 2);

const bool result_pow_is_ok =
(
(u0 == 1)
&& (u1 == u)
&& (u2 == u * u)
);

#if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)
static_assert(u0 == 1, "Error: Power of zero is not OK");
static_assert(u1 == u, "Error: Power of one is not OK");
static_assert(u2 == u * u, "Error: Power of two is not OK");
#endif

return result_pow_is_ok;
}
} // namespace exercise_pow_zero_one_two

namespace exercise_octal
{
auto test_uintwide_t_spot_values_exercise_octal() -> bool
{
#if defined WIDE_INTEGER_NAMESPACE
using local_uint128_t = WIDE_INTEGER_NAMESPACE::math::wide_integer::uint128_t;
#else
using local_uint128_t = ::math::wide_integer::uint128_t;
#endif

WIDE_INTEGER_CONSTEXPR local_uint128_t u_dec("100000000000000000000777772222211111");
WIDE_INTEGER_CONSTEXPR local_uint128_t u_oct("0464114134543515404256122464446501262047");

auto result_conversion_is_ok = (u_dec == u_oct);

#if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)
static_assert(u_dec == u_oct, "Error: Conversion decimal to octal is not OK");
#endif

std::stringstream strm;

strm << std::showbase << std::oct << u_oct;

result_conversion_is_ok = ((strm.str() == "0464114134543515404256122464446501262047") && result_conversion_is_ok);

return result_conversion_is_ok;
}
} // namespace exercise_octal

namespace from_issue_316
{
// See also: https://github.com/ckormanyos/wide-integer/issues/266
Expand Down Expand Up @@ -226,7 +140,6 @@ namespace from_issue_316

} // namespace from_issue_316


namespace from_issue_266
{
auto test_uintwide_t_spot_values_from_issue_266_inc() -> bool
Expand Down Expand Up @@ -427,6 +340,92 @@ namespace from_pull_request_130
}
} // namespace from_pull_request_130

namespace exercise_bad_string_input
{
auto test_uintwide_t_spot_values_exercise_bad_string_input() -> bool
{
#if defined WIDE_INTEGER_NAMESPACE
using local_uint128_t = WIDE_INTEGER_NAMESPACE::math::wide_integer::uint128_t;
#else
using local_uint128_t = ::math::wide_integer::uint128_t;
#endif

WIDE_INTEGER_CONSTEXPR local_uint128_t u("bad-string-input");

const bool result_bad_string_input_is_ok = (u == (std::numeric_limits<local_uint128_t>::max)());

#if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)
static_assert(u == (std::numeric_limits<local_uint128_t>::max)(), "Error: Reaction to bad string input is not OK");
#endif

return result_bad_string_input_is_ok;
}
} // namespace exercise_bad_string_input

namespace exercise_pow_zero_one_two
{
auto test_uintwide_t_spot_values_exercise_pow_zero_one_two() -> bool
{
#if defined WIDE_INTEGER_NAMESPACE
using local_uint128_t = WIDE_INTEGER_NAMESPACE::math::wide_integer::uint128_t;
#else
using local_uint128_t = ::math::wide_integer::uint128_t;
#endif

WIDE_INTEGER_CONSTEXPR local_uint128_t u(UINT64_C(9999999978787878));

using std::pow;

WIDE_INTEGER_CONSTEXPR local_uint128_t u0 = pow(u, 0);
WIDE_INTEGER_CONSTEXPR local_uint128_t u1 = pow(u, 1);
WIDE_INTEGER_CONSTEXPR local_uint128_t u2 = pow(u, 2);

const bool result_pow_is_ok =
(
(u0 == 1)
&& (u1 == u)
&& (u2 == u * u)
);

#if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)
static_assert(u0 == 1, "Error: Power of zero is not OK");
static_assert(u1 == u, "Error: Power of one is not OK");
static_assert(u2 == u * u, "Error: Power of two is not OK");
#endif

return result_pow_is_ok;
}
} // namespace exercise_pow_zero_one_two

namespace exercise_octal
{
auto test_uintwide_t_spot_values_exercise_octal() -> bool
{
#if defined WIDE_INTEGER_NAMESPACE
using local_uint128_t = WIDE_INTEGER_NAMESPACE::math::wide_integer::uint128_t;
#else
using local_uint128_t = ::math::wide_integer::uint128_t;
#endif

WIDE_INTEGER_CONSTEXPR local_uint128_t u_dec("100000000000000000000777772222211111");
WIDE_INTEGER_CONSTEXPR local_uint128_t u_oct("0464114134543515404256122464446501262047");

auto result_conversion_is_ok = (u_dec == u_oct);

#if(WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST == 1)
static_assert(u_dec == u_oct, "Error: Conversion decimal to octal is not OK");
#endif

std::stringstream strm;

strm << std::showbase << std::oct << u_oct;

result_conversion_is_ok = ((strm.str() == "0464114134543515404256122464446501262047") && result_conversion_is_ok);

return result_conversion_is_ok;
}
} // namespace exercise_octal

namespace local_test_spot_values
{
auto test() -> bool;
Expand Down
Loading

0 comments on commit b3f4aac

Please sign in to comment.