float_t有什么意义,什么时候应该使用? [英] What's the point of float_t and when should it be used?

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

问题描述

我正在使用一个正在使用旧版GCC的客户端(3.2.3是准确的),但是想要升级,一个被认为是升级到较新版本的绊脚石的原因是大小差异的类型 float_t 其中,肯定是正确的:

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:

在GCC 3.2.3

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

GCC 4.1.2

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

但是这个区别的原因是什么?为什么大小变小,何时应该不应该使用 float_t double_t

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 ?

推荐答案

float_t的原因是对于某些处理器和使用较大类型的编译器float double可以更有效,所以float_t允许编译器使用更大的类型而不是float。

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.

因此在OPs的情况下使用float_t大小的变化是标准允许的。如果原始代码想要使用较小的浮点数,那么应该使用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.

open-std doc


例如类型定义
float_t和double_t在
< math.h>中定义)旨在允许
有效使用具有
的架构更高效,更宽的格式。附件

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天全站免登陆