亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 高精度浮點數.c

?? 一個通用的高精度浮點數算法的實現,可以學習一下.
?? C
?? 第 1 頁 / 共 3 頁
字號:


void TLargeFloat::RevSqrt()//
{
    //求1/a^0.5,
    // 則有a=1/x^2;  y=a-1/x^2;
    // 求導得y'=2/x^3;
    // 代入牛頓方程 x(n+1)=x(n)-y(x(n))/y'(x(n));
    // 有迭代式 x_next=(3-a*x*x)*x/2; //可證明:該公式為2階收斂公式
 // 證明略
    ExpInt sqrExponent=m_Exponent.AsInt()/2;
    m_Exponent-=sqrExponent;
    m_Exponent-=sqrExponent;

    SelfType& a=*this;

    SelfType x(a);
  long double fx=x.AsFloat();
 if (fx<=0) throw TException("ERROR:TLargeFloat::RevSqrt()");
 x=1.0/sqrt(fx);//初始迭代值
    
    SelfType temp(0.0,TLargeFloat::TDigits(x.GetDigitsLength()));
    int size=x.m_Digits.size();
    int n=6;//n用來用來追蹤計算出的有效精度,并防止死循環
    while (true)
    {
        temp=(3-a*x*x)*x/2;
  if (temp.Compare(x)==0) break;
        x=temp;

  if (n>size) break;
  n*=2;//2階收斂公式
    }
    x.m_Exponent-=sqrExponent;
    swap(x);
    
}

void TLargeFloat::Sqrt() //求x^0.5;
{
    SelfType x(*this);
    x.RevSqrt();
    (*this)*=x;
}

void TLargeFloat::ArrayMUL(const Int32bit* x,const Int32bit* y,Int32bit* result, unsigned int MulSize)
{

 //沒有優化 

 for (int k=0;k<MulSize*2;++k) result[k]=0;

    for (int i=0;i<int(MulSize);++i)
    {
        if (x[i]>0)
        {
            for (int j=0;j<int(MulSize);++j)
            {
                int index=i+j;
                result[index]+=(x[i]*y[j]);
            }
            for (int k=MulSize*2-1;k>=1;--k)
            {
                if (result[k]>=emBase)
                {
                    result[k-1]+=result[k]/emBase;
                    result[k]=result[k] % emBase;
                }
            }
        }
    }
}

void TLargeFloat::MulInt(TMaxInt iValue)//乘以一個整數
{
 if (iValue==0) 
 {
  Clear();
  return;
 }
 else if (iValue<0)
 {
  iValue=-iValue;
  this->Chs();
  //continue
 }

 Int32bit iValueLow=Int32bit(iValue % emBase);
 TMaxInt iValueHigh=iValue / emBase;

 TLargeFloat temp(*this);

 int size=m_Digits.size();
 for (int i=size-1;i>=0;--i)
 {
  m_Digits[i]*=iValueLow;
 }
 for (int j=size-1;j>=1;--j)
 {
  if (m_Digits[j]>emBase)
  {
   m_Digits[j-1]+=m_Digits[j]/emBase;
   m_Digits[j]%=emBase;
  }
 }
 Canonicity();

 if (iValueHigh!=0)
 {
  temp.m_Exponent+=em10Power;
  temp.MulInt(iValueHigh);//遞歸
  (*this)+=temp;
 }
}

void TLargeFloat::DivInt(TMaxInt iValue)//除以一個整數
{
 if (iValue==0) 
 {
  throw TException("ERROR:TLargeFloat::DivInt()");
 }
 else if (iValue<0)
 {
  iValue=-iValue;
  this->Chs();
  //continue
 }

 if (iValue<=emBase)
 {
  Int32bit iDiv=Int32bit(iValue);
  int size=m_Digits.size();
  for (int i=0;i<size-1;++i)
  {
   m_Digits[i+1]+=(m_Digits[i]%iDiv)*emBase;
   m_Digits[i]/=iDiv;
  }
  if (size>=1)
   m_Digits[size-1]/=iDiv;
  Canonicity();
 }
 else
 {
  int size=m_Digits.size();
  TMaxInt HighData=0;
  for (int i=0;i<size-1;++i)
  {
   TMaxInt tempData=(HighData*emBase+m_Digits[i])%iValue;
   m_Digits[i]=Int32bit((HighData*emBase+m_Digits[i])/iValue);
   HighData=tempData;
  }
  if (size>=1)
   m_Digits[size-1]=Int32bit((HighData*emBase+m_Digits[size-1])/iValue);
  Canonicity();
 }

}


