Re: About the bits reserved for float variable [message #39497] |
Sat, 22 May 2004 05:01  |
George N. White III
Messages: 56 Registered: September 2000
|
Member |
|
|
On Fri, 21 May 2004, Nuno Oliveira wrote:
> I looking at the Chapter 5 of the Bulding Aplication.
>
> It says, for float variables that it's a 32 bits number in the range of
> +/-10^38 withe approximately six or seven decimal places of significance.
> What I'm missing here? How can a number 32 bit number range between -10^38
> and +10^38?
Read chapter 1 of any decent introductory numerical analysis text and then
"What Every Computer Scientist Should Know About Floating-Point
Arithmetic" by D. Goldberg, ACM Computing Surveys, Vol 23, 1991, p5-48)
and reprinted in Sun's online manuals. See links on:
http://cch.loria.fr/documentation/IEEE754/
While it is true that many people do get by without understanding
f.p. arithmetic, there are also many examples of calculations going astray
due to failure to recognize situations where the difference between
f.p. and real numbers matters. It is becoming more important to
understand the material in Goldberg's paper because newer hardware
speedups (speculative execution, merged operations, parallel
processing) tend to make it harder to diagnose arithmetic problems.
--
George N. White III <aa056@chebucto.ns.ca>
|
|
|
|
Re: About the bits reserved for float variable [message #39504 is a reply to message #39498] |
Fri, 21 May 2004 08:07   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
James Kuyper writes:
> It can do that by not representing every integer value in that range. A
> 32-bit type can represent a maximum of 2^32 different values. An
> ordinary 32 bit integer type represents 2^32 consecutive integer values.
> A 32-bit IEEE format floating point number represents a slightly smaller
> set of values (because some of the bit patters represent +infinity,
> -infinity, denormalized numbers, and NaNs), but those values are very
> closely spaced near 0, and more widely spaced out the larger the values
> are, which allows them to cover a much larger dynamic range.
>
> To be specific, an IEEE format number contains a sign bit, a mantissa,
> an exponent, and has an implicit offset which is used to interpret the
> value. The value represented by such a number is
>
> (-1)^sign *(1 + mantissa/2^n)*2^(exponent+offset)
>
> where 'n' is the number of bits in the mantissa, and offset is negative.
> Note that this formula provides no way to represent 0 (the mantissa is
> never negative). As a special exception, a mantissa and exponent that
> are both zero are treated as representing 0, rather than 2^offset, which
> is what the general formula would call for.
>
> Thus, for any given value of 'k' within a certain range, this format can
> represent exactly 2^n different value x in the range 2^k <= x < 2^k+1,
> evenly spaced within that interval.
Nuno, aren't you glad you asked. :-)
This kind of answer has always fallen into the
"Too Much Information" category for me. I think of
it this way, you can have fast or accurate, but you
can't have both. That's about as much as I've ever
needed to know using a computer. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: About the bits reserved for float variable [message #39505 is a reply to message #39504] |
Fri, 21 May 2004 08:00   |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
Nuno Oliveira wrote:
> I looking at the Chapter 5 of the Bulding Aplication.
>
> It says, for float variables that it's a 32 bits number in the range of
> +/-10^38 withe approximately six or seven decimal places of significance.
> What I'm missing here? How can a number 32 bit number range between -10^38
> and +10^38?
It can do that by not representing every integer value in that range. A
32-bit type can represent a maximum of 2^32 different values. An
ordinary 32 bit integer type represents 2^32 consecutive integer values.
A 32-bit IEEE format floating point number represents a slightly smaller
set of values (because some of the bit patters represent +infinity,
-infinity, denormalized numbers, and NaNs), but those values are very
closely spaced near 0, and more widely spaced out the larger the values
are, which allows them to cover a much larger dynamic range.
To be specific, an IEEE format number contains a sign bit, a mantissa,
an exponent, and has an implicit offset which is used to interpret the
value. The value represented by such a number is
(-1)^sign *(1 + mantissa/2^n)*2^(exponent+offset)
where 'n' is the number of bits in the mantissa, and offset is negative.
Note that this formula provides no way to represent 0 (the mantissa is
never negative). As a special exception, a mantissa and exponent that
are both zero are treated as representing 0, rather than 2^offset, which
is what the general formula would call for.
Thus, for any given value of 'k' within a certain range, this format can
represent exactly 2^n different value x in the range 2^k <= x < 2^k+1,
evenly spaced within that interval.
|
|
|
|
|
Re: About the bits reserved for float variable [message #39539 is a reply to message #39504] |
Tue, 25 May 2004 10:08  |
Nuno Oliveira
Messages: 75 Registered: October 2003
|
Member |
|
|
Those were definitely careful answers. Indeed, more that I needed to know.
But anyway I enjoyed knowing all those things. And besides that it's a great
thing to know that are that like to help the others. Enchanted!, I can say.
"David Fanning" <davidf@dfanning.com> wrote in message
news:MPG.1b17c91c4c958ba1989761@news.frii.com...
>
> Nuno, aren't you glad you asked. :-)
>
> This kind of answer has always fallen into the
> "Too Much Information" category for me. I think of
> it this way, you can have fast or accurate, but you
> can't have both. That's about as much as I've ever
> needed to know using a computer. :-)
>
> Cheers,
>
> David
>
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|