Skip to content

Commit 14678a9

Browse files
authored
Merge pull request #640 from ckormanyos/more_syntax
More syntax
2 parents be10136 + 84d54f2 commit 14678a9

8 files changed

Lines changed: 175 additions & 107 deletions

File tree

examples/chapter16_08/src/math/test/math_test_independent_test_system_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2019 - 2024.
2+
// Copyright Christopher Kormanyos 2019 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)

examples/chapter16_08/src/math/test/math_test_independent_test_system_boost.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2020 -2024.
2+
// Copyright Christopher Kormanyos 2020 -2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

8-
#ifndef MATH_TEST_INDEPENDENT_TEST_SYSTEM_BOOST_2020_10_10_H_
9-
#define MATH_TEST_INDEPENDENT_TEST_SYSTEM_BOOST_2020_10_10_H_
10-
11-
#include <ctime>
12-
#include <random>
8+
#ifndef MATH_TEST_INDEPENDENT_TEST_SYSTEM_BOOST_2020_10_10_H
9+
#define MATH_TEST_INDEPENDENT_TEST_SYSTEM_BOOST_2020_10_10_H
1310

1411
#include <boost/multiprecision/cpp_int.hpp>
1512
#include <boost/multiprecision/miller_rabin.hpp>
1613

1714
#include <math/test/math_test_independent_test_system_base.h>
1815

16+
#include <ctime>
17+
#include <random>
18+
1919
namespace WIDE_INTEGER_NAMESPACE { namespace math { namespace test {
2020

2121
template<const unsigned Width2>
@@ -46,7 +46,7 @@
4646

4747
++my_seed_count;
4848

49-
if((my_seed_count % 0x1000U) == 0U)
49+
if(static_cast<std::uint32_t>(my_seed_count % 0x1000U) == std::uint32_t { UINT8_C(0) })
5050
{
5151
my_gen.seed(static_cast<typename random_engine_type::result_type>(std::clock()));
5252
}
@@ -63,4 +63,4 @@
6363
} // namespace math
6464
} // namespace WIDE_INTEGER_NAMESPACE
6565

66-
#endif // MATH_TEST_INDEPENDENT_TEST_SYSTEM_BOOST_2020_10_10_H_
66+
#endif // MATH_TEST_INDEPENDENT_TEST_SYSTEM_BOOST_2020_10_10_H

examples/chapter16_08/src/math/test/math_test_independent_test_system_mathlink.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2019 - 2024.
2+
// Copyright Christopher Kormanyos 2019 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -81,7 +81,7 @@
8181
my_valid = ((is_open() == false) ? open() : is_open());
8282
}
8383

