制作一個(gè)小的C ++大型精度類,一切似乎工作得體,但添加,如果我一起添加0xffffffff和0x04我得到0xffff0003當(dāng)我應(yīng)該得到0x0100000003。這是問題的功能:mpfl operator+(const mpfl &lhs, const mpfl &rhs){ unsigned long i; mpfl ret(0); mpfl trhs(rhs); for (i = lhs.nbytes; i >= 0; i--) { if ( (unsigned short)lhs.data[i].data + (unsigned short)trhs.data[i].data > (unsigned short)255 ) { if (i > 0) { ret.data[i].carry = 1; ret.data[0].carry = 0; } else { ret.data[0].carry = 1; } } else ret.data[i].carry = 0; ret.data[i].data = lhs.data[i].data + trhs.data[i].data; if (i < lhs.nbytes) { if (ret.data[i].data == 255 && ret.data[i + 1].carry == 1) increment(&trhs, i + 1); ret.data[i].data += ret.data[i + 1].carry; } if (i == 0) break; } return ret;}這里是完整源代碼的鏈接(github使這更容易,因?yàn)樗泻芏啵?biāo)題:https://github.com/phyrrus9/mpfl/blob/master/mpfl.hclass:https://github.com/phyrrus9/mpfl/blob/master/mpfl.cpp驅(qū)動(dòng)程序:https://github.com/phyrrus9/mpfl/blob/master/main.cpp
不能通過攜帶來傳播價(jià)值
梵蒂岡之花
2019-09-06 16:40:35