Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Oct 28, 2023
1 parent 56d115b commit 682768f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions parts/header_file/files/elc/_files/base_defs/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ namespace math{
size_t m=exλ{
size_t m1=x.size_in_base_type(),m2=y.size_in_base_type();
if(m1>m2)
x = x>>((m1-m2)*bitnum_of(T::base_type));
x = x.right_shift_in_base_type(m1-m2);
//else if(m1<m2):不可能,因为x≥y
return m2;
}();
Expand All @@ -949,7 +949,7 @@ namespace math{
do{
while(x && y) {//外循环
--m;//提高精度
T a = x >> (m * bitnum_of(T::base_type)), b = y >> (m * bitnum_of(T::base_type));//取最显著数位
T a = x.right_shift_in_base_type(m), b = y.right_shift_in_base_type(m);//取最显著数位
/*初始化矩阵[A B a]为扩展的同一矩阵[1 0 a]
[C D b] [0 1 b]
*/
Expand Down
37 changes: 37 additions & 0 deletions parts/header_file/files/elc/_files/bignum/bignum/ubigint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,25 @@ class ubigint{
else
return fast_divmod_base(a_view,b_view);
}
//left_shift_in_base_type
template<integer_type T>
[[nodiscard]]ubigint left_shift_in_base_type(T n)const&noexcept{
if constexpr(signed_type<T>){
if(is_negative(n))return right_shift_in_base_type(abs(n));
else return left_shift_in_base_type(abs(n));
}
else{
if(!*this)return ubigint{};
const auto oldsize=_data.size();
const auto newsize_diff=to_size_t(n);
const auto newsize=oldsize+newsize_diff;
data_type aret{note::size(newsize)};
if(newsize_diff)
copy_assign[newsize_diff](note::to(aret.data()),base_type{0});
copy_assign[oldsize](aret.data()+newsize_diff,_data.data());
return ubigint{move(aret)};
}
}
//operator<<
template<integer_type T>
[[nodiscard]]ubigint operator<<(T n)const&noexcept{
Expand Down Expand Up @@ -952,6 +971,24 @@ class ubigint{
return ubigint{move(aret)};
}
}
//right_shift_in_base_type
template<integer_type T>
[[nodiscard]]ubigint right_shift_in_base_type(T n)const&noexcept{
if constexpr(signed_type<T>){
if(is_negative(n))return left_shift_in_base_type(abs(n));
else return right_shift_in_base_type(abs(n));
}
else{
if(!*this)return ubigint{};
const auto oldsize=_data.size();
const auto newsize_diff=to_size_t(n);
const auto newsize=oldsize-newsize_diff;
if(newsize_diff>=oldsize)return ubigint{};
data_type aret{note::size(newsize)};
copy_assign[newsize](aret.data(),_data.data()+newsize_diff);
return ubigint{move(aret)};
}
}
//operator>>
template<integer_type T>
[[nodiscard]]ubigint operator>>(T n)const&noexcept{
Expand Down

0 comments on commit 682768f

Please sign in to comment.