473,788 Members | 3,078 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
16 11283
Keith Thompson wrote:
"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.
The Hi-Tech compiler for the PIC gives you the option of 24 or 32 bit
floats. I am not sure what ANSI says about that.
Sep 6 '06 #11
Neil <Ne*******@worl dnet.att.netwri tes:
Keith Thompson wrote:
>"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.
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.

The Hi-Tech compiler for the PIC gives you the option of 24 or 32 bit
floats. I am not sure what ANSI says about that.
It doesn't directly say anything, but I don't believe it's possible to
meet the standard's requirements for type float in 24 bits. By my
calculations you need at least 27 bits (1 sign bit, 20 mantissa bits,
6 exponent 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 6 '06 #12

"Keith Thompson" <ks***@mib.orgw rote in message
news:ln******** ****@nuthaus.mi b.org...
Neil <Ne*******@worl dnet.att.netwri tes:
>Keith Thompson wrote:
>>"chandanlinst er" <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.

The Hi-Tech compiler for the PIC gives you the option of 24 or 32 bit
floats. I am not sure what ANSI says about that.

It doesn't directly say anything, but I don't believe it's possible to
meet the standard's requirements for type float in 24 bits. By my
calculations you need at least 27 bits (1 sign bit, 20 mantissa bits,
6 exponent bits).
Easy.Your 24 bits index into an array of double-precision 64 bit values.
Since the user isn't guaranteed more than 64 K of memory, you've done it.
--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.

Sep 6 '06 #13
Keith Thompson wrote:
Neil <Ne*******@worl dnet.att.netwri tes:
[ snip ]
>The Hi-Tech compiler for the PIC gives you the option of 24 or 32 bit
floats. I am not sure what ANSI says about that.

It doesn't directly say anything, but I don't believe it's possible to
meet the standard's requirements for type float in 24 bits. By my
calculations you need at least 27 bits (1 sign bit, 20 mantissa bits,
6 exponent bits).
Without regard to the Standard's requirements..

IEEE 754 has an extra bit. Float on my Sun and x86 iron is 32 bits and
includes a sign, 8 exponent bits and a 24-bit mantissa. They squeeze 33
bits into 32 by assuming the high order bit of a normalized mantissa is
always 1. This means we can use the bit position to hold the low order
bit of the exponent.

Same system for double, of course. Sign + 11 exponent bits + 53 mantissa
bits == 65. It fits, of course, in 64 bits.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Sep 6 '06 #14
Malcolm wrote:
"Keith Thompson" <ks***@mib.orgw rote in message
.... snip ...
>>
It doesn't directly say anything, but I don't believe it's
possible to meet the standard's requirements for type float in
24 bits. By my calculations you need at least 27 bits (1 sign
bit, 20 mantissa bits, 6 exponent bits).

Easy.Your 24 bits index into an array of double-precision 64 bit
values. Since the user isn't guaranteed more than 64 K of memory,
you've done it.
Harumph. C passes by value. How do you pass those beasts by value?

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Sep 7 '06 #15
CBFalconer <cb********@yah oo.comwrites:
Malcolm wrote:
>"Keith Thompson" <ks***@mib.orgw rote in message
... snip ...
>>>
It doesn't directly say anything, but I don't believe it's
possible to meet the standard's requirements for type float in
24 bits. By my calculations you need at least 27 bits (1 sign
bit, 20 mantissa bits, 6 exponent bits).

Easy.Your 24 bits index into an array of double-precision 64 bit
values. Since the user isn't guaranteed more than 64 K of memory,
you've done it.

Harumph. C passes by value. How do you pass those beasts by value?
They're only 24 bits; why would there be any problem passing them by
value?

So the idea is that a value of type "float" is a 24-bit index into a
table of, say, 32-bit floating-point objects. There are up to 2**32
possible values, but only 2**24 of them can exist within a single
execution of a program. Any operation that produces a new (32-bit)
value creates a new entry in the table and a new 24-bit index value.

This is a very silly idea, but it could satisfy *most* of the required
semantics of type float.

One thing that you couldn't do with this is write a value of type
"float" to a binary file, read it from another instance of the same
program, and get the same value. Maybe a conforming freestanding
implementation could get away this this. (Is there an embedded
version of the DS9K?)

--
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 7 '06 #16


"Joe Wright" <jo********@com cast.netwrote in message
news:3v******** *************** *******@comcast .com...
Keith Thompson wrote:
Neil <Ne*******@worl dnet.att.netwri tes:
[ snip ]
The Hi-Tech compiler for the PIC gives you the option of 24 or 32 bit
floats. I am not sure what ANSI says about that.
It doesn't directly say anything, but I don't believe it's possible to
meet the standard's requirements for type float in 24 bits. By my
calculations you need at least 27 bits (1 sign bit, 20 mantissa bits,
6 exponent bits).

Without regard to the Standard's requirements..

IEEE 754 has an extra bit. Float on my Sun and x86 iron is 32 bits and
includes a sign, 8 exponent bits and a 24-bit mantissa. They squeeze 33
bits into 32 by assuming the high order bit of a normalized mantissa is
always 1. This means we can use the bit position to hold the low order
bit of the exponent.

Same system for double, of course. Sign + 11 exponent bits + 53 mantissa
bits == 65. It fits, of course, in 64 bits.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Honeywell L66 has 36 bit floats.....

Sep 7 '06 #17

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

Similar topics

6
2662
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
1996
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
11119
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
9655
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
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
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
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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...
0
6749
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
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
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.