473,772 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does "float" always occupy 32 bits

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?

Sep 4 '06 #1
16 11280
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.
Sep 4 '06 #2
"chandanlinster " <ch************ @gmail.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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

Sep 4 '06 #3
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,o bjc,obj-c++,ada,treelan g
--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=releas e 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.goog legroups.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
Sep 4 '06 #4
Thanks everybody for providing the solutions.

Sep 4 '06 #5
"chandanlinster " <ch************ @gmail.comwrite s:
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?
Potentially, yes.

I've never heard of a C implementation where float is not 32 bits
(i.e., where sizeof(float) * CHAR_BIT != 32), but such implementations
could easily exist.

In any case, there's no real reason or need to assume that float is 32
bits. The compiler knows how big a float is so you don't need to
worry about it.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 4 '06 #6
Keith Thompson <ks***@mib.orgw rites:
"chandanlinster " <ch************ @gmail.comwrite s:
>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?

Potentially, yes.

I've never heard of a C implementation where float is not 32 bits
(i.e., where sizeof(float) * CHAR_BIT != 32), but such implementations
could easily exist.
I don't think that float could be much smaller than 32 bits. By
my calculations, a floating point number represented in the
format that the Standard expects would need approximately 28 bits
to have the required range and precision.
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 4 '06 #7
Ben Pfaff <bl*@cs.stanfor d.eduwrites:
Keith Thompson <ks***@mib.orgw rites:
>"chandanlinste r" <ch************ @gmail.comwrite s:
>>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?

Potentially, yes.

I've never heard of a C implementation where float is not 32 bits
(i.e., where sizeof(float) * CHAR_BIT != 32), but such implementations
could easily exist.

I don't think that float could be much smaller than 32 bits. By
my calculations, a floating point number represented in the
format that the Standard expects would need approximately 28 bits
to have the required range and precision.
Sure, but float could easily be larger than 32 bits.

And, in fact, contrary to what I wrote above, I've worked on machines
where float is 64 bits (and double is 64 bits, and long double is 128
bits). These were Cray vector machines, where the native word size is
64 bits.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 5 '06 #8
Keith Thompson <ks***@mib.orgw rites:
Ben Pfaff <bl*@cs.stanfor d.eduwrites:
>Keith Thompson <ks***@mib.orgw rites:
>>I've never heard of a C implementation where float is not 32 bits
(i.e., where sizeof(float) * CHAR_BIT != 32), but such implementations
could easily exist.

I don't think that float could be much smaller than 32 bits. By
my calculations, a floating point number represented in the
format that the Standard expects would need approximately 28 bits
to have the required range and precision.

Sure, but float could easily be larger than 32 bits.
Yes, I should have added that. I didn't mean to sound contradictory.
And, in fact, contrary to what I wrote above, I've worked on machines
where float is 64 bits (and double is 64 bits, and long double is 128
bits). These were Cray vector machines, where the native word size is
64 bits.
Right.
--
"I should killfile you where you stand, worthless human." --Kaz
Sep 5 '06 #9
In article <ln************ @nuthaus.mib.or gKeith Thompson <ks***@mib.orgw rites:
"chandanlinster " <ch************ @gmail.comwrite s:
....
Does this mean "float" variables have different sizes on different
machines?

Potentially, yes.

I've never heard of a C implementation where float is not 32 bits
(i.e., where sizeof(float) * CHAR_BIT != 32), but such implementations
could easily exist.
I have used them. sizeof(float) == 8.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Sep 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2660
by: asmirnov1234567890 | last post by:
Hi my python 2.3.4 for windows refuse to execute line float("NaN"). It says: >>> float("NaN") Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: invalid literal for float(): NaN
5
1995
by: geskerrett | last post by:
We are working on a project to decipher a record structure of an old accounting system that originates from the late80's mid-90's. We have come across a number format that appears to be a "float" but doesn't match any of the more standard implementations. so we are hoping this is a recognizable number storage format with an identifiable name AND pre-built conversion method similiar to the "struct" modules available in python. Here is...
8
8883
by: Manuel | last post by:
Anyone know why for openGL applications must be used GLfloat (and GLint, etc...) instead float, int, etc..? thx, Manuel
5
4199
by: Peter Hansen | last post by:
I'm investigating a puzzling problem involving an attempt to generate a constant containing an (IEEE 754) "infinity" value. (I understand that special float values are a "platform-dependent accident" etc...) The issue appears possibly to point to a bug in the Python compiler, with it producing inconsistent results. I'm using "Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32". This code sometimes produces a float of 1.0, sometimes...
29
11116
by: candy_init | last post by:
Hi all, I just came across the following program: #include <stdio.h> int main() { float a = 12.5; printf("%d\n", a); printf("%d\n", *(int *)&a); return 0;
5
1951
by: maya | last post by:
hi, here, http://www.mayacove.com/design/sd/test2.html <div class="entry"has a bottom-margin of 20px.. but it's ignored if divs inside it have "float" property.. (put borders around divs for testing purposes.. just like in my previous post, HTML and CSS both validate..)
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.