Skip to content

Commit c1a98a0

Browse files
committed
Change includes order
1 parent b5d28e9 commit c1a98a0

File tree

3 files changed

+79
-70
lines changed

3 files changed

+79
-70
lines changed

include/slimcpplib/long_math.h

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,16 @@ constexpr type_t shr2(type_t value_hi, type_t value_lo, uint_t shift) noexcept;
160160

161161
template<typename type_t, std::enable_if_t<is_unsigned_v<type_t>, int> = 0>
162162
constexpr type_t addc(type_t value1, type_t value2, bool& carry) noexcept;
163-
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int> = 0>
164-
constexpr void add(type_t& value1, const type_t& value2) noexcept;
165163

166164
// subtract with borrow
167165

168166
template<typename type_t, std::enable_if_t<is_unsigned_v<type_t>, int> = 0>
169167
constexpr type_t subb(type_t value1, type_t value2, bool& borrow) noexcept;
170-
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int> = 0>
171-
constexpr void sub(type_t& value1, const type_t& value2) noexcept;
172168

173169
// multiply with carry
174170

175171
template<typename type_t, std::enable_if_t<is_unsigned_v<type_t>, int> = 0>
176172
constexpr type_t mulc(type_t value1, type_t value2, type_t& carry) noexcept;
177-
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int> = 0>
178-
constexpr void mul(type_t& value1, const type_t& value2) noexcept;
179173

180174
// divide with remainder
181175

@@ -311,18 +305,6 @@ constexpr type_t addc(type_t value1, const type_t value2, bool& carry) noexcept
311305

312306

313307

314-
////////////////////////////////////////////////////////////////////////////////////////////////////
315-
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int>>
316-
constexpr void add(type_t& value1, const type_t& value2) noexcept
317-
{
318-
bool carry = false;
319-
320-
for (uint_t n = 0; n < std::size(value1); ++n)
321-
value1[n] = addc(value1[n], value2[n], carry);
322-
}
323-
324-
325-
326308
////////////////////////////////////////////////////////////////////////////////////////////////////
327309
template<typename type_t, std::enable_if_t<is_unsigned_v<type_t>, int>>
328310
constexpr type_t subb(type_t value1, type_t value2, bool& borrow) noexcept
@@ -342,18 +324,6 @@ constexpr type_t subb(type_t value1, type_t value2, bool& borrow) noexcept
342324

343325

344326

345-
////////////////////////////////////////////////////////////////////////////////////////////////////
346-
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int>>
347-
constexpr void sub(type_t& value1, const type_t& value2) noexcept
348-
{
349-
bool borrow = false;
350-
351-
for (uint_t n = 0; n < std::size(value1); ++n)
352-
value1[n] = subb(value1[n], value2[n], borrow);
353-
}
354-
355-
356-
357327
////////////////////////////////////////////////////////////////////////////////////////////////////
358328
template<typename type_t, std::enable_if_t<is_unsigned_v<type_t>, int> = 0>
359329
constexpr type_t mulc_classic(type_t value1, type_t value2, type_t& carry) noexcept
@@ -457,37 +427,6 @@ constexpr type_t mulc(type_t value1, type_t value2, type_t& carry) noexcept
457427

458428

459429

460-
////////////////////////////////////////////////////////////////////////////////////////////////////
461-
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int>>
462-
constexpr void mul(type_t& value1, const type_t& value2) noexcept
463-
{
464-
using value_t = typename type_t::value_type;
465-
value_t carry = 0;
466-
467-
type_t result;
468-
result[0] = mulc(value1[0], value2[0], carry);
469-
470-
for (uint_t n = 1; n < std::size(value1); ++n)
471-
result[n] = mulc(value1[n], value2[0], carry);
472-
473-
for (uint_t n = 1; n < std::size(value1); ++n) {
474-
475-
type_t tmp;
476-
carry = 0;
477-
478-
for (uint_t k = 0; k < n; ++k)
479-
tmp[k] = 0;
480-
for (uint_t k = 0; k < std::size(value1) - n; ++k)
481-
tmp[k + n] = mulc(value1[k], value2[n], carry);
482-
483-
add(result, tmp);
484-
}
485-
486-
value1 = result;
487-
}
488-
489-
490-
491430
////////////////////////////////////////////////////////////////////////////////////////////////////
492431
template<typename type_t, std::enable_if_t<is_unsigned_v<type_t>, int>>
493432
constexpr type_t divr(type_t value1, type_t value2, std::optional<type_t>& remainder) noexcept

