执行文件I / O时精度下降 [英] loss of precision in doing file I/O

查看:59
本文介绍了执行文件I / O时精度下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个疑问,我会尽可能清楚地向你揭露它,也许

它是不完全是主题,对不起。


我有几个双打矢量(一些计算的输出)和我

检查标准和点产品之间的产品

将它们存储在一个txt文件中,获得预期的结果。


向量是正交的,所以norm = 1和点产品给出了
类似于1.0e-18的东西,我认为它非常接近于零...


当我再次从txt文件中读取向量时,我检查相同的东西

我发现点积现在大约是1.0e-8。


这是正常的吗?有没有办法避免这种精度损失?


我在win2000上使用visual studio 6进行c ++编程。


感谢您的支持宝贵的帮助。


-

我的电子邮件地址中没有数字

解决方案

"吉夫"写道:

我有一个疑问,我会尽可能清楚地向你展示它,也许它不完全是主题,对不起。

我有几个双打矢量(一些计算的输出),我检查
它们之间的标准和点积,然后将它们存储在txt文件中获得预期的结果。

向量是正交的,所以norm = 1,点积给出类似于1.0e-18的东西,我认为它非常接近于零......当我再次从txt文件中读取向量时,我检查了相同的东西
我发现点积现在大约为1.0e-8。

这是正常的吗?有没有办法避免这种精度损失?

我在win2000上使用visual studio 6进行c ++编程。




如果您阅读并使用>>写入文件和<<数据将被转换为字符表示,并将使用默认精度。

1.0e-8听起来像我期望的那样。您可以更改

精度[请参阅ios :: precision()]或以二进制形式保存文件[请参阅

read()和write()]。


giff写道:

大家好,

我有一个疑问,我会尝试将它暴露给你尽可能清楚,也许
它不完全是主题,对不起。

我有几个双打矢量(一些计算的输出)和我
在将它们存储在txt文件中之前检查它们之间的规范和点积,得到预期的结果。

向量是正交的,因此norm = 1,点积给出
像1.0e-18这样的东西我认为非常接近于零...

当我再次从txt文件中读取向量时,我会检查相同的东西
和我发现点积现在大约是1.0e-8。

这是正常的吗?有没有办法避免这种精度损失?


请参阅此常见问题及以下内容:

http://www.parashift.com/c++-faq-lit...html#faq-29.16


你能告诉我们一个*完整*但*最小*的代码片段,我们可以削减

并粘贴到我们的编辑器中试试吗?这可能是用户错误。

我在win2000上使用visual studio 6在c ++中编程。




不相关。 (如果它是相关的,你就在错误的新闻组中。)


干杯! --M


giff写道:

我有几个双打矢量(一些计算的输出)和我在将它们存储在txt文件中之前检查它们之间的规范和点积,得到预期的结果。

向量是正交的,因此norm = 1和点产品给出了类似于1.0e-18的东西,我认为它非常接近于零...

当我再次从txt文件中读取向量时,我检查相同的
事情我发现点积现在大约是1.0e-8。

这是正常的吗?有没有办法避免这种精度损失?


在输出中写下更多数字。

我在win2000上使用visual studio 6在c ++中编程。



这没关系。


V

-

请删除资金''A'通过电子邮件回复

我没有回复最热门的回复,请不要问


Hi all,

I have a doubt, I''ll try to expose it to you as clearly as I can, maybe
it is not completely in topic, sorry about that.

I have a few vectors of doubles (output of some calculations) and I
check the norm and the dot product between couples of them before
storing them in a txt file, obtaining the expected results.

The vectors are orthonormal so the norm=1 and the dot product gives
something like 1.0e-18 that I suppose is quite close to zero...

When I read the vectors again from the txt file, I check the same things
and I find that the dot product is now around 1.0e-8.

Is this normal? Is there a way to avoid this loss of precision?

I am programming in c++ using visual studio 6 on win2000.

Thanks for your precious help.

--
there are no numbers in my email address

解决方案

"giff" writes:

I have a doubt, I''ll try to expose it to you as clearly as I can, maybe it
is not completely in topic, sorry about that.

I have a few vectors of doubles (output of some calculations) and I check
the norm and the dot product between couples of them before storing them
in a txt file, obtaining the expected results.

The vectors are orthonormal so the norm=1 and the dot product gives
something like 1.0e-18 that I suppose is quite close to zero...

When I read the vectors again from the txt file, I check the same things
and I find that the dot product is now around 1.0e-8.

Is this normal? Is there a way to avoid this loss of precision?

I am programming in c++ using visual studio 6 on win2000.



If you read and write to the file using >> and << the data will be converted
to a character representation and the default precision will be used.
1.0e-8 sounds about like what I would expect. You could change the
precision [see ios::precision() ] or save the file in the binary form [see
read() and write()].


giff wrote:

Hi all,

I have a doubt, I''ll try to expose it to you as clearly as I can, maybe
it is not completely in topic, sorry about that.

I have a few vectors of doubles (output of some calculations) and I
check the norm and the dot product between couples of them before
storing them in a txt file, obtaining the expected results.

The vectors are orthonormal so the norm=1 and the dot product gives
something like 1.0e-18 that I suppose is quite close to zero...

When I read the vectors again from the txt file, I check the same things
and I find that the dot product is now around 1.0e-8.

Is this normal? Is there a way to avoid this loss of precision?
See this FAQ and those following:

http://www.parashift.com/c++-faq-lit...html#faq-29.16

Can you show us a *complete* but *minimal* code snippet that we can cut
and paste into our editors to try it? It may be user error.
I am programming in c++ using visual studio 6 on win2000.



Irrelevant. (If it is relevant, you''re in the wrong newsgroup.)

Cheers! --M


giff wrote:

I have a few vectors of doubles (output of some calculations) and I
check the norm and the dot product between couples of them before
storing them in a txt file, obtaining the expected results.

The vectors are orthonormal so the norm=1 and the dot product gives
something like 1.0e-18 that I suppose is quite close to zero...

When I read the vectors again from the txt file, I check the same
things and I find that the dot product is now around 1.0e-8.

Is this normal? Is there a way to avoid this loss of precision?
Write more digits to the output.
I am programming in c++ using visual studio 6 on win2000.



That shoulnd''t matter.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


这篇关于执行文件I / O时精度下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