浮点阵列用C [英] A floating point array in C

查看:115
本文介绍了浮点阵列用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个code,其中我有一次在一个文本文件来加载存储在每个行浮点值...我使用的fscanf加载这些数据到彩车的阵列().. 。然而,我发现浮点分别存放在不同的方式,例如407.18被存储为407.179993,414.35作为414.350006 ...现在我卡住,因为它是绝对重要的号码被存储在他们的文件中的表格但在这里,它似乎是不同的,即使它的本质一样的....我如何得到原来的形式存储的数字?

i am developing a code where i have to load floating point values stored in each line at a time in a text file...i loaded each of these data into a array of floats using fscanf()...however i found that the floating points were stored in a different way, example 407.18 was stored as 407.179993, 414.35 as 414.350006...now i am stuck because it is absolutely important that the numbers be stored in the form they were in the file but here it seems to be different even though essentially its the same....how do i get the numbers to store in the original form?

推荐答案

如果这是绝对重要的是,数字存储在他们的文件形式,不使用浮点值 。并非所有的分数基本10个值可以被重新$ P $二进制正是psented。

If it's absolutely important that the numbers be stored in the form they were in the file, don't use floating-point values. Not all fractional base-10 values can be represented exactly in binary.

有关详细信息,您应该咨询文章什么每台计算机科学家如若知道浮点运算 [PDF链接]

For details, you should consult the article "What Every Computer Scientist Should Know About Floating-Point Arithmetic" [PDF link].

您应该存储的数字字符串形式或比例整数。

You should store the numbers in string form or as scaled integers.

这篇关于浮点阵列用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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