Re: Floating point rounding error



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.

.



Relevant Pages

  • Re: Floating point rounding error
    ... Floating point rounding error's a cool scene! ... Is this rule of representing decimals in binary applicable only to ... This doesn't represent decimals. ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)
  • Re: Non-terminating numbers
    ... In fact, "non-terminating" is not a property of the number itself, ... but of the decimal method of representing it. ... to the Greeks, Egyptians, Chinese, Indians, Persians, Arabs, etc. ... before "decimals" were used to represent non-integers. ...
    (sci.math)
  • Re: What is wrong with BitArray.CopyTo()?
    ... decimal value is done different in mainframes than in a microprocessor. ... representing a value as far as I remember me ... decimals, while it also had hardware instructions with 3 adresses so you had ...
    (microsoft.public.dotnet.general)
  • Re: What is wrong with BitArray.CopyTo()?
    ... decimal value is done different in mainframes than in a microprocessor. ... representing a value as far as I remember me ... decimals, while it also had hardware instructions with 3 adresses so you had ...
    (microsoft.public.dotnet.framework)
  • Re: A wrong calculation by excel
    ... This so-called error is the result of the computer converting decimals ... Floating-point arithmetic may give inaccurate results in Excel ... Tutorial to Understand IEEE Floating-Point Errors ...
    (microsoft.public.excel.misc)