473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How many distinct float values?

I can google search to find the range of values that can be represented
in a float by reading up on the IEEE std, but is that the same as how
many distinct values that can go in a float type?

For instance, floats can distinguish 0.000001 and 0.000002. If I
started with 0.000001 and kept adding 0.000001 until I hit some maximum
value (FLT_MAX?) and kept a counter of how many times I added 0.000001,
would I have a count of how many distinct values can go in a float? And
would that be the same thing as FLT_MAX - FLT_MIN?

Thanks very much.
Johnathan
Nov 14 '05 #1
7 4068
>I can google search to find the range of values that can be represented
in a float by reading up on the IEEE std, but is that the same as how
many distinct values that can go in a float type?
No. The distance between representable floating-point numbers is
not constant because, well, the binary (or decimal) point floats.

If it's a 32-bit floating point number, you can represent AT MOST
2**32 bit patterns. Subtract one for negative zero, which has the
same value as positive zero. Subtract more for NaNs (and this
depends on just how many different NaN values you think are distinct)
and infinities. Subtract more for denormal values which duplicate
non-denormal values or each other. In any case the number of
distinct values is likely to be somewhat more than 98% of 2**32 but
less than 100% of 2**32.
For instance, floats can distinguish 0.000001 and 0.000002. If I
started with 0.000001 and kept adding 0.000001 until I hit some maximum
value (FLT_MAX?) and kept a counter of how many times I added 0.000001,
would I have a count of how many distinct values can go in a float? And
No. And you would likely NEVER REACH FLT_MAX.

Consider, for example, decimal floating point with exactly 6 decimal
digits of precision. You start off with 0.000001, and keep counting
until you get 1.000000. At that point, 1.000000 + 0.000001 =
1.000000, so you quit getting different answers. This happens even
if you've got enough exponent to represent 1.000000 e+100.

Note that adjacent representable numbers in this decimal floating
point are 1e+94 apart for .999999e+100 and .999998e+100, but
one millionth apart for .999999e+00 and .999998e+00 .
would that be the same thing as FLT_MAX - FLT_MIN?


No. And on even unreasonable floating point systems,
FLT_MAX - FLT_MIN == FLT_MAX.

Gordon L. Burditt
Nov 14 '05 #2
Johnathan Doe wrote:
.... snip ...
For instance, floats can distinguish 0.000001 and 0.000002. If I
started with 0.000001 and kept adding 0.000001 until I hit some
maximum value (FLT_MAX?) and kept a counter of how many times I
added 0.000001, would I have a count of how many distinct values
can go in a float? And would that be the same thing as FLT_MAX -
FLT_MIN?


float f, inc;
unsigned long ct, overct;

f = inc = 0.000001;
ct = overct = 0;
while (f < FLT_MAX) {
f = f + inc;
ct++;
if (0 == ct) overct++;
}

can be expected to run for a very long time. Think about it.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #3
In message <41***********************@per-qv1-newsreader-01.iinet.net.au>
Johnathan Doe <No-spam-here-johnathan_doe@!!!NOSPAMTHANKS!!!fastmail.com.au> wrote:
I can google search to find the range of values that can be represented
in a float by reading up on the IEEE std, but is that the same as how
many distinct values that can go in a float type?

For instance, floats can distinguish 0.000001 and 0.000002. If I
started with 0.000001 and kept adding 0.000001 until I hit some maximum
value (FLT_MAX?) and kept a counter of how many times I added 0.000001,
would I have a count of how many distinct values can go in a float? And
would that be the same thing as FLT_MAX - FLT_MIN?


As an additional comment to the other answers you've received, C99 adds
a couple of functions nextafter() and nexttoward() that can be used to
enumerate distinct floating values. This example would count the number of
distinct finite float values:

float f = -FLT_MAX;
long long count = 1;
do
{
f = nextafterf(f, FLT_MAX);
count++;
}
while (f != FLT_MAX);

Anyway, roughly speaking, an IEEE 32-bit single number can hold 2^32
different values, as there are 2^32 different bit patterns for the number.
But more specifically these break down as:

2 zeros (exponent=mantissa=0)
2 infinities (exponent=max, mantissa=0)
16,777,214 NaNs (exponent=max, mantissa<>0)
16,777,214 subnormal numbers (exponent=0, mantissa<>0)
4,261,412,864 normal numbers (0<exponent<max)

The count loop above would count the normals, subnormals and one of the
zeros, so should give 4,278,190,079.

In IEEE, all subnormal and normal numbers are distinct - it's an efficient
representation in that respect. The only "duplicate" coding is +/-0, and that
has its uses in certain infinitesimal convergence calculations - it preserves
the information of which side a cut was approached.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1728 727430
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
Nov 14 '05 #4
Kevin Bracey <ke**********@tematic.com> writes:
In message
<41***********************@per-qv1-newsreader-01.iinet.net.au> Johnathan
Doe <No-spam-here-johnathan_doe@!!!NOSPAMTHANKS!!!fastmail.com.au>
wrote:
I can google search to find the range of values that can be represented
in a float by reading up on the IEEE std, but is that the same as how
many distinct values that can go in a float type?

