boost::multiprecision模块中float128相关的测试代码

C/C++ 专栏收录该内容
¥59.90 ¥99.00
124篇文章

boost::multiprecision模块中float128相关的测试代码

在C++中,float和double类型只能表示有限范围内的数值。如果需要使用更高的精度来表示浮点数,可以使用boost::multiprecision模块中提供的float128类型。float128可以表示比double更多的位数和更大的值范围,但是其精度相对于double仍然存在一定误差。

下面是使用boost::multiprecision中的float128类型进行简单计算的示例代码:

#include <iostream>
#include <boost/multiprecision/float128.hpp>

using namespace std;
using boost::multiprecision::float128;

int main()
{
    float128 f1 = 1.23;
    float128 f2 = 4.56;

    // 浮点数加法
    float128 f_sum = f1 + f2;
    cout << "f_sum = " << f_sum << endl;

    // 浮点数乘法
    float128 f_product = f1 * f2;
    cout << "f_product = " << f_product << endl;

    return 0;
}

在上述代码中,我们先定义两个float128类型的变量f1和f2,并分别赋值为1.23和4

使用boost库中的multiprecision模块提供的float128类型,可以在C++中表示高精度浮点数 需要注意的是,由于float128类型比普通的浮点类型要占用更多的内存,所以在进行大量计算时可能会影响程序的性能。但是,由于float128可以表示的精度远高于普通浮点数,因此在需要高精度计算的场合下,它是一个很好的选择。在主函数中,我们声明了两个float128类型的变量x和y,分别初始化为1.23和-4.56e-7。然后,我们使用cout语句打印出这两个变量的值。接着,我们定义了另外两个float128类型的变量z和w,分别计算了x + y和sqrt(x + y)的值,并将结果打印到控制台上。 阅读详情

相关推荐

boost::multiprecision::float128用法的测试程序

boost::multiprecision::float128用法的测试程序实现功能C++实现代码 实现功能 boost::multiprecision::float128用法的测试程序 C++实现代码 #include <boost/cstdfloat.hpp> // For float_64_t, float128_t. Must be first include! #include <boost/multiprecision/float128.hpp> #include &lt

希望我的博客,能帮上你解决学习中工作中所遇到的问题 762

使用Boost库的multiprecision模块进行float128相关的测试程序(C/C++)

这个示例程序演示了如何使用Boost库的multiprecision模块进行float128类型的操作。通过使用float128类型,我们可以在某些需要更高精度的计算场景中获得更准确的结果。上述代码演示了如何使用Boost库的multiprecision模块进行float128的相关操作。float128是一种具有更高精度的浮点数类型,可以用于需要更高精度计算的场景。的值,这样我们可以验证float128类型的变量的赋值是否成功。接下来,我们进行了一些基本的数学运算。的正弦值,并将结果保存在。

HackVibe的博客 288

BeautyGAN: Instance-level Facial Makeup Transfer with Deep Generative Adversarial Network(2018,妆容迁移)

论文下载地址:BeautyGAN | Proceedings of the 26th ACM international conference on Multimedia 目的:在实例级实现化妆图像和非化妆图像的妆容迁移 方法:全局域集损失和本地实例级损失合并到一个双输入/输出对抗生成网络。步骤:使用一对鉴别器将非化妆面传输到化妆域,鉴别器从域的真实样本中分辨出生成的图像。在域集迁移的基础上,采用基于不同人脸区域的像素级直方图损失来实现实例级迁移。为了保持人脸的一致性和消除伪影,在总体目标函数中加入了.

weixin_53965540的博客 669

海光(hygon)CPU ESXI vSphere 紫屏问题修复记录

海光服务器ESXI 紫屏问题修复

edison202302的博客 3574

【机器学习】【期末复习】有关机器学习的计算题可供期末复习参考(带本人手写解答与思考)

本文为学校课程《机器学习》的期末复习材料,主要是关于一些机器学习模型的计算题的解答过程。

网瘾中心呼唤爱的博客 1万+

DCDC开关节点SW的Layout抉择:打孔换层与EMI共模辐射的权衡

本文深入探讨了DCDC转换器中开关节点SW的Layout设计对EMI共模辐射的影响。通过分析SW节点的EMI辐射机制、打孔换层对输入环路的影响以及铜皮面积与共模辐射的量化关系,提出了工程实践中的权衡策略和优化方法,帮助工程师在设计中平衡EMI性能和电路效率。

weixin_29722783的博客 253

隐藏在WAV音频里的秘密:用Python脚本从‘噪音’CTF题中提取Flag

本文详细解析了如何利用Python脚本从WAV音频文件中提取隐藏的Flag信息,特别针对CTF比赛中的音频隐写技术。通过分析WAV文件结构、编写Python解析脚本,并解决字节序处理和异常值等实际问题,帮助读者掌握从‘噪音’中解码Flag的技巧。

weixin_30617737的博客 490

使用Python爬虫抓取政府网站政务信息:公告、通知的自动化抓取与分析

通过结合Requests、BeautifulSoup、Selenium等技术,你能够高效地抓取政府网站的数据,并通过MySQL存储与Pandas分析这些数据。通过自动化手段抓取这些信息,不仅可以提高数据收集的效率,还能够实时获取最新的政务动态,为政策研究、舆情分析等提供宝贵数据。我们将通过Python的Requests、BeautifulSoup、Selenium等工具,结合最新的技术实现一个完整的爬虫系统,帮助你轻松抓取并分析政务信息。通过爬虫,我们可以自动化地从指定网站上抓取公告、新闻、通知等信息。

2201_76125261的博客 1909

Prompt Engineering 学习指南:从入门到精通的最佳路径与资源

随着大型语言模型(LLM)能力的飞速发展,Prompt Engineering(提示工程)已成为人与AI协作的核心技能。本报告旨在为不同水平的学习者提供一条清晰、高效的学习路径,整合了当前社区公认的最佳实践和顶级开源资源,帮助您系统地掌握 Prompt Engineering,释放 LLM 的全部潜力。保持好奇心,不断尝试,您将能驾驭语言模型这一强大的工具,创造出前所未有的价值。超越简单的“一问一答”,学习如何将 Prompt Engineering 与外部工具和数据结合,构建强大的 AI 应用。

shiter编写程序的艺术 705

小卫星多普勒频偏MATLAB代码

多普勒频偏是由于发射机和接收机之间的相对运动而引起的频率变化。对于小卫星,由于其速度和高度的变化,多普勒频偏会变得更加明显。本文将探讨小卫星多普勒频偏的原理、影响因素以及补偿方法。多普勒频偏的原理当发射机和接收机之间存在相对运动时,接收到的信号频率会发生变化。这种频率变化称为多普勒频偏。其原理可以描述如下:设发射机和接收机之间的距离为 d,发射信号的频率为 f0,发射机和接收机的相对速度为 v。则接收到的信号频率 f 为:其中 c 为光速。

qq_59747472的博客 252

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

上一篇: MPI集合操作reduce性能测试
下一篇: GDCM:使用XMLDictReader类解析DICOM标准数据
普通网友
博客等级 码龄3年 119粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址