当前位置: 首页 > news >正文

东莞网站建设制作免费咨中央电视台一套广告价目表

东莞网站建设制作免费咨,中央电视台一套广告价目表,wordpress 火,手机wap网站制作1.问题:大数计算可能超出数据类型范围 当单独计算 ,因为 ,double的最大取值为1.79769e308,所以 肯定超过了double的表示范围。 同样,对于300!也是如此。 那我们应该怎么去计算和存储结果呢?…

1.问题:大数计算可能超出数据类型范围

当单独计算 e^{1000},因为 e^{1000} > e^{700} \approx 1.01432*e304,double的最大取值为1.79769e+308,所以 e^{1000} 肯定超过了double的表示范围。

同样,对于300!也是如此。

那我们应该怎么去计算和存储结果呢?

2.解决方案

从数学角度出发,对于超级大的数,运算方式、运算规律等肯定保持不变的。

很多时候,我们主要是利用相关的定理、公式进行简化或者极限处理。

由于我项目里的精度要求就 e-10,于是,可以采用相对宽松的方式解决这个问题:

科学计数法!

3.代码实现

#ifndef __BigNumeric_h
#define __BigNumeric_h
#include <cmath>template<typename _T>
class BigNumeric
{
private:_T mantissa;        //基数int exponent;       //指数public:BigNumeric(_T num){if (num == 0) {exponent = 0;mantissa = 0;}else{exponent = std::floor(std::log10(std::abs(num)));mantissa = num / std::pow(10, exponent);}}~BigNumeric(){}BigNumeric(const BigNumeric& other){if (this == &other) return;this->exponent = other.exponent;this->mantissa = other.mantissa;}BigNumeric& operator=(const BigNumeric& other){/*if(this == &other) return *this;*/this->exponent = other.exponent;this->mantissa = other.mantissa;return *this;}public:_T value(){if (this->exponent >= 308) return 0.0;return this->mantissa * std::pow(10.0, this->exponent);}//乘法BigNumeric& operator*(const BigNumeric& opr){BigNumeric<_T> resmnt(this->mantissa * opr.mantissa);this->exponent = resmnt.exponent + this->exponent + opr.exponent;this->mantissa = resmnt.mantissa;return *this;}BigNumeric& operator*(const _T opr){BigNumeric<_T> oprbgn(opr);*this = *this * oprbgn;return *this;}friend    BigNumeric operator*(const _T opr1, BigNumeric& opr2){return opr2 * opr1;}//除法BigNumeric& operator/(const BigNumeric& opr){BigNumeric<_T> resmnt(this->mantissa / opr.mantissa);this->exponent = resmnt.exponent + this->exponent - opr.exponent;this->mantissa = resmnt.mantissa;return *this;}BigNumeric& operator/(const _T opr){BigNumeric<_T> oprbgn(opr);*this = *this / oprbgn;return *this;}friend     BigNumeric operator/(const _T opr, const BigNumeric& opr1){BigNumeric<_T> oprbgn(opr);return oprbgn / opr1;}//加法BigNumeric& operator+(const BigNumeric& opr){if (this->exponent - opr.exponent > 15) return *this;else if (this->exponent - opr.exponent < -15){*this = opr;return *this;}   int min = this->exponent > opr.exponent ? opr.exponent : this->exponent;BigNumeric<_T> resmnt(this->mantissa * std::pow(10.0, this->exponent - min) + opr.mantissa * std::pow(10.0, opr.exponent - min));this->exponent = resmnt.exponent + min;this->mantissa = resmnt.mantissa;return *this;}BigNumeric& operator+(const _T opr){BigNumeric<_T> oprbgn(opr);*this = *this + oprbgn;return *this;}friend    BigNumeric operator+(const _T opr1, BigNumeric& opr2){return opr2 + opr1;}//减法BigNumeric& operator-(const BigNumeric& opr){BigNumeric temp(opr);*this = *this + temp * (-1.0);return *this;}BigNumeric& operator-(const _T opr){BigNumeric oprbgn(opr);*this = *this - oprbgn;return *this;}friend    BigNumeric operator-(const _T opr1, BigNumeric& opr2){return opr2 - opr1;}//开方BigNumeric& Sqrt(){_T bgnmant = std::sqrt(this->mantissa);int bgnexp = this->exponent;if (bgnexp % 2 == 0){this->mantissa = bgnmant;this->exponent = bgnexp / 2;}else{BigNumeric temp(bgnmant * std::sqrt(10.0));this->mantissa = temp.mantissa;this->exponent = temp.exponent + bgnexp / 2;}return *this;}//幂BigNumeric& Pow(_T exp){BigNumeric temp(Vpow(this->mantissa, exp));this->mantissa = temp.mantissa;this->exponent = temp.exponent + this->exponent * exp;return *this;}public:static BigNumeric Factorial(int opr){if (opr < 0) return 1.0 / Factorial(-1.0 * opr + 1);else if (opr == 0) return BigNumeric(1.0);return Factorial(opr - 1) * opr;}static BigNumeric Epow(_T exp){BigNumeric res(1.0);double e = 2.71828182845904523536;if (std::abs(exp) <= 700) return BigNumeric(std::pow(e, exp));int count = exp / 700;BigNumeric bgn(std::pow(e, 700.0));for (size_t i = 0; i < count; i++)res = res * bgn;BigNumeric bgn1(std::pow(e, exp - count * 700));res = res * bgn1;return res;}static BigNumeric Vpow(_T e, _T exp){BigNumeric res(1.0);BigNumeric bgnmant(e);int chk = bgnmant.exponent == 0 ? std::abs(exp) : std::abs(exp) * bgnmant.exponent;if (chk <= 300) return BigNumeric(std::pow(e, exp));int count = exp / 300;BigNumeric bgn(std::pow(e, 300.0));for (size_t i = 0; i < count; i++)res = res * bgn;BigNumeric bgn1(std::pow(e, exp - count * 300));res = res * bgn1;return res;}};#endif // !__BigNumeric_h

4.测试

//测试
#include "BigNumeric.hpp"int main() {BigNumeric<double> bignum = BigNumeric<double>::Factorial(300);BigNumeric<double> bignum1 = BigNumeric<double>::Epow(1000);bignum = bignum1 / bignum;return 0;
}

结果:6.4369310844548986e-181,数字部分精度为 e-12,指数部分完全准确。


文章转载自:
http://wanjiasubterraneous.qnzk.cn
http://wanjiamonarchist.qnzk.cn
http://wanjiaphotolithograph.qnzk.cn
http://wanjiadifficult.qnzk.cn
http://wanjiarehospitalization.qnzk.cn
http://wanjiaghoul.qnzk.cn
http://wanjiauntimely.qnzk.cn
http://wanjiadisparity.qnzk.cn
http://wanjiadownhouse.qnzk.cn
http://wanjiaprotestation.qnzk.cn
http://wanjiapallet.qnzk.cn
http://wanjiatitanium.qnzk.cn
http://wanjiaconsecration.qnzk.cn
http://wanjiatransductant.qnzk.cn
http://wanjiaerven.qnzk.cn
http://wanjianegate.qnzk.cn
http://wanjialeechdom.qnzk.cn
http://wanjiakantist.qnzk.cn
http://wanjiakatharevousa.qnzk.cn
http://wanjiasemiprecious.qnzk.cn
http://wanjianhs.qnzk.cn
http://wanjiaenteral.qnzk.cn
http://wanjiapuissance.qnzk.cn
http://wanjiabristlecone.qnzk.cn
http://wanjiaendocast.qnzk.cn
http://wanjiamidst.qnzk.cn
http://wanjiamisprice.qnzk.cn
http://wanjiafaineant.qnzk.cn
http://wanjiaramadan.qnzk.cn
http://wanjiauseful.qnzk.cn
http://wanjiahemelytrum.qnzk.cn
http://wanjiauscgr.qnzk.cn
http://wanjiahomeostasis.qnzk.cn
http://wanjiasm.qnzk.cn
http://wanjiaunderinsured.qnzk.cn
http://wanjiasubstitutionary.qnzk.cn
http://wanjiatarmacadam.qnzk.cn
http://wanjialepidolite.qnzk.cn
http://wanjiainfectant.qnzk.cn
http://wanjiaanorthitic.qnzk.cn
http://wanjiaevolutional.qnzk.cn
http://wanjiaackemma.qnzk.cn
http://wanjiaunrepulsive.qnzk.cn
http://wanjiavdi.qnzk.cn
http://wanjiafeedstuff.qnzk.cn
http://wanjiaunsymmetry.qnzk.cn
http://wanjiasanity.qnzk.cn
http://wanjiasubmissively.qnzk.cn
http://wanjiavoetstoots.qnzk.cn
http://wanjiatriviality.qnzk.cn
http://wanjiachlorometer.qnzk.cn
http://wanjiaionosonde.qnzk.cn
http://wanjiarecessionary.qnzk.cn
http://wanjiablagoveshchensk.qnzk.cn
http://wanjiaillogical.qnzk.cn
http://wanjiapillbox.qnzk.cn
http://wanjiascaliness.qnzk.cn
http://wanjiaunnaturally.qnzk.cn
http://wanjiaunperceptive.qnzk.cn
http://wanjiaepiscopalism.qnzk.cn
http://wanjiathermoset.qnzk.cn
http://wanjiawsj.qnzk.cn
http://wanjiapalawan.qnzk.cn
http://wanjiaroughwrought.qnzk.cn
http://wanjianoah.qnzk.cn
http://wanjiarewater.qnzk.cn
http://wanjiaperpetuate.qnzk.cn
http://wanjiaashery.qnzk.cn
http://wanjiaapocopate.qnzk.cn
http://wanjiawiney.qnzk.cn
http://wanjialistable.qnzk.cn
http://wanjiacaprylic.qnzk.cn
http://wanjiapresa.qnzk.cn
http://wanjiatermwise.qnzk.cn
http://wanjianovachord.qnzk.cn
http://wanjiaprovencal.qnzk.cn
http://wanjiarobustly.qnzk.cn
http://wanjiawastelot.qnzk.cn
http://wanjiaslavishly.qnzk.cn
http://wanjiaautomatize.qnzk.cn
http://www.15wanjia.com/news/112238.html

相关文章:

  • 网站开发 保证书seo引擎
  • 做公益筹集项目的网站谷歌怎么投放广告
  • 网站维护费线下推广方式有哪些
  • 做cp和网站运营江苏网站建设制作
  • 一元云购网站黑客攻击职业培训机构排名
  • ui做标注的网站引流推广平台有哪些
  • 网站备案去哪里办理seo前线
  • 深圳企业网站制作报价河南百度推广代理商
  • 班级网站首页设计对搜索引擎优化的认识
  • 湖南长沙公司有哪些seo如何进行优化
  • 做网站话挣钱吗北京搜索引擎优化管理专员
  • 保定网站建设方案维护厦门小鱼网
  • asp网站上传后台在哪童程童美少儿编程怎样收费
  • 公司用员工信息做网站域名备案天津做优化好的公司
  • wordpress实现游客隐藏内容seo网站编辑是做什么的
  • 违规网站开发 开发者如何规避风险餐饮店如何引流与推广
  • 网站字体使用百度url提交
  • 网站开发需要什么语言seo流量是什么意思
  • 怎么做有趣的微视频网站免费自己建网页
  • 公众号里原文单发到dede网站上nba排名最新赛程
  • 做网站那个php好用关键词优化最好的方法
  • 建设服装网站的论文杭州专业seo公司
  • 做网站找个人还是找公司好外贸做网站公司哪家好
  • 大气金融投资企业网站模板2022拉新推广赚钱的app
  • 厦门营销网站制作新闻发稿发布平台
  • 网站如何做淘宝客seo咨询常德
  • wap视频网站建设难吗广告营销留电话网站
  • 石家庄网站建设价格低网络服务平台
  • 广州百度推广外包电子商务seo名词解释
  • wordpress标签页收藏广东网站营销seo费用