什么是则float_t点,当它应该被使用? [英] What's the point of float_t and when should it be used?

查看:1467
本文介绍了什么是则float_t点,当它应该被使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与谁在使用旧版本的GCC(3.2.3是precise),但想要升级客户端和一个已经给出绊脚石升级到新版本的原因之一是工作的差异在类型的大小则float_t 其中,果然是正确的:

在GCC 3.2.3

 的sizeof(则float_t)= 12
的sizeof(浮动)= 4
的sizeof(DOUBLE_T)= 12
的sizeof(双)= 8

在GCC 4.1.2

 的sizeof(则float_t)= 4
的sizeof(浮动)= 4
的sizeof(DOUBLE_T)= 8
的sizeof(双)= 8

但什么是造成这种差异的原因吗?为什么尺寸变得越来越小,何时应该和不应该使用则float_t DOUBLE_T


解决方案

究其原因,为float_t是,使用较大型如一些处理器和编译器长双浮法可能是更有效,所以允许则float_t编译器来使用更大的类型,而不是浮动。

因此​​,在使用中则float_t大小的变化的有机磷农药的情况是什么样的标准允许。如果原来的code想使用较小尺寸的浮动,应该使用浮动。

有在开放-STD DOC


  

例如类型定义
  则float_t和DOUBLE_T(定义
  &所述;文件math.h&1+),用于让
  有效利用结构与
  更有效的,更广泛的格式。附件


I'm working with a client who is using an old version of GCC (3.2.3 to be precise) but wants to upgrade and one reason that's been given as stumbling block to upgrading to a newer version is differences in the size of type float_t which, sure enough is correct:

On GCC 3.2.3

sizeof(float_t) = 12
sizeof(float) = 4
sizeof(double_t) = 12
sizeof(double) = 8

On GCC 4.1.2

sizeof(float_t) = 4
sizeof(float) = 4
sizeof(double_t) = 8
sizeof(double) = 8

but what's the reason for this difference? Why did the size get smaller and when should and shouldn't you use float_t or double_t ?

解决方案

The reason for float_t is that for some processors and compilers using a larger type e.g. long double for float could be more efficient and so the float_t allows the compiler to use the larger type instead of float.

thus in the OPs case using float_t the change in size is what the standard allows for. If the original code wanted to use the smaller float sizes it should be using float.

There is some rationale in open-std doc

for example the type definitions float_t and double_t (defined in <math.h>), are intended to allow effective use of architectures with more efficient, wider formats. Annexes

这篇关于什么是则float_t点,当它应该被使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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