📄 sc_unsigned.cpp
字号:
// other cases return div_unsigned_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_UINT64, DIGITS_PER_UINT64, vd); }sc_unsignedoperator/(uint64 u, const sc_unsigned& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) { div_by_zero(v.sgn); // case 1 return sc_unsigned(); // case 2 } CONVERT_INT64_2(u); // other cases return div_unsigned_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.nbits, v.ndigits, v.digit); }sc_unsignedoperator/(const sc_unsigned& u, unsigned long v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) { div_by_zero(v); // case 1 return sc_unsigned(); // case 2 } CONVERT_LONG_2(v); // other cases return div_unsigned_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_ULONG, DIGITS_PER_ULONG, vd); }sc_unsignedoperator/(unsigned long u, const sc_unsigned& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) { div_by_zero(v.sgn); // case 1 return sc_unsigned(); // case 2 } CONVERT_LONG_2(u); // other cases return div_unsigned_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, v.nbits, v.ndigits, v.digit); }// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------// SECTION: MOD operators: %, %=.// ----------------------------------------------------------------------------// Cases to consider when finding the remainder r = u % v:// Note that u = q * v + r for r < q.// 1. 0 % 0 or u % 0 => error// 2. 0 % v => 0 = 0 * v + 0// 3. u % v && u = v => u = 1 * u + 0 - u or v can be 1 or -1// 4. u % v && u < v => u = 0 * v + u - u can be 1 or -1// 5. u % v && u > v => u = q * v + r - v can be 1 or -1sc_unsignedoperator%(const sc_unsigned& u, const sc_unsigned& v){ if ((u.sgn == SC_ZERO) || (v.sgn == SC_ZERO)) { div_by_zero(v.sgn); // case 1 return sc_unsigned(); // case 2 } // other cases return mod_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, v.nbits, v.ndigits, v.digit);}sc_unsignedoperator%(const sc_unsigned& u, uint64 v){ if ((u.sgn == SC_ZERO) || (v == 0)) { div_by_zero(v); // case 1 return sc_unsigned(); // case 2 } CONVERT_INT64_2(v); // other cases return mod_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_unsignedoperator%(uint64 u, const sc_unsigned& v){ if ((u == 0) || (v.sgn == SC_ZERO)) { div_by_zero(v.sgn); // case 1 return sc_unsigned(); // case 2 } CONVERT_INT64(u); // other cases return mod_unsigned_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.nbits, v.ndigits, v.digit);}sc_unsignedoperator%(const sc_unsigned& u, unsigned long v){ if ((u.sgn == SC_ZERO) || (v == 0)) { div_by_zero(v); // case 1 return sc_unsigned(); // case 2 } CONVERT_LONG_2(v); // other cases return mod_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_unsignedoperator%(unsigned long u, const sc_unsigned& v){ if ((u == 0) || (v.sgn == SC_ZERO)) { div_by_zero(v.sgn); // case 1 return sc_unsigned(); // case 2 } CONVERT_LONG(u); // other cases return mod_unsigned_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, v.nbits, v.ndigits, v.digit);}// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------// SECTION: Bitwise AND operators: &, &=// ----------------------------------------------------------------------------// Cases to consider when computing u & v:// 1. u & 0 = 0 & v = 0// 2. u & v => sgn = +// 3. (-u) & (-v) => sgn = -// 4. u & (-v) => sgn = +// 5. (-u) & v => sgn = +sc_unsignedoperator&(const sc_unsigned& u, const sc_unsigned& v){ if ((u.sgn == SC_ZERO) || (v.sgn == SC_ZERO)) // case 1 return sc_unsigned(); // other cases return and_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, v.sgn, v.nbits, v.ndigits, v.digit);}sc_unsignedoperator&(const sc_unsigned& u, uint64 v){ if ((u.sgn == SC_ZERO) || (v == 0)) // case 1 return sc_unsigned(); CONVERT_INT64(v); // other cases return and_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd); }sc_unsignedoperator&(uint64 u, const sc_unsigned& v){ if ((u == 0) || (v.sgn == SC_ZERO)) // case 1 return sc_unsigned(); CONVERT_INT64(u); // other cases return and_unsigned_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.sgn, v.nbits, v.ndigits, v.digit);}sc_unsignedoperator&(const sc_unsigned& u, unsigned long v){ if ((u.sgn == SC_ZERO) || (v == 0)) // case 1 return sc_unsigned(); CONVERT_LONG(v); // other cases return and_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_unsignedoperator&(unsigned long u, const sc_unsigned& v){ if ((u == 0) || (v.sgn == SC_ZERO)) // case 1 return sc_unsigned(); CONVERT_LONG(u); // other cases return and_unsigned_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, v.sgn, v.nbits, v.ndigits, v.digit);}// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------// SECTION: Bitwise OR operators: |, |=// ----------------------------------------------------------------------------// Cases to consider when computing u | v:// 1. u | 0 = u// 2. 0 | v = v// 3. u | v => sgn = +// 4. (-u) | (-v) => sgn = -// 5. u | (-v) => sgn = -// 6. (-u) | v => sgn = -sc_unsignedoperator|(const sc_unsigned& u, const sc_unsigned& v){ if (v.sgn == SC_ZERO) // case 1 return sc_unsigned(u); if (u.sgn == SC_ZERO) // case 2 return sc_unsigned(v); // other cases return or_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, v.sgn, v.nbits, v.ndigits, v.digit);}sc_unsignedoperator|(const sc_unsigned& u, uint64 v){ if (v == 0) // case 1 return sc_unsigned(u); CONVERT_INT64(v); if (u.sgn == SC_ZERO) // case 2 return sc_unsigned(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false); // other cases return or_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_unsignedoperator|(uint64 u, const sc_unsigned& v){ if (u == 0) return sc_unsigned(v); CONVERT_INT64(u); if (v.sgn == SC_ZERO) return sc_unsigned(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false); // other cases return or_unsigned_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.sgn, v.nbits, v.ndigits, v.digit);}sc_unsignedoperator|(const sc_unsigned& u, unsigned long v){ if (v == 0) // case 1 return sc_unsigned(u); CONVERT_LONG(v); if (u.sgn == SC_ZERO) // case 2 return sc_unsigned(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false); // other cases return or_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_unsignedoperator|(unsigned long u, const sc_unsigned& v){ if (u == 0) return sc_unsigned(v); CONVERT_LONG(u); if (v.sgn == SC_ZERO) return sc_unsigned(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false); // other cases return or_unsigned_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, v.sgn, v.nbits, v.ndigits, v.digit);}// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------// SECTION: Bitwise XOR operators: ^, ^=// ----------------------------------------------------------------------------// Cases to consider when computing u ^ v:// Note that u ^ v = (~u & v) | (u & ~v).// 1. u ^ 0 = u// 2. 0 ^ v = v// 3. u ^ v => sgn = +// 4. (-u) ^ (-v) => sgn = -// 5. u ^ (-v) => sgn = -// 6. (-u) ^ v => sgn = +sc_unsignedoperator^(const sc_unsigned& u, const sc_unsigned& v){ if (v.sgn == SC_ZERO) // case 1 return sc_unsigned(u); if (u.sgn == SC_ZERO) // case 2 return sc_unsigned(v); // other cases return xor_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, v.sgn, v.nbits, v.ndigits, v.digit);}sc_unsignedoperator^(const sc_unsigned& u, uint64 v){ if (v == 0) // case 1 return sc_unsigned(u); CONVERT_INT64(v); if (u.sgn == SC_ZERO) // case 2 return sc_unsigned(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false); // other cases return xor_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_unsignedoperator^(uint64 u, const sc_unsigned& v){ if (u == 0) return sc_unsigned(v); CONVERT_INT64(u); if (v.sgn == SC_ZERO) return sc_unsigned(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false); // other cases return xor_unsigned_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.sgn, v.nbits, v.ndigits, v.digit);}sc_unsignedoperator^(const sc_unsigned& u, unsigned long v){ if (v == 0) // case 1 return sc_unsigned(u); CONVERT_LONG(v); if (u.sgn == SC_ZERO) // case 2 return sc_unsigned(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false); // other cases return xor_unsigned_friend(u.sgn, u.nbits, u.ndigits, u.digit, vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_unsignedoperator^(unsigned long u, const sc_unsigned& v){ if (u == 0) return sc_unsigned(v); CONVERT_LONG(u); if (v.sgn == SC_ZERO) return sc_unsigned(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false); // other cases return xor_unsigned_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, v.sgn, v.nbits, v.ndigits, v.digit);}// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------// SECTION: Bitwise NOT operator: ~// ----------------------------------------------------------------------------// Operators in this section are included from sc_nbcommon.cpp.// ----------------------------------------------------------------------------// SECTION: LEFT SHIFT operators: <<, <<=// ----------------------------------------------------------------------------sc_unsignedoperator<<(const sc_unsigned& u, const sc_signed& v){ if ((v.sgn == SC_ZERO) || (v.sgn == SC_NEG)) return sc_unsigned(u); return operator<<(u, v.to_ulong());}// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------// SECTION: RIGHT SHIFT operators: >>, >>=// ----------------------------------------------------------------------------sc_unsignedoperator>>(const sc_unsigned& u, const sc_signed& v){ if ((v.sgn == SC_ZERO) || (v.sgn == SC_NEG)) return sc_unsigned(u); return operator>>(u, v.to_long());}// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------// SECTION: Unary arithmetic operators.// ----------------------------------------------------------------------------sc_unsignedoperator+(const sc_unsigned& u){ return sc_unsigned(u);}// ----------------------------------------------------------------------------// SECTION: EQUAL operator: ==// ----------------------------------------------------------------------------bool
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -