-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multiprecision: add custom and boost tests and fix bugs
- Loading branch information
Showing
11 changed files
with
2,287 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 119 additions & 81 deletions
200
.../libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/big_uint_impl.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/big_uint/ops/pow.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2019-2021 Aleksei Moskvin <[email protected]> | ||
// Copyright (c) 2020 Mikhail Komarov <[email protected]> | ||
// Copyright (c) 2020 Ilias Khairullin <[email protected]> | ||
// Copyright (c) 2024 Andrey Nefedov <[email protected]> | ||
// | ||
// 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 | ||
//---------------------------------------------------------------------------// | ||
|
||
#pragma once | ||
|
||
// IWYU pragma: private; include "nil/crypto3/multiprecision/big_uint.hpp" | ||
|
||
#include <type_traits> | ||
|
||
#include "nil/crypto3/multiprecision/detail/big_uint/big_uint_impl.hpp" | ||
#include "nil/crypto3/multiprecision/detail/integer_ops_base.hpp" | ||
|
||
namespace nil::crypto3::multiprecision { | ||
template<typename T1, typename T2, | ||
std::enable_if_t<detail::is_integral_v<std::decay_t<T1>> && | ||
detail::is_integral_v<std::decay_t<T2>>, | ||
int> = 0> | ||
constexpr std::decay_t<T1> pow(T1 b, T2 e) { | ||
if (is_zero(e)) { | ||
return 1u; | ||
} | ||
|
||
T1 res = 1u; | ||
|
||
while (true) { | ||
bool lsb = bit_test(e, 0u); | ||
e >>= 1u; | ||
if (lsb) { | ||
res *= b; | ||
if (is_zero(e)) { | ||
break; | ||
} | ||
} | ||
b *= b; | ||
} | ||
|
||
return res; | ||
} | ||
} // namespace nil::crypto3::multiprecision |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
crypto3/libs/multiprecision/include/nil/crypto3/multiprecision/detail/integer_ops_pow.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2024 Andrey Nefedov <[email protected]> | ||
// | ||
// 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 | ||
//---------------------------------------------------------------------------// | ||
|
||
#pragma once | ||
|
||
#include "nil/crypto3/multiprecision/detail/big_uint/ops/pow.hpp" // IWYU pragma: export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.