const TLargeFloat operator + (const TLargeFloat& x,const TLargeFloat& y)
{
 TLargeFloat temp(x);
 return temp+=y;
}

 const TLargeFloat operator - (const TLargeFloat& x,const TLargeFloat& y)
{
 TLargeFloat temp(x);
 return temp-=y;
}
 const TLargeFloat operator * (const TLargeFloat& x,const TLargeFloat& y)
{
 TLargeFloat temp(x);
 return temp*=y;
}
 const TLargeFloat operator / (const TLargeFloat& x,const TLargeFloat& y)
{
 TLargeFloat temp(x);
 return temp/=y;
}


 const TLargeFloat::SelfType TLargeFloat::operator -  () const//求負
{
 SelfType temp(*this);
 temp.Chs();
 return temp;
}

 const TLargeFloat::SelfType& TLargeFloat::operator +  () const//求正
{
 return *this;
}

TLargeFloat::SelfType& TLargeFloat::operator *= (long double  fValue)
{
 if (!FloatIsInteger(fValue))
 {
  TLargeFloat temp(fValue,TCharacter());
  return (*this)*=temp;
 }
 else
 {
  TMaxInt iValue=TMaxInt(floor(fValue));
  MulInt(iValue);
  return *this;
 }
}

TLargeFloat::SelfType& TLargeFloat::operator /= (long double  fValue)
{
 if (!FloatIsInteger(fValue))
 {
  TLargeFloat temp(fValue,TCharacter());
  return (*this)/=temp;
 }
 else
 {
  TMaxInt iValue=TMaxInt(floor(fValue));
  DivInt(iValue);
  return *this;
 }
}

 TLargeFloat::SelfType& TLargeFloat::operator += (long double  fValue)
{
 TLargeFloat temp(fValue,TCharacter());
 return (*this)+=temp;
}

 TLargeFloat::SelfType& TLargeFloat::operator -= (long double  fValue)
{
 TLargeFloat temp(fValue,TCharacter());
 return (*this)-=temp;
}

 const TLargeFloat operator + (const TLargeFloat& x,long double y)
{
 TLargeFloat temp(x);
 return temp+=y;
}
 const TLargeFloat operator - (const TLargeFloat& x,long double y)
{
 return x+(-y);
}
 const TLargeFloat operator * (const TLargeFloat& x,long double y)
{
 TLargeFloat temp(x);
 return temp*=y;
}
 const TLargeFloat operator / (const TLargeFloat& x,long double y)
{
 TLargeFloat temp(x);
 return temp/=y;
}
 const TLargeFloat operator + (long double x,const TLargeFloat& y)
{
 return y+x;
}
 const TLargeFloat operator - (long double x,const TLargeFloat& y)
{
 return (-y+x);
}
 const TLargeFloat operator * (long double x,const TLargeFloat& y)
{
 return y*x;
}
 const TLargeFloat operator / (long double x,const TLargeFloat& y)
{
 TLargeFloat temp(y);
 temp.Rev();
 temp*=x;
 return temp;
}

 bool operator ==(const TLargeFloat& x,const TLargeFloat& y)
{
 return (x.Compare(y)==0);
}

 bool operator < (const TLargeFloat& x,const TLargeFloat& y)
{
 return (x.Compare(y)<0);
}

 bool operator ==(const TLargeFloat& x,long double y)
{
 TLargeFloat tempy(y,TLargeFloat::TCharacter());
 return (x==tempy);
}
 bool operator < (const TLargeFloat& x,long double y)
{
 TLargeFloat tempy(y,TLargeFloat::TCharacter());
 return (x<tempy);
}


