高精度四則運算(萬進(jìn)制)C++_第1頁
高精度四則運算(萬進(jìn)制)C++_第2頁
高精度四則運算(萬進(jìn)制)C++_第3頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、C+C+版By小貝壓位高精萬進(jìn)制/頭文件:thp.h #ifndef_cstring_#define _cstring_ #include#endif#ifndef_cstdlib_#define _cstdlib_ #include#endifconst int THP_MAXLEN=1000; const int THP_MAXSTRLEN=4040;constintL0=10000;classthpfriend const thp operator-(const thp&,const thp&); friend const thp operator+(const thp&,const t

2、hp&); friend const thp operator*(const thp&,const thp&); friend const thp operator/(const thp&,const thp&); friend void thpdiv(const thp&,const thp&,thp&,thp&);friend const thp operator%(const thp&,const thp&); public:const thp& operator=(const thp&); const thp& operator=(const char*);bool operator=

3、(const thp&)const;bool operator=(const thp&)const;booloperator(constthp&)const;bool operator(const thp&)const;inlinevoidshl(constint);const thp& operator + ;inline void makeempty; constchar*tostrconst;inlinethp& operator-=(const thp&);thp;thp(const char*); constintthpstd;protected:int_dataTHP_MAXLEN

4、,_high,_sign;private:;/源代碼 thp.cpp#include“thp.h“constintinti;thp:thpstdfor(i=0;i=_high;i+)while(_datai=L0)this-thpstd;return(*this);voidthp:shl(constintn)inti;for(i=_high;i=0;i-)_datai+n=_datai;_high+=n; if(_data_high=0)_high=0;thp&thp:operator-=(constthp&o)int tint,i,len; for(i=0;i=_high;i+)tint=_

5、datai-o._datai;if(tint_high;len=0;len-)if(_datalen!=0)break;if(len=0)break;_high=len; return(*this);voidthpdiv(constthp&a,constthp&b,thp&c,thp&d)inti;d.makeempty; c.makeempty; for(i=a._high;i=0;i-)d.shl(1);d._data0=a._datai;while(b0;i-)if(c._datai!=0)c._high=i;break;inlineboolthp:operator!=(constthp

6、&o)constreturn(!(0=memcmp(this,&o,sizeof(thp);boolthp:operator=(constthp&o)constreturn(0=memcmp(this,&o,sizeof(thp);inlineboolthp:operator_high!=o._high)return(this-_high_high;i=0;i-)if(this-_datai!=o._datai)return(this-_datai(constthp&o)constif(*this=o)return(false);return(!(*thiso);boolthp:operato

7、r=(constthp&o)constreturn(*this=(constthp&o)constreturn(!(*thisb?a:b);thp:thpmakeempty;thp:thp(constchar*s)*this=s;constthpoperator-(constthp&a,constthp&b)int i,len,tint;thpre;len=max(a._high,b._high);for(i=0;i=len;i+)tint=a._datai-b._datai+re._datai;if(tint0&re._datalen1)len-;re._high=len;return(re

8、);constthpoperator/(constthp&a,constthp&b)thp re1,re2; thpdiv(a,b,re1,re2);return(re1);constthpoperator*(constthp&a,constthp&b)int i,j,tint,len;thpre;for(i=0;i=a._high;i+)for(j=0;j=b._high;j+)len=i+j;tint=a._datai*b._dataj+re._datai+j;re._datai+j=tint%L0; re._datai+j+1+=tint/L0;if(re._datalen+1!=0)l

9、en+;re._high=len;return(re);constthpoperator+(constthp&a,constthp&b)inti,len,tint;thp re; len=max(a._high,b._high);for(i=0;i=0;i-)tint=_datai; for(j=0;j1&*re=”0”)re+;return(re);inlinevoidthp:makeemptymemset(this,0,sizeof(thp);constthp&thp:operator=(constchar*s)char ts5; memset(ts,0,sizeof(ts);intlen

10、,i;makeempty;len=strlen(s);_high=(len-1)/4;i=(len-1)%4+1;strncpy(ts,s,i);s+=i;_data_high=atoi(ts);i=_high;while(i0)i-;memset(ts,0,sizeof(ts);strncpy(ts,s,4);s+=4;_datai=atoi(ts);return(*this);constthp&thp:operator=(constthp&hp)memcpy(this,&hp,sizeof(thp);return(*this);/cpp.cpp#ifndef_iostream_#defin

11、e _iostream_ #include#endif#ifndef_ctime_#define _ctime_ #include#endif#ifndef_conio_h_#define _conio_h_ #include#endif#include“thp.h“using std:cout;usingstd:endl;intmainclock_t t1=clock;thpa=“12312312234444444444423444444444444441122222233333333333333333333333333333333333333333334234233333333333333

12、333333333333333333333333333333333333333333333333333333333333333333333332352345345634523423423444449877243523452342342340000000000000000000000000000000000000000000000066666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666

13、666663423423333333333333333333333333333333333333333333333333333333333333333333333333333333333333235234534563452342342344444987724352345234234234000000000000000000000000000000000000000000000006666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666

14、666666666666666666666666666666342342333333333333333333333333333333333333333333333333333333333333333333333333333333333333323523453456345234234234444498772435234523423423400000000000000000000000000000000000000000000000666666666666666666666666666666666666666666666666666666666666666666666666666666666666

15、666666666666666666666666666666666666666666666666666666634234233333333333333333333333333333333333333333333333333333333333333333333333333333333333332352345345634523423423444449877243523452342342340000000000000000000000000000000000000000000000066666666666666666666666666666666666666666666666666666666666

16、666666666666666666666666666666666666666666666666666666666666666666666666666666663423423333333333333333333333333333333333333333333333333333333333333333333333333333333333333235234534563452342342344444987724352345234234234000000000000000000000000000000000000000000000006666666666666666666666666666666666

17、666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666444444444444444444444444444444444444444444444443423452234234342“;thp b=“234234334444444444444444444444444444444444234234234234233423423333333333333333333333333333333333333333333333333333333333333333333333333333333333333235234534563452342342344444987724352345234234234000000000000000000000000000

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論