double还是float,这是更快? [英] double or float, which is faster?

查看:359
本文介绍了double还是float,这是更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读加速C ++。我发现一个语句有时 double 的执行速度比C ++中的 float 更快。在读完句子后,我对 float double 工作感到困惑。请向我解释这一点。

I am reading "accelerated C++". I found one sentence which states "sometimes double is faster in execution than float in C++". After reading sentence I got confused about float and double working. Please explain this point to me.

推荐答案

取决于本机硬件的功能。

Depends on what the native hardware does.


  • 如果硬件实现double(像x86那样),那么通过将float扩展到这里来模拟float,并且转换会花费时间。

  • If the hardware implements double (like the x86 does), then float is emulated by extending it there, and the conversion will cost time. In this case, double will be faster.

如果硬件仅实现float,那么使用double模拟将花费更多的时间。在这种情况下,float将会更快。

If the hardware implements float only, then emulating double with it will cost even more time. In this case, float will be faster.

如果硬件实现了,并且两者都必须在软件中实现。在这种情况下,两者都会很慢,但double会稍慢(更多的加载和存储操作至少)。

And if the hardware implements neither, and both have to be implemented in software. In this case, both will be slow, but double will be slightly slower (more load and store operations at the least).

您提及的报价可能是指x86平台,其中第一种情况 >给定。但这一般不成立。

The quote you mention is probably referring to the x86 platform, where the first case was given. But this doesn't hold true in general.

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

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