/////////////////////
//UnitTest
//
namespace Private_UnitTest
{

#define _TestCheck(Value) \
{\
 if (!(Value))\
 {\
  throw TLargeFloatException("UnitTest not pass when Check:\"" #Value "\""); \
 }\
}

#define _TestCheck_Exception(Value,LabLine)/*檢測異常*/ \
{\
 int __TestCheck_Exception_ERROR =0; \
 try\
 {\
  Value; \
 }\
    catch(TLargeFloatException&)\
 {\
  goto ok_lab_##LabLine;\
 } \
 throw TLargeFloatException("_TestCheck_Exception not pass when Check:\"" #Value "\""); \
    ok_lab_##LabLine: ;\
}

void LargeFloat_BaseTest()
{
 TLargeFloat x(0,TLargeFloat::TDigits(100));
 _TestCheck(x==0);
 
 x=1.0e20;
 x=-x;

 TLargeFloat y=x;
 _TestCheck(y==-1.0e20);
 _TestCheck(x==y);

 x=1.0e-4;
 y=1.0e-11;
 TLargeFloat z=x;
 z+=y;
 _TestCheck(z==(x+y));

 z=y-x;
 _TestCheck(z+x==y);

 const long double ttmpld=0.000123454365465454765474;
 x=ttmpld;
 _TestCheck(x==ttmpld);
 _TestCheck(Private_::abs(x.AsFloat()-ttmpld)<1e-10);


 //const __int64 ttmpi64=-1234567891235555;
 const double ttmpi64=-1234567891235555;
 x=ttmpi64;
 _TestCheck(x==ttmpi64);
 _TestCheck(abs(x/ttmpi64-1)<0.00001);
 _TestCheck(abs(x*x-x*ttmpi64)<0.00001);
 _TestCheck(abs(x.AsFloat()-ttmpi64)<0.00001);

 x=-x;
 _TestCheck(x==-ttmpi64);
 x=0.0;
 _TestCheck(0==x);

 const int tmpi=-123;
 x=tmpi;
 _TestCheck(-tmpi==abs(x));
 _TestCheck(tmpi*tmpi==sqr(x));

}

void LargeFloat_TestException()
{
 TLargeFloat  x(-2,TLargeFloat::TDigits(1000));
 TLargeFloat  y(-2,TLargeFloat::TDigits(1000));

 _TestCheck_Exception(sqrt(x),0);
 _TestCheck_Exception(x/0,1);
 _TestCheck_Exception(x/(y=0),2);
 /*
 x=1.1234e300;
 x=x*x;
 _TestCheck_Exception(x.AsFloat(); ,3);

 x=1.1234e150;
 _TestCheck_Exception( for(;;) {x=x*x;} ,4);
 x=1.1234e-200;
 _TestCheck_Exception( for(;;) {x=x*x;} ,5);
  */

 _TestCheck_Exception(TLargeFloat(545,TLargeFloat::TDigits(0)); , 6);

 x=0;
 _TestCheck_Exception( revsqrt(x); ,7);

}

void LargeFloat_TestCompare()
{
 TLargeFloat  x(-0.3456346e-5,TLargeFloat::TDigits(1000));
 TLargeFloat  y(3.5453,TLargeFloat::TDigits(1000));

 _TestCheck(x!=y);
 _TestCheck(x<y);
 _TestCheck(y>x);

 y=x;
 _TestCheck(x==y);
 _TestCheck(!(x<y));
 _TestCheck(!(y>x));

 _TestCheck(x!=0);
 _TestCheck(x<0);
 _TestCheck(0>x);
 x=123;
 _TestCheck(x==123);
 _TestCheck(!(x<123));
 _TestCheck(!(123>x));
}

void LargeFloat_TestAbs_Add()
{
 //todo:

}

//todo: 其他測試

}//end namespace Private_UnitTest


void LargeFloat_UnitTest()//正確性測試
{
 using namespace Private_UnitTest;

 LargeFloat_BaseTest();
 LargeFloat_TestException();
 LargeFloat_TestCompare();
 LargeFloat_TestAbs_Add();
}

////

//調試輸出
void Debug_toCout(const std::string& strx,const TLargeFloat& x)
{
 std::cout<<strx<<std::endl<<x<<std::endl;
}

//TLargeFloat.cpp
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


main函數,Demo程序
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// LargeFloat.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include "TLargeFloat.h"

int main(int argc, char* argv[])
{
 
 try
 {
  LargeFloat_UnitTest();
  
  TLargeFloat x(0,TLargeFloat::TDigits(100));
  x=1;
  Debug_toCout("1/7:=",x/7);
  
  x=double(123456787654321);// __int64(123456787654321)
  Debug_toCout("123456787654321*123456787654321 := ",x*x);

  x=2;
  Debug_toCout("2^0.5 := ",sqrt(x));

  //test PI
  std::cout<<std::endl;
  x=GetBorweinPI();
  Debug_toCout("PI := ",x);

 }
 catch (const TLargeFloatException& lfe)
 {
  std::cout<<">> LargeFloat運算時發生異常: "<<lfe.what()<<std::endl;
 }
 catch (const std::exception& e)
 {
  std::cout<<">> 異常: "<<e.what()<<std::endl;
 }
 catch (...)
 {
  std::cout<<">> 未知的異常! "<<std::endl;
 }

 std::cout<<std::endl;
 std::cout<<"...end..."<<std::endl;
 char c;
 std::cin>>c;
 return 0; 

}
/////////////////////

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美一区二区三区久本道91| 国产美女av一区二区三区| 天天操天天综合网| 国产精品1024| 欧美一区二区私人影院日本| 国产精品午夜电影| 久久福利资源站| 欧美写真视频网站| 亚洲欧美国产毛片在线| 国产麻豆日韩欧美久久| 欧美自拍偷拍一区| 中文字幕乱码日本亚洲一区二区| 日韩电影一区二区三区四区| 色天使久久综合网天天| 国产女主播视频一区二区| 免费不卡在线观看| 欧美日韩国产小视频在线观看| 国产精品理伦片| 国产99精品在线观看| 精品成人一区二区三区| 日本强好片久久久久久aaa| 欧美在线视频你懂得| 中文字幕一区二区三区四区| 国产福利91精品一区| 欧美一区二区视频免费观看| 亚洲国产精品嫩草影院| 色老汉一区二区三区| 亚洲欧美日韩中文播放| aaa国产一区| 国产精品第五页| 91玉足脚交白嫩脚丫在线播放| 国产精品日产欧美久久久久| 国产成人av电影在线| 国产欧美综合在线观看第十页| 狠狠色狠狠色综合系列| 欧美成人三级电影在线| 久草在线在线精品观看| 精品第一国产综合精品aⅴ| 国产成人自拍网| 久久久久久亚洲综合影院红桃 | 丰满岳乱妇一区二区三区| 精品88久久久久88久久久| 国产自产高清不卡| 国产欧美日产一区| 99久久精品国产一区| 亚洲美女视频一区| 欧美性高清videossexo| 美女在线一区二区| 国产亚洲视频系列| 91日韩精品一区| 亚洲成人在线网站| 26uuu精品一区二区| 成人激情动漫在线观看| 中文字幕日韩一区| 欧美视频一区二区三区四区| 三级不卡在线观看| 国产日韩欧美电影| 日本电影欧美片| 美腿丝袜在线亚洲一区| 欧美激情资源网| 欧美在线观看一区二区| 蜜臀久久久久久久| 国产精品国产三级国产aⅴ入口| 色妹子一区二区| 久久精品国产在热久久| 国产精品乱码一区二区三区软件 | 欧美人牲a欧美精品| 久草精品在线观看| 亚洲女子a中天字幕| 欧美一区二区三区免费在线看| 国产精品99久久久久久似苏梦涵| 亚洲欧美成人一区二区三区| 欧美精品一区二区三区视频| 91麻豆国产福利精品| 六月丁香婷婷久久| 一区二区三区日本| 国产香蕉久久精品综合网| 欧美性大战久久久久久久蜜臀| 国产精品影视网| 亚洲电影一区二区| 中国av一区二区三区| 日韩午夜激情av| 在线亚洲+欧美+日本专区| 国产乱码精品一品二品| 日韩av午夜在线观看| 日韩理论片在线| 国产亚洲欧美色| 制服丝袜成人动漫| 一本久道久久综合中文字幕 | 日韩高清在线不卡| 亚洲男帅同性gay1069| 久久综合久色欧美综合狠狠| 欧美久久久久免费| 91污片在线观看| 成人免费毛片片v| 国内精品不卡在线| 日韩av在线免费观看不卡| 悠悠色在线精品| ...av二区三区久久精品| 久久伊99综合婷婷久久伊| 日韩一区二区三区高清免费看看| 一本色道a无线码一区v| 91网页版在线| 一本色道a无线码一区v| av成人老司机| 99r国产精品| 99久久综合色| 99久久er热在这里只有精品15| 国产精品亚洲人在线观看| 精品无人码麻豆乱码1区2区| 精品一区免费av| 老司机免费视频一区二区| 久久精品国产在热久久| 捆绑调教美女网站视频一区| 麻豆久久久久久久| 精品一区二区三区在线播放视频 | www.成人在线| av日韩在线网站| 91在线观看污| 99精品偷自拍| 一本大道久久a久久综合婷婷 | 亚洲一区在线观看免费观看电影高清 | 亚洲精品美腿丝袜| 一区二区三区中文免费| 一区二区视频免费在线观看| 一二三区精品视频| 丝袜a∨在线一区二区三区不卡| 天堂久久一区二区三区| 麻豆精品新av中文字幕| 黄色精品一二区| av在线一区二区| 欧美性极品少妇| 精品国产3级a| 亚洲少妇屁股交4| 丝袜亚洲另类欧美| 韩国三级电影一区二区| 成人精品gif动图一区| 色就色 综合激情| 日韩三级免费观看| 国产日韩在线不卡| 亚洲最大成人综合| 久久精品国产99国产精品| kk眼镜猥琐国模调教系列一区二区| 色系网站成人免费| 欧美不卡激情三级在线观看| 国产精品天干天干在观线| 亚洲成人在线网站| 高清在线观看日韩| 欧美视频中文字幕| 国产欧美一区二区精品秋霞影院| 亚洲男女毛片无遮挡| 蜜臀av性久久久久av蜜臀妖精| 国产精品影视网| 欧美丰满少妇xxxxx高潮对白| 国产欧美精品在线观看| 亚洲一区在线观看免费观看电影高清 | 337p亚洲精品色噜噜噜| 亚洲国产精品成人综合| 午夜久久久久久电影| 高清成人在线观看| 69久久99精品久久久久婷婷 | 成人在线综合网| 91精品国产综合久久蜜臀| 国产精品三级电影| 九九热在线视频观看这里只有精品 | 日韩欧美久久久| 亚洲专区一二三| 成人午夜精品一区二区三区| 欧美日韩电影在线播放| 成人欧美一区二区三区在线播放| 日av在线不卡| 欧美日韩综合在线免费观看| 国产精品久久一级| 国产另类ts人妖一区二区| 欧美日韩第一区日日骚| 亚洲精品久久久蜜桃| 粉嫩av亚洲一区二区图片| 精品国产不卡一区二区三区| 日本不卡一二三| 欧美性猛交一区二区三区精品| 中文字幕欧美日韩一区| 国产一区二三区| 日韩欧美高清在线| 视频一区视频二区中文| 欧美日韩国产在线观看| 一区二区三区在线播放| 99久久免费精品| 国产精品二三区| av在线不卡免费看| 国产精品不卡在线观看| 国产·精品毛片| 国产精品久久777777| 不卡视频免费播放| 国产精品九色蝌蚪自拍| 成人aa视频在线观看| 中国av一区二区三区| 波多野结衣中文一区| 国产精品高清亚洲| 成人永久aaa| 一色桃子久久精品亚洲|