浮动?双? [英] float? double?

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

问题描述

大家好......


我已经介绍了一些关于浮点数和双重数据类型之间差异的信息......但是,在现实世界,哪个最好?什么时候我们应该用
使用浮点数还是加倍?


谢谢

Erick

hi all...

I''ve readed some lines about the difference between float and double
data types... but, in the real world, which is the best? when should we
use float or double??

thanks
Erick

推荐答案

----- BEGIN PGP签名消息-----

哈希:SHA1

Erick-written :
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Erick-wrote:

大家好......


我已经介绍了浮点数和双精度之间的区别/>
数据类型......但是,在现实世界中哪个是最好的?什么时候我们应该使用浮点数还是双倍?
hi all...

I''ve readed some lines about the difference between float and double
data types... but, in the real world, which is the best? when should we
use float or double??



这是一个相当开放的问题。


但是,考虑到C浮点数学是在
双精度(转换为单精度和从单精度转换为

存储或从变量中检索值),以及(对于某些类型

of function)单精度浮点值(float)是自动提升为双精度值(double)的
,我会有

到说浮动可以超过两倍的唯一好处是,浮动可能比b
需要更少的存储空间而不是双倍。


我的钱,除非空间有问题,使用double作为代码的默认浮点格式可能会更好地坚持




只需要我的2cents值

- -

Lew Pitcher

----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.4.3( MingW32) - WinPT 0.11.12

iD8DBQFE5 hHGagVFX4UWr64RAmY2AKCBaT3TGdQdV9z8BHRXDc EgbNw5dACcCN8A

Ljp + / QJFHbOg99yloCUp00c =

= lP4v

----- END PGP SIGNATURE -----

That''s a fairly open-ended question.

However, considering that C floatingpoint math is conducted in
double-precision (with conversions to and from single precision only to
store or retrieve values from variables), and that (for certain types
of function) single-precision floatingpoint values ("float") are
promoted to double-precision values ("double") automagically, I''d have
to say that the only benefit float has over double is that float may
take less storage space than double.

For my money, unless space is an issue, it''s probably better to stick
with double as the default floatingpoint format for your code.

Just my 2cents worth
- --
Lew Pitcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12

iD8DBQFE5hHGagVFX4UWr64RAmY2AKCBaT3TGdQdV9z8BHRXDc EgbNw5dACcCN8A
Ljp+/QJFHbOg99yloCUp00c=
=lP4v
-----END PGP SIGNATURE-----


在文章< 11 ********************* @ m79g2000cwm.googlegroups中。 com>,

Erick-< er ********* @ yahoo.eswrote:
In article <11*********************@m79g2000cwm.googlegroups. com>,
Erick-<er*********@yahoo.eswrote:

>我'关于float和double
数据类型之间的差异已经引起了一些界限......但是,在现实世界中哪个是最好的?什么时候我们应该使用float还是double?
>I''ve readed some lines about the difference between float and double
data types... but, in the real world, which is the best? when should we
use float or double??



哪个最好,皮卡车还是半吨卡车?

浮动和双倍是根据允许的最小精度定义的
每个
。在任何给定的平台上,不要求两者之间有任何* b $ b * *之间的差异:如果浮动数据类型满足C对其施加的最低要求。双数据类型,

然后两者可能完全相同。


传统上,浮动比双倍快但提供的更少

精度。 double永远不会提供 - 而不是浮动的精确度,但是现在这些天来,找到计算机上的双倍

与浮动一样快(或快于)的情况并不少见。此外,浮动永远不会占用超过
永久存储而不是双倍,有时内存大小

是最大的因素(但是这些天你通常只是出去并且

如果需要,可以购买更多内存。)


还有一些计算机没有实现浮动或

硬件加倍,因此从速度的角度来看,有时两者都比使用整数运算差得多。但是现在还有很多计算机,其中整数算术比b $ b慢两倍 - 计算机被卖到了市场,其中

(比如说) )95%的需要速度的操作可能是浮点运算,因此开发资源主要用于加速浮点数。因此,从速度

的角度来看,你不能相信浮点数比整数算术更慢或更快。但是,当使用整数运算时,有时候

对于保持所需精度的

绝对至关重要。


所有这些也就是说,它取决于 ;-)

尺寸,速度,精度:对于任何给定的任务,其中任何一个都可能是关键因素。速度特别多变:CPU升级

而不改变其他任何东西可能会完全改变速度因素。

-

如果你撒谎编译器,它将得到它的报复。 - Henry Spencer


Which is best, a pickup truck, or a half-tonne truck?
float and double are defined in terms of minimum precision allowed
for each. On any given platform, it is not required that there is
*any* difference between the two: if the float data type meets the
minimum requirements that C imposes on the double data type,
then the two could be exactly the same.

Traditionally, float was faster than double but offered less
precision. double never offers -less- precision than float, but
these days, it is not uncommon to find computers on which double
is as fast (or faster than) float. Also, float never occupies -more-
permanent storage than does double, and sometimes memory size
is the biggest factor (but these days you usually just go out and
buy more memory if you need it.)

There are also still computers which do not implement either float or
double in hardware, so from a speed perspective, sometimes both
are significantly worse than using integer arithmetic instead. But
there are also numerous computers these days on which integer arithmetic
is slower than double -- computers being sold into markets where
(say) 95% of the operations requiring speed are likely to be
floating point operations, so the development resources are spent
primarily on accelarating floating point. Thus, from a speed
perspective, you cannot trust that floating point with be either
slower or faster than integer arithmetic. But there -are- times
when using integer arithmetic can be absolutely crucial for
preserving required accuracy.

All of which is to say, "it depends" ;-)
Size, speed, precision: for any given task, any of them might be
the key factor. Speed is particularily variable: a CPU upgrade
without changing anything else might completely alter the speed factors.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer


文章< 11 ********************** @ m79g2000cwm.googlegroups .com>,

Lew Pitcher< lp ****** @ sympatico.cawrote:
In article <11**********************@m79g2000cwm.googlegroups .com>,
Lew Pitcher <lp******@sympatico.cawrote:

>但考虑到C浮点数学以双精度进行(只有单精度转换才能存储或从变量中检索值),
>However, considering that C floatingpoint math is conducted in
double-precision (with conversions to and from single precision only to
store or retrieve values from variables),



这是不正确的,至少对于C89(我没有检查过C99。)


通常的算术转换如果有必要,请选择长双,

然后在必要时加倍,然后:


否则,如果任一操作数的类型为float,则另一个操作数

转换为浮动。


二进制+等操作的描述参考

通常的算术转换,但绝对不要说<为了计算的目的,
float被提升为double。

-

如果你撒谎到编译器,它将报复。 - Henry Spencer

That''s incorrect, at least for C89 (I haven''t checked C99.)

The "usual arithmetic conversions" choses long double if necessary,
then double if necessary, then:

Otherwise, if either operand has type float, the other operand
is converted to float.

The descriptions of operations such as binary + refer to the
usual arithmetic conversions, but definitely do NOT say that
float is promoted to double for the purposes of the calculation.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer


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

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