Skip to content

Commit

Permalink
Merge pull request #561 from ckormanyos/update_wide_math
Browse files Browse the repository at this point in the history
Update wide math
  • Loading branch information
ckormanyos authored Oct 14, 2024
2 parents 2eac221 + b424eda commit 8695f65
Show file tree
Hide file tree
Showing 37 changed files with 2,769 additions and 1,824 deletions.
4 changes: 2 additions & 2 deletions examples/chapter16_08/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ else
TOOL_PREFIX="$2"
fi

CFLAGS="-Wall -Wextra -pedantic -mmcu=atmega328p -fsigned-char -Os -fno-exceptions -gdwarf-2 -finline-functions -ffunction-sections -fdata-sections -flto"
CPPFLAGS="-std=c++11 -fno-rtti -fno-use-cxa-atexit -fno-use-cxa-get-exception-ptr -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs -ftemplate-depth=32"
CFLAGS="-Wall -Wextra -Wpedantic -mmcu=atmega328p -fsigned-char -Os -fno-exceptions -gdwarf-2 -finline-functions -ffunction-sections -fdata-sections -flto"
CPPFLAGS="-std=c++14 -fno-rtti -fno-use-cxa-atexit -fno-use-cxa-get-exception-ptr -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs -ftemplate-depth=32"
CINCLUDES="-Isrc/mcal/avr -Isrc/util/STL -Isrc"
CDEFINES="-DWIDE_INTEGER_NAMESPACE=ckormanyos"

Expand Down
4 changes: 2 additions & 2 deletions examples/chapter16_08/chapter16_08.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_80_0;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_85_0;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_80_0;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)\src;$(SolutionDir)\src\mcal\win32;C:\boost\boost_1_85_0;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
</PropertyGroup>
Expand Down
3,145 changes: 1,900 additions & 1,245 deletions examples/chapter16_08/src/math/wide_integer/uintwide_t.h

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions examples/chapter16_08/src/mcal/mcal_reg_access_dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#ifndef MCAL_REG_ACCESS_DYNAMIC_2013_12_13_H_
#define MCAL_REG_ACCESS_DYNAMIC_2013_12_13_H_

#if defined(__GNUC__) && (__GNUC__ >= 12)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif

namespace mcal
{
namespace reg
Expand Down Expand Up @@ -40,4 +45,8 @@
}
}

#if defined(__GNUC__) && (__GNUC__ >= 12)
#pragma GCC diagnostic pop
#endif

#endif // MCAL_REG_ACCESS_DYNAMIC_2013_12_13_H_
9 changes: 9 additions & 0 deletions examples/chapter16_08/src/mcal/mcal_reg_access_static.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#ifndef MCAL_REG_ACCESS_STATIC_2010_12_01_H_
#define MCAL_REG_ACCESS_STATIC_2010_12_01_H_

#if defined(__GNUC__) && (__GNUC__ >= 12)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif

namespace mcal
{
namespace reg
Expand Down Expand Up @@ -42,4 +47,8 @@
}
}

#if defined(__GNUC__) && (__GNUC__ >= 12)
#pragma GCC diagnostic pop
#endif

#endif // MCAL_REG_ACCESS_STATIC_2010_12_01_H_
5 changes: 3 additions & 2 deletions examples/chapter16_08/src/sys/idle/sys_idle_miller_rabin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <random>

#include <math/wide_integer/miller_rabin/miller_rabin_state.h>
#include <mcal_benchmark.h>
#include <mcal_math_independent_test_system.h>
Expand All @@ -17,6 +15,9 @@
#include <util/utility/util_narrow_cast.h>
#include <util/utility/util_time.h>

#include <array>
#include <random>