84-
virtual ~independent_test_system_mathlink() noexcept
84+
~independent_test_system_mathlink() noexcept override
8585
{
8686
const volatile bool close_is_ok = close();
8787

examples/chapter16_08/src/math/test/math_test_independent_test_system_none.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2019 - 2024.
2+
// Copyright Christopher Kormanyos 2019 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,7 +17,7 @@
1717
public:
1818
independent_test_system_none() noexcept = default;
1919

20-
virtual ~independent_test_system_none() noexcept = default;
20+
~independent_test_system_none() noexcept override = default;
2121

2222
auto is_prime(const char* const pstr_prime_candidate) const -> bool override
2323
{
Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2020 - 2022.
2+
// Copyright Christopher Kormanyos 2020 - 2025.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

8-
#ifndef MCAL_RANDOM_2020_06_11_H_
9-
#define MCAL_RANDOM_2020_06_11_H_
10-
11-
#include <cstdint>
12-
#include <limits>
8+
#ifndef MCAL_RANDOM_2020_06_11_H
9+
#define MCAL_RANDOM_2020_06_11_H
1310

1411
#include <mcal_cpu.h>
1512
#include <mcal_port.h>
1613
#include <mcal_port_pin_dummy.h>
1714
#include <mcal_spi/mcal_spi_software_port_driver.h>
1815
#include <util/utility/util_time.h>
1916

17+
#include <cstdint>
18+
#include <limits>
19+
2020
namespace mcal { namespace random {
2121

2222
namespace detail {
@@ -31,95 +31,94 @@
3131
public:
3232
using result_type = UnsignedIntegralType;
3333

34-
static_assert(std::uint_fast8_t(std::numeric_limits<result_type>::digits % 8) == 0U,
34+
static_assert(static_cast<std::uint_fast8_t>(std::numeric_limits<result_type>::digits % 8) == std::uint_fast8_t { UINT8_C(0) },
3535
"Error: Integral type must have a multiple of 8 digits.");
3636

37-
static_assert(( (std::numeric_limits<result_type>::is_integer == true)
38-
&& (std::numeric_limits<result_type>::is_signed == false)),
37+
static_assert(( std::numeric_limits<result_type>::is_integer
38+
&& (!std::numeric_limits<result_type>::is_signed)),
3939
"Error: Integral type must an unsigned integral type.");
4040

41-
random_engine_reverse_z_diode_raw(const result_type = result_type()) noexcept
42-
: my_spi() { }
41+
explicit random_engine_reverse_z_diode_raw(const result_type = result_type()) noexcept { }
42+
43+
random_engine_reverse_z_diode_raw(const random_engine_reverse_z_diode_raw&) noexcept { }
4344

44-
random_engine_reverse_z_diode_raw(const random_engine_reverse_z_diode_raw&)
45-
: my_spi() { }
45+
random_engine_reverse_z_diode_raw(const random_engine_reverse_z_diode_raw&&) noexcept { }
4646

47-
random_engine_reverse_z_diode_raw(const random_engine_reverse_z_diode_raw&&)
48-
: my_spi() { }
47+
~random_engine_reverse_z_diode_raw() noexcept { }
4948

50-
random_engine_reverse_z_diode_raw& operator=(const random_engine_reverse_z_diode_raw&)
49+
auto operator=(const random_engine_reverse_z_diode_raw&) noexcept -> random_engine_reverse_z_diode_raw&
5150
{
5251
return *this;
5352
}
5453

55-
random_engine_reverse_z_diode_raw& operator=(const random_engine_reverse_z_diode_raw&&)
54+
auto operator=(const random_engine_reverse_z_diode_raw&&) noexcept -> random_engine_reverse_z_diode_raw&
5655
{
5756
return *this;
5857
}
5958

60-
static constexpr result_type(min)() noexcept
59+
static constexpr auto (min)() noexcept -> result_type
6160
{
62-
return result_type(0U);
61+
return result_type { UINT8_C(0) };
6362
}
6463

65-
static constexpr result_type(max)() noexcept
64+
static constexpr auto (max)() noexcept -> result_type
6665
{
6766
return (std::numeric_limits<result_type>::max)();
6867
}
6968

70-
void seed(result_type = result_type()) { }
69+
auto seed(result_type = result_type()) noexcept -> void { }
7170

72-
result_type operator()() noexcept
71+
auto operator()() noexcept -> result_type
7372
{
7473
// Get random value having type result_type.
7574
return get_value(my_spi);
7675
}
7776

78-
void discard(unsigned long long skip) noexcept
77+
auto discard(unsigned long long skip) noexcept -> void
7978
{
80-
for(unsigned long long i = 0U; i < skip; ++i)
79+
for(unsigned long long i = static_cast<unsigned long long>(UINT8_C(0)); i < skip; ++i)
8180
{
82-
const result_type tmp = get_value(my_spi);
81+
const result_type tmp { get_value(my_spi) };
8382

8483
static_cast<void>(tmp);
8584
}
8685
}
8786

8887
private:
89-
spi_type my_spi;
88+
spi_type my_spi { };
9089

91-
static result_type get_value(util::communication_base& com) noexcept
90+
static auto get_value(util::communication_base& com) noexcept -> result_type
9291
{
93-
result_type value = result_type(0U);
92+
result_type value { UINT8_C(0) };
9493

95-
for(std::uint_fast8_t i = 0U; i < std::uint_fast8_t(std::numeric_limits<result_type>::digits / 8); ++i)
94+
for(std::uint_fast8_t i { std::uint_fast8_t { UINT8_C(0) } };
95+
i < static_cast<std::uint_fast8_t>(std::numeric_limits<result_type>::digits / 8);
96+
++i)
9697
{
9798
std::uint8_t by;
9899

99-
com.send(UINT8_C(0xFFU));
100+
com.send(UINT8_C(0xFF));
100101
com.recv(by);
101102

102-
value |= result_type(result_type(by) << (i * 8U));
103+
value |= static_cast<result_type>(static_cast<result_type>(by) << static_cast<unsigned>(i * 8U));
103104
}
104105

105106
return value;
106107
}
107108
};
108109

109110
using spi_software_port_driver_type =
110-
mcal::spi::spi_software_port_driver<mcal::port::port_pin<std::uint8_t, std::uint8_t, mcal::reg::portc, 4U>,
111+
mcal::spi::spi_software_port_driver<mcal::port::port_pin<std::uint8_t, std::uint8_t, mcal::reg::portc, std::uint8_t { UINT8_C(4) }>,
111112
mcal::port::port_pin_dummy,
112113
mcal::port::port_pin_dummy,
113-
mcal::port::port_pin<std::uint8_t, std::uint8_t, mcal::reg::portc, 5U>,
114-
45U,
114+
mcal::port::port_pin<std::uint8_t, std::uint8_t, mcal::reg::portc, std::uint8_t { UINT8_C(5) }>,
115+
static_cast<std::uint_fast16_t>(UINT8_C(45)),
115116
false>;
116117

117118
} // namespace detail
118119

119-
using default_random_engine =
120-
detail::random_engine_reverse_z_diode_raw<detail::spi_software_port_driver_type,
121-
std::uint8_t>;
120+
using default_random_engine = detail::random_engine_reverse_z_diode_raw<detail::spi_software_port_driver_type, std::uint8_t>;
122121

123122
} } // namespace mcal::random
124123

125-
#endif // MCAL_RANDOM_2020_06_11_H_
124+
#endif // MCAL_RANDOM_2020_06_11_H

ref_app/src/app/benchmark/app_benchmark_detail.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,33 @@
2828
using std::fabs;
2929
using std::fpclassify;
3030

31-
NumericType closeness { };
31+
using numeric_type = NumericType;
3232

33-
if(fpclassify(b) == FP_ZERO)
33+
const int fpc_a { fpclassify(a) };
34+
const int fpc_b { fpclassify(b) };
35+
36+
bool result_is_ok { };
37+
38+
if(fpc_b == FP_ZERO)
39+
{
40+
const numeric_type closeness { (fpc_a == FP_ZERO) ? numeric_type { 0 } : fabs(a - b) };
41+
42+
result_is_ok = (closeness < tol);
43+
}
44+
else if((fpc_a != FP_NORMAL) || (fpc_b != FP_NORMAL))
3445
{
35-
closeness = fabs(a - b);
46+
result_is_ok = false;
3647
}
3748
else
3849
{
39-
const NumericType ratio { a / b };
50+
const numeric_type ratio { a / b };
51+
52+
const numeric_type closeness { fabs(numeric_type { 1 - ratio }) };
4053

41-
closeness = NumericType { fabs(NumericType { 1 - ratio }) };
54+
result_is_ok = (closeness < tol);
4255
}
4356

44-
return (closeness < tol);
57+
return result_is_ok;
4558
}
4659

4760
} // namespace detail

0 commit comments

Comments
 (0)