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: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/22/04


Date: Tue, 22 Jun 2004 11:36:00 +0100

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
    ... Here's a decent article explaining numbers in computers in pretty simple ... >> expecting exact results every time. ... > How you regard FP numbers is an interesting point, ... > 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)
  • 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)
  • 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)