For instance, floats can distinguish 0.000001 and 0.000002. If I
started with 0.000001 and kept adding 0.000001 until I hit some maximum
value (FLT_MAX?) and kept a counter of how many times I added 0.000001,
would I have a count of how many distinct values can go in a float? And
would that be the same thing as FLT_MAX - FLT_MIN?


As an additional comment to the other answers you've received, C99 adds
a couple of functions nextafter() and nexttoward() that can be used to
enumerate distinct floating values. This example would count the number of
distinct finite float values:

float f = -FLT_MAX;
long long count = 1;
do
{
f = nextafterf(f, FLT_MAX);
count++;
}
while (f != FLT_MAX);

Anyway, roughly speaking, an IEEE 32-bit single number can hold 2^32
different values, as there are 2^32 different bit patterns for the number.
But more specifically these break down as:

[details snipped]

It's also important to remember that C's type "float" isn't
necessarily an IEEE floating-point type. It almost certainly will be
on any modern machine, but there are still system's with other
floating-point formats (VAX, IBM 370, some older Cray systems, etc.).

In C99, an implementation will define the symbol __STDC_IEC_559__
if it conforms to the IEEE floating-point standard (C99 Annex F).

--
Keith Thompson (The_Other_Keith) 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.
Nov 14 '05 #5
Memorize the following:

<ftp://ftp.quitt.net/Outgoing/goldbergFollowup.pdf>

--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
Nov 14 '05 #6
In article <d5****************@tematic.com> Kevin Bracey <ke**********@tematic.com> writes:
....
In IEEE, all subnormal and normal numbers are distinct - it's an efficient
representation in that respect. The only "duplicate" coding is +/-0, and that
has its uses in certain infinitesimal convergence calculations - it preserves
the information of which side a cut was approached.


Yes, I know that Kahan was a big proponent of it (as of the signed
infinities). But you get in problems when you try to implement
standard functions with complex arguments.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 14 '05 #7
In message <ln************@nuthaus.mib.org>
Keith Thompson <ks***@mib.org> wrote:
In C99, an implementation will define the symbol __STDC_IEC_559__
if it conforms to the IEEE floating-point standard (C99 Annex F).


Although Annex F specifies a lot more than just IEEE 754 conformance. The
implementation I use has been IEEE 754 conformant for years - far more so
than most x86 compilers, but is still some way from meeting all the
requirements of Annex F regarding library functions and pragmas. There's lots
of intricacy there to do with when exceptions get raised etc. So
__STDC_IEC_559__ remains undefined.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1728 727430
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
Nov 14 '05 #8

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

Similar topics

8
by: Richard | last post by:
This is probably easy but I can't work it out. I have this statement SELECT DISTINCT TOP 100 PERCENT dbo.CIF_PlaceReference.Name FROM dbo.CIF_Departures INNER JOIN dbo.CIF_PlaceReference...
3
by: blue | last post by:
I'm trying to order a varchar column first numerically, and second alphanumerically using the following SQL: SELECT distinct doc_number FROM doc_line WHERE product_id = 'WD' AND doc_type = 'O'...
8
by: Rich | last post by:
My table looks like this: char(150) HTTP_REF, char(250) HTTP_USER, char(150) REMOTE_ADDR, char(150) REMOTE_HOST, char(150) URL, smalldatetime TIME_STAMP There are no indexes on this table...
5
by: Fred Zuckerman | last post by:
Can someone explain the difference between these 2 queries? "Select Distinct id, account, lastname, firstname from table1" and "Select DistinctRow id, account, lastname, firstname from table1" ...
2
by: Shi Jin | last post by:
Hi there, I have been thinking this for quite a while: if we are considering the number of different representations of one type,say int and float, is there any difference as long as they are...
11
by: Marc Pelletier | last post by:
Hello, I am having trouble implementing the following callback: CNCSError CECWCompressor::WriteReadLine(UINT32 nNextLine, void **ppInputArray) where ppInputArray is a 3 by x array. The...
5
by: Daniel Wetzler | last post by:
Dear MSSQL experts, I use MSSQL 2000 and encountered a strange problem wqhile I tried to use a select into statement . If I perform the command command below I get only one dataset which has...
1
by: joesfer | last post by:
I'm trying to develop a graphical user interface for a renderer i've got written in an unmanaged C++ DLL with C#. During the rendering process, several images are sent to a delegate as float*...
4
printedgoods
by: printedgoods | last post by:
Hello all, I have a table that has data about the t-shirts i sell. My goal is to display the colors that are available in a specific way on my asp page: Shirt I have been playing around...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.