📄 sc_signed.cpp
字号:
return sc_signed(u); CONVERT_LONG(v); if (u.sgn == SC_ZERO) // case 2 return sc_signed(-vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false); // cases 3 and 4 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit, -vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_signedoperator-(unsigned long u, const sc_signed& v){ if (u == 0) // case 1 return sc_signed(v, -v.sgn); CONVERT_LONG(u); if (v.sgn == SC_ZERO) // case 2 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false); // cases 3 and 4 return add_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, -v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator-(const sc_unsigned &u, unsigned long v){ if (v == 0) // case 1 return sc_signed(u); CONVERT_LONG(v); if (u.sgn == SC_ZERO) // case 2 return sc_signed(-vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false); // cases 3 and 4 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit, -vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_signedoperator-(unsigned long u, const sc_unsigned& v){ if (u == 0) // case 1 return sc_signed(v, -v.sgn); CONVERT_LONG(u); if (v.sgn == SC_ZERO) // case 2 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false); // cases 3 and 4 return add_signed_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: MULTIPLICATION operators: *, *=// ----------------------------------------------------------------------------// Cases to consider when computing u * v:// 1. u * 0 = 0 * v = 0// 2. 1 * v = v and -1 * v = -v// 3. u * 1 = u and u * -1 = -u// 4. u * v = u * vsc_signedoperator*(const sc_unsigned& u, const sc_signed& v){ small_type s = mul_signs(u.sgn, v.sgn); if (s == SC_ZERO) // case 1 return sc_signed(); // cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, v.nbits, v.ndigits, v.digit);}sc_signedoperator*(const sc_signed& u, const sc_unsigned& v){ small_type s = mul_signs(u.sgn, v.sgn); if (s == SC_ZERO) // case 1 return sc_signed(); // cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, v.nbits, v.ndigits, v.digit);}sc_signedoperator*(const sc_signed& u, const sc_signed& v){ small_type s = mul_signs(u.sgn, v.sgn); if (s == SC_ZERO) // case 1 return sc_signed(); // cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, v.nbits, v.ndigits, v.digit);}sc_signedoperator*(const sc_signed& u, int64 v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_INT64_2(v); // cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_UINT64, DIGITS_PER_UINT64, vd); }sc_signedoperator*(int64 u, const sc_signed& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_INT64_2(u); // cases 2-4 return mul_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.nbits, v.ndigits, v.digit); }sc_signedoperator*(const sc_unsigned& u, int64 v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_INT64_2(v); // cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_UINT64, DIGITS_PER_UINT64, vd); }sc_signedoperator*(int64 u, const sc_unsigned& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_INT64_2(u); // cases 2-4 return mul_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.nbits, v.ndigits, v.digit); }sc_signedoperator*(const sc_signed& u, uint64 v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_INT64_2(v); // cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_UINT64, DIGITS_PER_UINT64, vd); }sc_signedoperator*(uint64 u, const sc_signed& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_INT64_2(u); // cases 2-4 return mul_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.nbits, v.ndigits, v.digit); }sc_signedoperator*(const sc_signed& u, long v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_LONG_2(v); // cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_ULONG, DIGITS_PER_ULONG, vd); }sc_signedoperator*(long u, const sc_signed& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_LONG_2(u); // cases 2-4 return mul_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, v.nbits, v.ndigits, v.digit); }sc_signedoperator*(const sc_unsigned& u, long v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_LONG_2(v); // cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_ULONG, DIGITS_PER_ULONG, vd); }sc_signedoperator*(long u, const sc_unsigned& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_LONG_2(u); // cases 2-4 return mul_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, v.nbits, v.ndigits, v.digit); }sc_signedoperator*(const sc_signed& u, unsigned long v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_LONG_2(v); // else cases 2-4 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_ULONG, DIGITS_PER_ULONG, vd); }sc_signedoperator*(unsigned long u, const sc_signed& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) // case 1 return sc_signed(); CONVERT_LONG_2(u); // cases 2-4 return mul_signed_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: DIVISION operators: /, /=// ----------------------------------------------------------------------------// Cases to consider when finding the quotient q = floor(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_signedoperator/(const sc_unsigned& u, const sc_signed& v){ small_type s = mul_signs(u.sgn, v.sgn); if (s == SC_ZERO) { div_by_zero(v.sgn); // case 1 return sc_signed(); // case 2 } // other cases return div_signed_friend(s, u.nbits, u.ndigits, u.digit, v.nbits, v.ndigits, v.digit);}sc_signedoperator/(const sc_signed& u, const sc_unsigned& v){ small_type s = mul_signs(u.sgn, v.sgn); if (s == SC_ZERO) { div_by_zero(v.sgn); // case 1 return sc_signed(); // case 2 } // other cases return div_signed_friend(s, u.nbits, u.ndigits, u.digit, v.nbits, v.ndigits, v.digit);}sc_signedoperator/(const sc_signed& u, const sc_signed& v){ small_type s = mul_signs(u.sgn, v.sgn); if (s == SC_ZERO) { div_by_zero(v.sgn); // case 1 return sc_signed(); // case 2 } // other cases return div_signed_friend(s, u.nbits, u.ndigits, u.digit, v.nbits, v.ndigits, v.digit);}sc_signedoperator/(const sc_signed& u, int64 v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) { div_by_zero(v); // case 1 return sc_signed(); // case 2 } CONVERT_INT64_2(v); // other cases return div_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_UINT64, DIGITS_PER_UINT64, vd); }sc_signedoperator/(int64 u, const sc_signed& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) { div_by_zero(v.sgn); // case 1 return sc_signed(); // case 2 } CONVERT_INT64_2(u); // other cases return div_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.nbits, v.ndigits, v.digit); }sc_signedoperator/(const sc_unsigned& u, int64 v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) { div_by_zero(v); // case 1 return sc_signed(); // case 2 } CONVERT_INT64_2(v); // other cases return div_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_UINT64, DIGITS_PER_UINT64, vd); }sc_signedoperator/(int64 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_signed(); // case 2 } CONVERT_INT64_2(u); // other cases return div_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.nbits, v.ndigits, v.digit); }sc_signedoperator/(const sc_signed& u, uint64 v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) { div_by_zero(v); // case 1 return sc_signed(); // case 2 } CONVERT_INT64_2(v); // other cases return div_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_UINT64, DIGITS_PER_UINT64, vd); }sc_signedoperator/(uint64 u, const sc_signed& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) { div_by_zero(v.sgn); // case 1 return sc_signed(); // case 2 } CONVERT_INT64_2(u); // other cases return div_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, v.nbits, v.ndigits, v.digit); }sc_signedoperator/(const sc_signed& u, long v){ small_type s = mul_signs(u.sgn, get_sign(v)); if (s == SC_ZERO) { div_by_zero(v); // case 1 return sc_signed(); // case 2 } CONVERT_LONG_2(v); // other cases return div_signed_friend(s, u.nbits, u.ndigits, u.digit, BITS_PER_ULONG, DIGITS_PER_ULONG, vd); }sc_signedoperator/(long u, const sc_signed& v){ small_type s = mul_signs(v.sgn, get_sign(u)); if (s == SC_ZERO) { div_by_zero(v.sgn); // case 1 return sc_signed(); // case 2 } CONVERT_LONG_2(u); // other cases return div_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, v.nbits, v.ndigits, v.digit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -