No apologies necessary. I didn't want the OP to get confused since the issue
you raised requires an understanding of FP representation that it was clear
the OP didn't have.
I'm just jealous I didn't think of doing the same thing (I'll lay the blame
on being chronically sleep-deprived these days).
Colin
"Stu Smith" <stuarts@nospam-digita.com> wrote in message
news:uxWgVHDWEHA.4092@TK2MSFTNGP11.phx.gbl...[color=blue]
>
> "Colin Young" <x@nospam.com> wrote in message
> news:u99R3o7VEHA.3696@TK2MSFTNGP10.phx.gbl...[color=green]
> > I just assumed he had picked those numbers at random. It wasn't entirely
> > clear from his post if he was genuinely curious, or just being a[/color]
> smart-ass.[color=green]
> > I figured the OP could use the links I provided since it seems that[/color][/color]
their[color=blue][color=green]
> > code isn't dealing with numbers that are guaranteed to be exactly
> > representable (as does the code most of us probably write).[/color]
>
> Apologies, it was smart-ass-ness. It was just that chap said you "CAN'T"[/color]
get[color=blue]
> exact results from floating point, which to me seems just as inaccurate as
> expecting exact results every time. Some numbers can be represented[/color]
exactly,[color=blue]
> and some (most!) numbers can't be. Obviously all FP numbers are exact
> numbers themselves; it's the FP operations which give mathematically[/color]
inexact[color=blue]
> results at certain (but not all) times.
>
> I'll try to hold back a bit on the nit-picking next time,
> Stu
>[color=green]
> >
> > Colin
> >
> > "Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
> > news:MPG.1b40fe2919e247e798ad22@msnews.microsoft.c om...[color=darkred]
> > > Colin Young <x@nospam.com> wrote:
> > > > See e.g.:
> > > >
> > > >
http://www.math.grin.edu/~stone/cour...EEE-reals.html
> > > >
> > > >[/color][/color][/color]
http://research.microsoft.com/~holla...ieeefloat.html[color=blue][color=green][color=darkred]
> > > >
> > > > A quick google search on IEEE floating point will turn up lots more[/color]
> > info.[color=darkred]
> > > >
> > > > If you need to represent exact numbers (e.g. financial calcs where[/color][/color][/color]
you[color=blue][color=green]
> > can't[color=darkred]
> > > > just drop a penny here and there) use System.decimal, but note that[/color][/color][/color]
it[color=blue][color=green]
> > will[color=darkred]
> > > > only work with numbers that you can write down exactly (e.g. 1/3[/color][/color][/color]
can't[color=blue][color=green]
> > be[color=darkred]
> > > > represented exactly in decimal or float).
> > >
> > > That doesn't answer Stu's question though. He's absolutely right -
> > > calculations involving things like 0.5 and 0.75 may well be[/color][/color][/color]
represented[color=blue][color=green][color=darkred]
> > > exactly.
> > >
> > > Note that decimal floating point doesn't fundamentally represent
> > > numbers exactly in a way that binary floating point can't - it's just[/color][/color][/color]
a[color=blue][color=green][color=darkred]
> > > different base, so more numbers are exactly representible.
> > >
> > > See
http://www.pobox.com/~skeet/csharp/floatingpoint.html and
> > >
http://www.pobox.com/~skeet/csharp/decimal.html for more info.
> > >
> > > --
> > > Jon Skeet - <skeet@pobox.com>
> > >
http://www.pobox.com/~skeet
> > > If replying to the group, please do not mail me too[/color]
> >
> >[/color]
>
>[/color]