include/slimcpplib/long_math_long.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434

3535
#include "long_math.h"
3636

37+
#if __has_include("long_math_gcc.h")
38+
#include "long_math_gcc.h"
39+
#endif // __has_include("long_math_gcc.h")
40+
41+
#if __has_include("long_math_msvc.h")
42+
#include "long_math_msvc.h"
43+
#endif // __has_include("long_math_msvc.h")
44+
45+
3746
namespace slim
3847
{
3948
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -107,6 +116,21 @@ constexpr long_uint_t<type_t, size> mulc(long_uint_t<type_t, size> value1, long_
107116
template<typename type_t, uint_t size>
108117
constexpr long_uint_t<type_t, size> divr(long_uint_t<type_t, size> value1, long_uint_t<type_t, size> value2, std::optional<long_uint_t<type_t, size>>& remainder) noexcept;
109118

119+
// add two vectors
120+
121+
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int> = 0>
122+
constexpr void add(type_t& value1, const type_t& value2) noexcept;
123+
124+
// subtract two vectors
125+
126+
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int> = 0>
127+
constexpr void sub(type_t& value1, const type_t& value2) noexcept;
128+
129+
// multiply two vectors
130+
131+
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int> = 0>
132+
constexpr void mul(type_t& value1, const type_t& value2) noexcept;
133+
110134

111135

112136
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -321,6 +345,61 @@ constexpr long_uint_t<type_t, size> divr(long_uint_t<type_t, size> value1, long_
321345
return quotient;
322346
}
323347

348+
349+
350+
////////////////////////////////////////////////////////////////////////////////////////////////////
351+
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int>>
352+
constexpr void add(type_t& value1, const type_t& value2) noexcept
353+
{
354+
bool carry = false;
355+
356+
for (uint_t n = 0; n < std::size(value1); ++n)
357+
value1[n] = addc(value1[n], value2[n], carry);
358+
}
359+
360+
361+
362+
////////////////////////////////////////////////////////////////////////////////////////////////////
363+
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int>>
364+
constexpr void sub(type_t& value1, const type_t& value2) noexcept
365+
{
366+
bool borrow = false;
367+
368+
for (uint_t n = 0; n < std::size(value1); ++n)
369+
value1[n] = subb(value1[n], value2[n], borrow);
370+
}
371+
372+
373+
374+
////////////////////////////////////////////////////////////////////////////////////////////////////
375+
template<typename type_t, std::enable_if_t<is_unsigned_array_v<type_t>, int>>
376+
constexpr void mul(type_t& value1, const type_t& value2) noexcept
377+
{
378+
using value_t = typename type_t::value_type;
379+
value_t carry = 0;
380+
381+
type_t result;
382+
result[0] = mulc(value1[0], value2[0], carry);
383+
384+
for (uint_t n = 1; n < std::size(value1); ++n)
385+
result[n] = mulc(value1[n], value2[0], carry);
386+
387+
for (uint_t n = 1; n < std::size(value1); ++n) {
388+
389+
type_t tmp;
390+
carry = 0;
391+
392+
for (uint_t k = 0; k < n; ++k)
393+
tmp[k] = 0;
394+
for (uint_t k = 0; k < std::size(value1) - n; ++k)
395+
tmp[k + n] = mulc(value1[k], value2[n], carry);
396+
397+
add(result, tmp);
398+
}
399+
400+
value1 = result;
401+
}
402+
324403
} // namespace slim
325404

326405
////////////////////////////////////////////////////////////////////////////////////////////////////

include/slimcpplib/long_uint.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,8 @@
3232

3333
#pragma once
3434

35-
#include "long_math.h"
3635
#include "long_math_long.h"
3736

38-
#if __has_include("long_math_gcc.h")
39-
#include "long_math_gcc.h"
40-
#endif // __has_include("long_math_gcc.h")
41-
42-
#if __has_include("long_math_msvc.h")
43-
#include "long_math_msvc.h"
44-
#endif // __has_include("long_math_msvc.h")
45-
4637
namespace slim
4738
{
4839
////////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)