Skip to content

Commit

Permalink
more move
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Oct 29, 2023
1 parent 7a07ad8 commit 160ef2a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 53 deletions.
8 changes: 4 additions & 4 deletions parts/header_file/files/elc/_files/bignum/_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ namespace base::math{
//bool:是否是有符号类型
static constexpr bool is_signed = true;
//bool:是否有NaN
static constexpr bool has_NaN = true;
static constexpr bool has_NaN = false;
//bool:是否有inf
static constexpr bool has_inf = false;
static constexpr bool has_inf = true;
//bool:是否有min
static constexpr bool has_min = false;
//bool:是否有max
Expand Down Expand Up @@ -157,9 +157,9 @@ namespace base::math{
//bool:是否是有符号类型
static constexpr bool is_signed = false;
//bool:是否有NaN
static constexpr bool has_NaN = true;
static constexpr bool has_NaN = false;
//bool:是否有inf
static constexpr bool has_inf = false;
static constexpr bool has_inf = true;
//bool:是否有min
static constexpr bool has_min = true;
//min
Expand Down
84 changes: 46 additions & 38 deletions parts/header_file/files/elc/_files/bignum/bignum/bigfloat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ class bigfloat{
[[nodiscard]]friend ubigfloat&& abs(bigfloat&& a)noexcept{
return move(a._num);
}
//friend isNaN
[[nodiscard]]friend constexpr bool isNaN(const bigfloat&)noexcept{
return false;
}
//friend isInf
[[nodiscard]]friend bool isInf(const bigfloat&a)noexcept{
return isInf(a._num);
}
//friend is_negative
[[nodiscard]]friend bool is_negative(const bigfloat& a)noexcept{
return a._is_negative;
Expand Down Expand Up @@ -173,11 +181,11 @@ class bigfloat{
}
//operator+
template<arithmetic_type T>
[[nodiscard]]bigfloat operator+(const T&other)const&noexcept{
[[nodiscard]]bigfloat operator+(T&&other)const&noexcept{
if(_is_negative==is_negative(other))
return bigfloat{_num+abs(other), _is_negative};
return bigfloat{_num+abs(forward<T>(other)), _is_negative};
else{
auto uother=abs(other);
auto uother=abs(forward<T>(other));
if(_num>uother)
return bigfloat{_num-move(uother), _is_negative};
else
Expand All @@ -186,11 +194,11 @@ class bigfloat{
}
//operator-
template<arithmetic_type T>
[[nodiscard]]bigfloat operator-(const T&other)const&noexcept{
[[nodiscard]]bigfloat operator-(T&&other)const&noexcept{
if(_is_negative!=is_negative(other))
return bigfloat{_num+abs(other), _is_negative};
return bigfloat{_num+abs(forward<T>(other)), _is_negative};
else{
auto uother=abs(other);
auto uother=abs(forward<T>(other));
if(_num>uother)
return bigfloat{_num-move(uother), _is_negative};
else
Expand All @@ -199,30 +207,30 @@ class bigfloat{
}
//operator*
template<arithmetic_type T>
[[nodiscard]]bigfloat operator*(const T&other)const&noexcept{
[[nodiscard]]bigfloat operator*(T&&other)const&noexcept{
const bool sign=_is_negative!=is_negative(other);
return bigfloat{_num*abs(other), sign};
return bigfloat{_num*abs(forward<T>(other)), sign};
}
//operator/
template<arithmetic_type T>
[[nodiscard]]bigfloat operator/(const T&other)const&noexcept{
[[nodiscard]]bigfloat operator/(T&&other)const&noexcept{
const bool sign=_is_negative!=is_negative(other);
return bigfloat{_num/abs(other), sign};
return bigfloat{_num/abs(forward<T>(other)), sign};
}
//operator+=
template<unsigned_type T>
bigfloat& operator+=(const T& other)&noexcept{
_num+=other;
bigfloat& operator+=(T&&other)&noexcept{
_num+=forward<T>(other);
return*this;
}
template<arithmetic_type T>
bigfloat& operator+=(const T&other)&noexcept{
bigfloat& operator+=(T&&other)&noexcept{
if(_is_negative==is_negative(other)){
_num+=abs(other);
_num+=abs(forward<T>(other));
return*this;
}
else{
auto uother=abs(other);
auto uother=abs(forward<T>(other));
if(_num>uother){
_num-=move(uother);
return*this;
Expand All @@ -236,9 +244,9 @@ class bigfloat{
}
//operator-=
template<arithmetic_type T>
bigfloat& operator-=(const T&other)&noexcept{
bigfloat& operator-=(T&&other)&noexcept{
if(_is_negative==is_negative(other)){
auto uother=abs(other);
auto uother=abs(forward<T>(other));
if(_num>uother){
_num-=move(uother);
return*this;
Expand All @@ -250,67 +258,67 @@ class bigfloat{
}
}
else{
_num+=abs(other);
_num+=abs(forward<T>(other));
return*this;
}
}
//operator*=
template<unsigned_type T>
bigfloat& operator*=(const T& other)&noexcept{
_num*=other;
bigfloat& operator*=(T&&other)&noexcept{
_num*=forward<T>(other);
return*this;
}
template<arithmetic_type T>
bigfloat& operator*=(const T&other)&noexcept{
bigfloat& operator*=(T&&other)&noexcept{
_is_negative=_is_negative!=is_negative(other);
_num*=abs(other);
_num*=abs(forward<T>(other));
return*this;
}
//operator/=
template<unsigned_type T>
bigfloat& operator/=(const T& other)&noexcept{
_num/=other;
bigfloat& operator/=(T&&other)&noexcept{
_num/=forward<T>(other);
return*this;
}
template<arithmetic_type T>
bigfloat& operator/=(const T&other)&noexcept{
bigfloat& operator/=(T&&other)&noexcept{
_is_negative=_is_negative!=is_negative(other);
_num/=abs(other);
_num/=abs(forward<T>(other));
return*this;
}
//operator==
template<arithmetic_type T>
[[nodiscard]]bool operator==(const T& other)const noexcept{
[[nodiscard]]bool operator==(T&&other)const noexcept{
if(_is_negative!=is_negative(other))return false;
return _num==abs(other);
return _num==abs(forward<T>(other));
}
//operator<=>
template<arithmetic_type T>
[[nodiscard]]auto operator<=>(const T& other)const noexcept{
[[nodiscard]]auto operator<=>(T&&other)const noexcept{
if(_is_negative!=is_negative(other))
return _is_negative?strong_ordering::less:strong_ordering::greater;
const bool needs_reverse=_is_negative;
auto result=_num <=> abs(other);
auto result=_num <=> abs(forward<T>(other));
if(needs_reverse)
result=compare.reverse(result);
return result;
}
//operatorX for rvalue
template<arithmetic_type T>
[[nodiscard]]bigfloat&& operator+(const T& other)&&noexcept{
return move(*this += other);
[[nodiscard]]bigfloat&& operator+(T&&other)&&noexcept{
return move(*this += forward<T>(other));
}
template<arithmetic_type T>
[[nodiscard]]bigfloat&& operator-(const T&other)&&noexcept{
return move(*this -= other);
[[nodiscard]]bigfloat&& operator-(T&&other)&&noexcept{
return move(*this -= forward<T>(other));
}
template<arithmetic_type T>
[[nodiscard]]bigfloat&& operator*(const T&other)&&noexcept{
return move(*this *= other);
[[nodiscard]]bigfloat&& operator*(T&&other)&&noexcept{
return move(*this *= forward<T>(other));
}
template<arithmetic_type T>
[[nodiscard]]bigfloat&& operator/(const T&other)&&noexcept{
return move(*this /= other);
[[nodiscard]]bigfloat&& operator/(T&&other)&&noexcept{
return move(*this /= forward<T>(other));
}
//operator!
[[nodiscard]]bool operator!()const noexcept{
Expand Down
17 changes: 8 additions & 9 deletions parts/header_file/files/elc/_files/bignum/bignum/ubigfloat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ class ubigfloat{
ubigfloat(T num)noexcept{
if(isNaN(num))return;
//将一个浮点类型无损的转换为两个bigint相除
if(isInf(num)){
_numerator = 1u;
_denominator = zero;
return;
}
if(is_negative(num))num = -num;
if constexpr(has_inf<T>)
if(num == arithmetic_type_info_prover<T>::Inf()){
_numerator = 1u;
_denominator = zero;
return;
}
const auto info=get_precision_and_exponent(num);
if(info.exponent<0){//小数,有猜测价值
//优先进行猜测以处理近似的简单分数
Expand Down Expand Up @@ -227,8 +226,8 @@ class ubigfloat{
[[nodiscard]]friend constexpr bool isNaN(const ubigfloat&)noexcept{
return false;
}
//friend isinf
[[nodiscard]]friend bool isinf(const ubigfloat&a)noexcept{
//friend isInf
[[nodiscard]]friend bool isInf(const ubigfloat&a)noexcept{
return!a._denominator;
}
//friend trunc
Expand Down Expand Up @@ -463,7 +462,7 @@ class ubigfloat{
_denominator/=g;
}
//friend simplify
friend decltype(auto) simplify(ubigfloat& a)noexcept{
friend auto& simplify(ubigfloat& a)noexcept{
a.simplify();
return a;
}
Expand Down
4 changes: 2 additions & 2 deletions parts/header_file/files/elc/_files/bignum/bignum/ubigint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,10 +1029,10 @@ class ubigint{
return*this;
}
template<unsigned_basic_integer_type T>
[[nodiscard]]ubigint& operator+(T&&other)&&noexcept{
[[nodiscard]]ubigint&& operator+(T&&other)&&noexcept{
//using add_to_base to avoid new alloc
add_to_base(_data,other);
return*this;
return move(*this);
}
//operator-=
ubigint& operator-=(const ubigint& other)&noexcept{
Expand Down

0 comments on commit 160ef2a

Please sign in to comment.