From 682768f2af6b4ffb4df65567f60a4c0d504ec5a0 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 28 Oct 2023 14:40:33 +0800 Subject: [PATCH] Update --- .../files/elc/_files/base_defs/math.hpp | 4 +- .../elc/_files/bignum/bignum/ubigint.hpp | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/parts/header_file/files/elc/_files/base_defs/math.hpp b/parts/header_file/files/elc/_files/base_defs/math.hpp index 60399387..b07c5942 100644 --- a/parts/header_file/files/elc/_files/base_defs/math.hpp +++ b/parts/header_file/files/elc/_files/base_defs/math.hpp @@ -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> (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] */ diff --git a/parts/header_file/files/elc/_files/bignum/bignum/ubigint.hpp b/parts/header_file/files/elc/_files/bignum/bignum/ubigint.hpp index a6bd65a7..525fdd17 100644 --- a/parts/header_file/files/elc/_files/bignum/bignum/ubigint.hpp +++ b/parts/header_file/files/elc/_files/bignum/bignum/ubigint.hpp @@ -917,6 +917,25 @@ class ubigint{ else return fast_divmod_base(a_view,b_view); } + //left_shift_in_base_type + template + [[nodiscard]]ubigint left_shift_in_base_type(T n)const&noexcept{ + if constexpr(signed_type){ + 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 [[nodiscard]]ubigint operator<<(T n)const&noexcept{ @@ -952,6 +971,24 @@ class ubigint{ return ubigint{move(aret)}; } } + //right_shift_in_base_type + template + [[nodiscard]]ubigint right_shift_in_base_type(T n)const&noexcept{ + if constexpr(signed_type){ + 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 [[nodiscard]]ubigint operator>>(T n)const&noexcept{