Re: Floating point rounding error
- From: Mukesh_Singh_Nick@xxxxxxxxx
- Date: Sat, 16 Jun 2007 05:07:47 -0700
On Jun 16, 4:53 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
Mukesh_Singh_N...@xxxxxxxxx said:
<snip>
I know binary arithmetic with integrals. I sometimes wondered and
never bothered myself as to how decimals were represented as binaries.
The representation of floating-point numbers is implementation-defined.
IEEE 754 is common but not universal.
I want to understand your example.
I can see a pattern in the representation.
0.1 is half.
0.01 is a right shift and you further halve it.
0.001 two right shifts further halving it and so on.
You lost me at 0.011. Can I please request you to explain.
You understand binary integers. Extend the concept.
13 in binary is 1101 (1 * eight + 1 * four + 0 * two + 1 * one).
So each column represents a multiplier half as big as that of the column
to its left.
So we might reasonably think of the columns beyond the binary point as
representing a half, a quarter, an eighth, etc.
So 0.11 would be (half + quarter) = (three-quarters) = 0.75
0.011 would be (quarter + eighth) = (three-eighths) = 0.375
and so on.
That isn't necessarily how they're stored internally, of course, but it
does give you a good idea of the number of bits you need for storing a
particular value to a particular precision. I recommend that you readhttp://docs.sun.com/source/806-3568/ncg_goldberg.html
(Title: "What Every Computer Scientist Should Know About Floating-Point
Arithmetic")
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
email: rjh at the above domain, - www.
Thank you so very much, Richard. You just taught me something
*fantabulous*. I just learnt something terrific, something I could not
have learnt reading a thousand words. Actually, I think I've just
understood the IEEE 754-1985 implementation in a nutshell.
Is this rule of representing decimals in binary applicable only to
754?
And then I revisited your previous table wherein you try to reach a
precision for 1234.12345678 by heuristic computation. It suddenly
removed a big block in my head.
Thank you, everyday.
.
- Follow-Ups:
- Re: Floating point rounding error
- From: Peter 'Shaggy' Haywood
- Re: Floating point rounding error
- References:
- Floating point rounding error
- From: Mukesh_Singh_Nick
- Re: Floating point rounding error
- From: Richard Heathfield
- Re: Floating point rounding error
- From: Mukesh_Singh_Nick
- Re: Floating point rounding error
- From: Richard Heathfield
- Floating point rounding error
- Prev by Date: Re: Floating point rounding error
- Next by Date: Re: Meaning of "most significant digits" in the printf documentation
- Previous by thread: Re: Floating point rounding error
- Next by thread: Re: Floating point rounding error
- Index(es):
Relevant Pages
|