[NTLUG:Discuss] The wrong computation example from the newsgroup

sysmail@glade.net sysmail at glade.net
Mon Mar 19 12:04:43 CST 2001


You know, an easy way to fix is to just add .5 before any cast to int...


On Mon, 19 Mar 2001, Christopher Browne wrote:

> On Mon, 19 Mar 2001 14:37:34, the world broke into rejoicing as
> "m m" <llliiilll at hotmail.com>  said:
> > you guys are so smart, know all the details of these stuff, and do not think
> > it is a problem (because of the architecture of computer, the complier....)
> > Question here:  for those who are not a programmer or just know how to use
> > computer, Linux can still be trusted? (remember back to the first message of
> > this thread, the author said some thing like "it only happen on Linux
> > distros....")
> > in other words, if I am going to use Linux for business, and I have do
> > computation like the example, and I got wrong result. I think it may not
> > acceptable, people are looking for a reliable computers (OSs). shouldn't
> > this problem be fixed? (remember it only happen on Linux box)
> > Don't upset, I am just in the view point of a regular user.
>
> The essential problem here is that floating point computations are somewhat
> "fuzzy."  This has always been true; there is an area of computer science
> called "numerical analysis" that concentrates on this.
>
> The computation in question is one where the _exact_ answer is 10.  But
> since the intermediate values are _NOT_ exact, and the final step of the
> computation is to round down to the nearest integer, there is no guarantee
> that different systems will necessarily get exactly the same answer.
>
> Suppose on one system the answer that gets calculated is 10.0000001235.
> Round that down, and you get 10.  And you and I can look at that and say
> that seems AOK.
>
> On another system, or with a different calculation, you might get as a
> result the value 9.9999999712341.  That is very near to 10, but when the
> value gets rounded _DOWN_ to the nearest integer, the result is 9.
>
> Now, the odd-ball thing that is popping up in this particular situation is
> that on the same system, two ways are being used to calculate the value
> (that should be about 10.0000000000, more or less).  Those two ways
> _appear_ the same, but are coming up with very slightly different
> results.  The fact of there being a difference is somewhat peculiar.
>
> But there is the common fact that these calculations are _fuzzy_, due to
> using float values, and so cannot be trusted.
>
> That issue has nothing to do with Linux.  If floating point calculations
> are run on Linux, or Windows, or MVS, or VMS, or on whatever kind of system
> you care to name, there is the very same issue that they are fuzzy, and
> must not be trusted too much.  FP calculations were fuzzy and needed
> to be managed carefully back in the 1960s, when they were a new idea.
> They were fuzzy and needed to be managed carefully back in the 1970s,
> when they were a little less new.  They are fuzzy and need to be managed
> carefully today, when people have this notion that with smart enough
> development environments, anyone capable of reading "X in 24 hours"
> can become a programmer.
>
> They will be fuzzy and competent use of FP will require understanding
> something of numerical analysis 20 years from now. And 20 years from
> now, miscomputation of some similar calculation will surprise the vast
> majority of people that have never been trained in numerical analysis.
> --
> (concatenate 'string "aa454" "@freenet.carleton.ca")
> http://www.ntlug.org/~cbbrowne/internet.html
> "90% of the ideas people bring to  me are no good.  So if I reject all
> of them I've got a pretty good batting average" -- Sam Goldwyn (MGM)
> _______________________________________________
> http://ntlug.org/mailman/listinfo/discuss
>




More information about the Discuss mailing list