Re: Floating Point (was Non-strictly Weak Sorting using STL?)
On Jan 11, 9:04 pm, Andy Champ <no....@nospam.com> wrote:
peter koch wrote:
On 9 Jan., 23:49, Andy Champ <no....@nospam.com> wrote:
peter koch wrote:
On 9 Jan., 21:22, Andy Champ <no....@nospam.com> wrote:
Actually, I do have a relevant point.
No.
He said "Specifically, I wish to
sort these objects by a double field unless they are equal". I wish t=
o
point out that "equal" is not a reliable measure for floating point
numbers.
That is wrong.
Only when he has answered that is it worth considering
strictly weak ordering and the secondary key.
And this is also wrong.
I don't want to start a flame-fest here Peter, but it's
generally known that a floating point number is an
approximation to an actual value.
I don't know where it is "generally known"; all of the experts I
know seem to concure that a floating point number exactly
represents a specific value. It may not be the value you want,
but that's another problem; if you know what you're doing, in
many applications, you can ensure that it is the value you want.
Perhaps you'd like to explain to us what floating point system
is able to accurately express the precise value of 1/3?
All of the ones I know can: the exact value of 1/3 is 0 (at
least in C++), and all of the floating point representations I
know are capable of exactly representing 0.
And what will the result be if you double it?
0. While floating point arithmetic differs in a lot of aspects
from real arithmetic, 0 does behave the same in both of them.
And if you subtract 1/3 from 1, how it will compare to the
previous result?
With what previous results. 1-1/3 is 1.
But perhaps you meant 1.0/3.0. In that case, of course, all of
the answers are implementation defined. But precisely defined.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34