473,902 Members | 3,778 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 11308
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
2671
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
2004
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
8888
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
4205
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
11141
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
1955
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
9997
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
11279
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10870
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
10981
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
9673
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
7205
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
5893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4725
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

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.