Re: why Math.Log(8,2) is 2.9999999999999996 and not 3

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Colin Young (x_at_nospam.com)
Date: 06/22/04


Date: Tue, 22 Jun 2004 11:11:13 -0400

Here's a decent article explaining numbers in computers in pretty simple
terms: http://www.sybase.com/detail?id=1012599. I'm including it for
completeness for interested observers, not that I think Mr. Smith or Mr.
Skeet need this explained to them (I have a naive hope that people having
trouble with floating point will do a google search first and find this
thread archived).

I've actually never really completely understood the whole decimal thing. I
blame it on my engineering education. As far as I'm concerned 1.24e4 +
9.3e-1 = 1.24e4, but just try telling an accountant that 93 cents can just
be ignored.

Colin

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1b421be616c5d79098ad36@msnews.microsoft.com...
> Stu Smith <stuarts@nospam-digita.com> wrote:
> > Apologies, it was smart-ass-ness. It was just that chap said you "CAN'T"
get
> > exact results from floating point, which to me seems just as inaccurate
as
> > expecting exact results every time. Some numbers can be represented
exactly,
> > and some (most!) numbers can't be. Obviously all FP numbers are exact
> > numbers themselves; it's the FP operations which give mathematically
inexact
> > results at certain (but not all) times.
>
> How you regard FP numbers is an interesting point, actually. You can
> either regard them as exact numbers which are within a certain distance
> of the last calculation, or you can regard them as a range in and of
> themselves. I've never been entirely certain which is the best way of
> thinking of them - I suspect it depends on the situation.
>
> My point about decimal vs double is an important one though - people
> tend to think of decimals as "exact" and doubles as "rough" when
> there's no such distinction in reality - they have different bases,
> levels of precision and scale ranges, but they're fundamentally much
> more similar than they're usually portrayed.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Relevant Pages

  • Re: why Math.Log(8,2) is 2.9999999999999996 and not 3
    ... > expecting exact results every time. ... How you regard FP numbers is an interesting point, ... tend to think of decimals as "exact" and doubles as "rough" when ... levels of precision and scale ranges, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Loss of Bargain.
    ... bargain, would I have to buy the exact same product elsewhere, or will a ... suitable alternative (with regard to parts included, warranty, price, ...
    (uk.legal)
  • Re: What, me worry?
    ... The exact number depends on whether you regard the ... Confederate States of America as part of the US. ...
    (rec.arts.sf.fandom)
  • Re: Loss of Bargain.
    ... bargain, would I have to buy the exact same product elsewhere, or will a ... suitable alternative (with regard to parts included, warranty, price, ...
    (uk.legal)
  • camping around loch lomond
    ... regard to wild camping ....??? ... no-one seems to be exact on what the rules are- ... thanks in anticipation - Valerie ...
    (uk.rec.camping)