Type checks and destructor added

This commit is contained in:
Ashish Bhanu Daulatabad 2021-04-11 00:01:01 +05:30
parent 2001c91cd4
commit 6c4fdc53d1
3 changed files with 17 additions and 6 deletions

View File

@ -91,8 +91,8 @@ uint256_t exp(uint256_t number, uint256_t power, const uint256_t &mod) {
* @return the resultant point
*/
Point addition(Point a, Point b, uint256_t curve_a_coeff, uint256_t mod) {
uint256_t lambda; /// Slope
uint256_t zero; /// value zero
uint256_t lambda(0); /// Slope
uint256_t zero(0); /// value zero
lambda = zero = 0;
uint256_t inf = ~zero;
if (a.x != b.x || a.y != b.y) {

View File

@ -37,8 +37,9 @@ struct std::is_unsigned<uint128_t> : std::true_type {};
std::string add(const std::string &first, const std::string &second) {
std::string third;
int16_t sum = 0, carry = 0;
for (int i = first.size() - 1, j = second.size() - 1; i >= 0 || j >= 0;
--i, --j) {
for (int32_t i = static_cast<int32_t>(first.size()) - 1,
j = static_cast<int32_t>(second.size()) - 1;
i >= 0 || j >= 0; --i, --j) {
sum = ((i >= 0 ? first[i] - '0' : 0) + (j >= 0 ? second[j] - '0' : 0) +
carry);
carry = sum / 10;
@ -125,6 +126,11 @@ class uint128_t {
*/
uint128_t(uint128_t &&num) : f(std::move(num.f)), s(std::move(num.s)) {}
/**
* @brief Destructor for uint128_t
*/
~uint128_t() = default;
/**
* @brief Leading zeroes in binary
* @details Calculates leading zeros in 128-bit integer
@ -632,7 +638,7 @@ class uint128_t {
if (!p) {
return uint128_t(f, s);
}
if (p >= 64) {
if (p >= 64 && p <= 128) {
return uint128_t((this->s << (p - 64)), 0);
}
return uint128_t((this->f << p) + ((this->s >> (64 - p))),

View File

@ -1,5 +1,5 @@
/**
* @file uint128_t.hpp
* @file uint256_t.hpp
*
* @details Implementation of 256-bit unsigned integers.
* @note The implementation can be flagged as not completed. This header is used
@ -103,6 +103,11 @@ class uint256_t {
*/
uint256_t(const uint64_t high, const uint64_t low) : f(high), s(low) {}
/**
* @brief Destructor for uint256_t
*/
~uint256_t() = default;
/**
* @brief Leading zeroes in binary
* @details Calculates leading zeros in 256-bit integer