namespace
{
using sys_idle_miller_rabin_uint_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t<WIDE_INTEGER_NAMESPACE::math::wide_integer::size_t(128U), std::uint16_t>;
Expand Down
68 changes: 41 additions & 27 deletions examples/chapter16_08/src/util/STL/algorithm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2018.
// Copyright Christopher Kormanyos 2007 - 2024.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -233,7 +233,9 @@
{
for( ; first != last; ++result, ++first)
{
*result = *first;
using result_value_type = typename std::iterator_traits<output_iterator>::value_type;

*result = result_value_type(*first);
}

return result;
Expand All @@ -247,10 +249,12 @@
{
while (first1 != last1)
{
using out2_value_type = typename std::iterator_traits<bidirectional_output_iterator2>::value_type;

--last1;
--last2;

*last2 = *last1;
*last2 = out2_value_type(*last1);
}

return last2;
Expand All @@ -264,12 +268,12 @@
output_iterator result,
unary_function_type unary_function)
{
using output_value_type = typename std::iterator_traits<output_iterator>::value_type;

while(first != last)
{
if(unary_function(*first))
{
using output_value_type = typename std::iterator_traits<output_iterator>::value_type;

*result = output_value_type(*first);

++result;
Expand All @@ -287,10 +291,10 @@
forward_iterator last,
const value_type& value)
{
using forward_value_type = typename std::iterator_traits<forward_iterator>::value_type;

for( ; first != last; ++first)
{
using forward_value_type = typename std::iterator_traits<forward_iterator>::value_type;

*first = forward_value_type(value);
}
}
Expand All @@ -315,10 +319,10 @@
forward_iterator last,
generator_type generator)
{
using forward_value_type = typename std::iterator_traits<forward_iterator>::value_type;

while(first != last)
{
using forward_value_type = typename std::iterator_traits<forward_iterator>::value_type;

*first = forward_value_type(generator());

++first;
Expand All @@ -332,10 +336,10 @@
size_type count,
generator_type generator)
{
using output_value_type = typename std::iterator_traits<output_iterator>::value_type;

for(size_type i = size_type(0); i < count; ++i)
{
using output_value_type = typename std::iterator_traits<output_iterator>::value_type;

*first = output_value_type(generator());

++first;
Expand All @@ -361,10 +365,10 @@
output_iterator result,
unary_function_type unary_function)
{
using output_value_type = typename std::iterator_traits<output_iterator>::value_type;

for( ; first != last; ++first, ++result)
{
using output_value_type = typename std::iterator_traits<output_iterator>::value_type;

*result = output_value_type(unary_function(*first));
}

Expand All @@ -381,10 +385,10 @@
output_iterator result,
binary_function_type binary_function)
{
using output_value_type = typename std::iterator_traits<output_iterator>::value_type;

for( ; first1 != last1; ++first1, ++first2, ++result)
{
using output_value_type = typename std::iterator_traits<output_iterator>::value_type;

*result = output_value_type(binary_function(*first1, *first2));
}

Expand Down Expand Up @@ -421,7 +425,7 @@
{
while(first1 != last1)
{
if(binary_function(*first1, *first2) == false)
if(!binary_function(*first1, *first2))
{
break;
}
Expand Down Expand Up @@ -453,7 +457,7 @@
iterator_type last,
unary_function_type unary_function)
{
while((first != last) && (unary_function(*first) == false))
while((first != last) && (!unary_function(*first)))
{
++first;
}
Expand All @@ -467,7 +471,7 @@
iterator_type last,
unary_function_type unary_function)
{
while((first != last) && (unary_function(*first) == false))
while((first != last) && (!unary_function(*first)))
{
++first;
}
Expand Down Expand Up @@ -765,8 +769,8 @@
}

template<typename swap_type>
void swap(swap_type& left,
swap_type& right)
STL_LOCAL_CONSTEXPR_ALGORITHMS void swap(swap_type& left,
swap_type& right)
{
if(&left != &right)
{
Expand All @@ -777,6 +781,16 @@
}
}

template<typename swap_type>
STL_LOCAL_CONSTEXPR_ALGORITHMS void swap(swap_type&& left,
swap_type&& right)
{
const swap_type tmp(left);

left = right;
right = tmp;
}

template<typename input_iterator1,
typename input_iterator2>
STL_LOCAL_CONSTEXPR_ALGORITHMS void iter_swap(input_iterator1 left,
Expand All @@ -793,9 +807,9 @@

template<typename input_iterator1,
typename input_iterator2>
input_iterator2 swap_ranges(input_iterator1 first1,
input_iterator1 last1,
input_iterator2 first2)
STL_LOCAL_CONSTEXPR_ALGORITHMS input_iterator2 swap_ranges(input_iterator1 first1,
input_iterator1 last1,
input_iterator2 first2)
{
while(first1 != last1)
{
Expand All @@ -810,8 +824,8 @@

template<typename value_type,
std::size_t N>
void swap(value_type(&left) [N],
value_type(&right)[N])
STL_LOCAL_CONSTEXPR_ALGORITHMS void swap(value_type(&left) [N],
value_type(&right)[N])
{
swap_ranges(&left[0U], &left[N], &right[0U]);
}
Expand All @@ -824,7 +838,7 @@
{
for( ; ; ++first)
{
for( ; (first != last) && (unary_function(*first) == true); ++first)
for( ; (first != last) && unary_function(*first); ++first)
{
;
}
Expand All @@ -834,7 +848,7 @@
break;
}

for( ; (first != --last) && (unary_function(*last) == false); )
for( ; (first != --last) && (!unary_function(*last)); )
{
;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/chapter16_08/src/util/STL/array
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
template<typename T, size_t N>
STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator!=(const array<T, N>& left, const array<T, N>& right)
{
return ((left == right) == false);
return (!(left == right));
}

template<typename T, size_t N>
Expand All @@ -135,13 +135,13 @@
template<typename T, size_t N>
STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator>=(const array<T, N>& left, const array<T, N>& right)
{
return ((left < right) == false);
return (!(left < right));
}

template<typename T, size_t N>
STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator<=(const array<T, N>& left, const array<T, N>& right)
{
return ((right < left) == false);
return (!(right < left));
}

template<typename T, size_t N >
Expand Down
18 changes: 8 additions & 10 deletions examples/chapter16_08/src/util/STL/charconv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2021 - 2022.
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2021 - 2024.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand All @@ -8,7 +8,9 @@
#ifndef CHARCONV_2021_04_12_
#define CHARCONV_2021_04_12_

// Implement std::time_t of <charconv> for compilers that do not yet support it.
// Implement some of <charconv> for compilers that do not yet support it.
// At the moment, this contains nothing more than the implementation
// of the struct std::to_chars_result.

#include <errno.h>

Expand Down Expand Up @@ -37,13 +39,9 @@

to_chars_result to_chars(char* first, char* last, bool value, int base = 10) = delete;

inline to_chars_result to_chars(char* first, char* last, float value) { return to_chars_result{ }; }
inline to_chars_result to_chars(char* first, char* last, double value) { return to_chars_result{ }; }
inline to_chars_result to_chars(char* first, char* last, long double value) { return to_chars_result{ }; }

//to_chars_result to_chars(char* first, char* last, float value, chars_format fmt);
//to_chars_result to_chars(char* first, char* last, double value, chars_format fmt);
//to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
inline to_chars_result to_chars(char* first, char* last, float value) { static_cast<void>(first); static_cast<void>(last); static_cast<void>(value); return to_chars_result{ }; }
inline to_chars_result to_chars(char* first, char* last, double value) { static_cast<void>(first); static_cast<void>(last); static_cast<void>(value); return to_chars_result{ }; }
inline to_chars_result to_chars(char* first, char* last, long double value) { static_cast<void>(first); static_cast<void>(last); static_cast<void>(value); return to_chars_result{ }; }
}

#endif // CHARCONV_2021_04_12_
6 changes: 3 additions & 3 deletions examples/chapter16_08/src/util/STL/chrono
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2011 - 2022.
// Copyright Christopher Kormanyos 2011 - 2024.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -575,7 +575,7 @@
static const bool is_steady = false;

// !!! PLATFORM AND OS SPECIFIC IMPLEMENTATION !!!
static time_point now() STL_LOCAL_NOEXCEPT;
static time_point now() noexcept;
};


Expand Down Expand Up @@ -605,7 +605,7 @@
static const bool is_steady = true;

// !!! PLATFORM AND OS SPECIFIC IMPLEMENTATION !!!
static time_point now() STL_LOCAL_NOEXCEPT;
static time_point now() noexcept;
};


Expand Down
15 changes: 15 additions & 0 deletions examples/chapter16_08/src/util/STL/ciso646
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2023.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef CISO646_2023_08_15
#define CISO646_2023_08_15

// Implement some of <ciso646> for compilers that do not yet support it.

#include <iso646.h>

#endif // CISO646_2023_08_15
Loading

0 comments on commit 8695f65

Please sign in to comment.