是否“浮动”总是占32位 [英] Does "float" always occupy 32 bits

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

问题描述

据我所知,浮点变量被声明为float

遵循IEEE格式表示(大小为32位)。但是,C编程语言一书的第1章 - 第9页第9页。声明

两个范围内的范围和浮动依赖于您的机器

使用

这是否意味着浮动 ;变量在不同的机器上有不同的大小?

解决方案

chandanlinster写道:


据我所知,浮点变量被声明为float

遵循IEEE格式表示(大小为32位)。但是,C编程语言一书的第1章 - 第9页第9页。声明

两个范围内的范围和浮动依赖于您的机器

使用

这是否意味着浮动 ;变量在不同的
机器上有不同的大小?



是的。


虽然IEEE单-precision类型是最常见的实现

float,这不是必需的。该标准仅需要最小范围和最低精度
。实现可以选择表示它们实现了

IEC 60559,IEEE 754的修订版。


实际上,大多数程序并不依赖于特定的大小。浮动;

那些假定通常是那些也假设int为32位的人,所以

浮点数和整数可以互换存储。毋庸置疑,这些都不是便携式假设,而且很少适用,更不用说必要了。


S.


" chandanlinster" < ch ************ @ gmail.comwrote in message

news:11 ****************** ****@e3g2000cwe.googlegro ups.com ...


据我所知浮点变量,声明为浮点数

遵循IEEE格式表示(大小为32位)。



这不保证。




chapter1-page no本书的第9章The C programming language声明

两个范围内的范围和浮动依赖于您的机器

使用

这是否意味着浮动 ;变量在不同的
机器上有不同的大小?



是的。


菲利普


大家好。


我有一台运行debian Linux的AMD-64版本的gcc&这是我得到的
...


字符:1

短:2

长:8

浮动:4

双倍:8

长双:16


这里有我的编译器选项..


使用内置规格。

目标:x86_64-linux-gnu

配置:。 ./src/configure -v

--enable-languages = c,c ++,java,fortran,objc,obj-c ++,ada,treelang

--prefix = / usr --enable-shared --with-system-zlib --libexecdir = / usr / lib

--without-included-gettext --enable-threads = posix --enable-nls

--program-suffix = -4.1 --enable -__ cxa_atexit --enable-clocale = gnu

--enable-libstdcxx-debug --enable-java-awt = gtk --enable-gtk-cairo

--with-java-home = / usr / lib / jvm / java-1.4.2-gcj-4.1-1.4.2.0 / jre

--enable-mpfr --enable-checking = release x86_64-linux-gnu

线程模型:posix

gcc版本4.1.2 20060613(预发布) (Debian 4.1.1-5)


干杯

/ R


Philip Potter写道:


" chandanlinster" < ch ************ @ gmail.comwrote in message

news:11 ****************** ****@e3g2000cwe.googlegro ups.com ...


据我所知浮点变量,声明为浮点数

遵循IEEE格式表示(大小为32位)。



这不保证。




chapter1-page no本书的第9章The C programming language声明

两个范围内的范围和浮动依赖于您的机器

使用

这是否意味着浮动 ;变量在不同的
机器上有不同的大小?



是的。


Philip


As far as I know floating point variables, that are declared as float
follow IEEE format representation (which is 32-bit in size). But
chapter1-page no 9 of the book "The C programming language" states that
"THE RANGE OF BOTH int AND float DEPENDS ON THE MACHINE YOU ARE
USING".
Does this mean "float" variables have different sizes on different
machines?

解决方案

chandanlinster wrote:

As far as I know floating point variables, that are declared as float
follow IEEE format representation (which is 32-bit in size). But
chapter1-page no 9 of the book "The C programming language" states that
"THE RANGE OF BOTH int AND float DEPENDS ON THE MACHINE YOU ARE
USING".
Does this mean "float" variables have different sizes on different
machines?

Yes.

Although the IEEE single-precision type is the most common implementation of
float, this is not required. The standard only requires a minimum range and
minimum precision. Implementations can optionally signal that they implement
IEC 60559, a revision of IEEE 754.

In practice, most programs do not depend on the particular size of a float;
the ones that assume are usually those who also assume an int is 32 bits, so
floats and ints can be stored interchangeably. Needless to say, these are
not portable assumptions, and rarely appropriate, let alone necessary.

S.


"chandanlinster" <ch************@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...

As far as I know floating point variables, that are declared as float
follow IEEE format representation (which is 32-bit in size).

This is not guaranteed.

But
chapter1-page no 9 of the book "The C programming language" states that
"THE RANGE OF BOTH int AND float DEPENDS ON THE MACHINE YOU ARE
USING".
Does this mean "float" variables have different sizes on different
machines?

Yes.

Philip


Hi Guys.

I have a AMD-64 turion running debian Linux with gcc & here is what I
got..

char:1
short:2
long:8
float:4
double:8
long double:16

Here are my compiler options..

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,fortran,objc,obj-c++,ada,treelang
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/jre
--enable-mpfr --enable-checking=release x86_64-linux-gnu
Thread model: posix
gcc version 4.1.2 20060613 (prerelease) (Debian 4.1.1-5)

Cheers
/R

Philip Potter wrote:

"chandanlinster" <ch************@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...

As far as I know floating point variables, that are declared as float
follow IEEE format representation (which is 32-bit in size).


This is not guaranteed.

But
chapter1-page no 9 of the book "The C programming language" states that
"THE RANGE OF BOTH int AND float DEPENDS ON THE MACHINE YOU ARE
USING".
Does this mean "float" variables have different sizes on different
machines?


Yes.

Philip


这篇关于是否“浮动”总是占32位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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