From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 107079,c7637cfdf68e766 X-Google-Attributes: gid107079,public X-Google-Thread: 103376,c7637cfdf68e766 X-Google-Attributes: gid103376,public X-Google-Thread: f8362,c7637cfdf68e766 X-Google-Attributes: gidf8362,public X-Google-Thread: f43e6,c7637cfdf68e766 X-Google-Attributes: gidf43e6,public X-Google-Thread: 109d8a,c7637cfdf68e766 X-Google-Attributes: gid109d8a,public From: Malome Khomo Subject: Re: floating point comparison Date: 1997/09/05 Message-ID: #1/1 X-Deja-AN: 270150890 Distribution: inet References: <5ud3mc$5d2$1@news.fsu.edu> <5uknb2$cnp$1@cnn.nas.nasa.gov> X-Sender: mkhomo@Mars.mcs.net Organization: MCSNet Services Newsgroups: comp.lang.ada,sci.math.num-analysis,comp.software-eng,comp.theory,sci.math Date: 1997-09-05T00:00:00+00:00 List-Id: On 3 Sep 1997, Chris L. Kuszmaul wrote: > In article checker@netcom.com (Chris Hecker) writes: > > > > >I don't mean to flame here, because I agree that precise terminology is > >very important, but do you guys (or anyone) actually have any useful > >and applicable hints for someone trying to make numerical code work? > > > If you are doing matrix operations, then you can get good > ... More hints for 'scalar' problems: Conversely if you are doing scalar operations and/or do not have access to canned numerical packages here are a few rules of thumb that can go a long way: 1) don't use floats to sequence with, because you have to compare them for your stopping conditions( it won't stop where you expect): NEVER this: float seq; for(seq=0.0;seq<2.0;seq+=0.1){...} RATHER this: int seq; for(seq=0;seq<20;seq+=1){...} 2) When you must compare floats for equality use integral values: double var; if( floor(var*1000)==ceil(1.23456*200) ) { ... } The expression is highly contrived for illustration purposes 3) If you are near critical regions, but must divide, consider using type systems that support arbitrary precision. presumably you do not need high precision _all_ the time. These 'side' computations need special handling, usually separate link and programing to integrate the result back into your floating point 'scalar' computation. 4) If you really must you can even use an arithmetic package that performs exact arithmetic ( +, * and - are always so; exact here mean zero-remainder division over rationals). Do not try this on irrationals so if square root or some such thing features in your computation, go back and study numerical techniques. 5) The primary goal of all the numerical methods is to converge most rapidly to the desired solution. Try to understand what your process is achieving and evaluate the benefit/cost of improving the algorithm. As two extreme examples if you are servicing a joy-stuck gammer with graphics, it's not worth the trouble getting an exact value for a frame that will flash by and be forgotten. If on the other hand you're to guide the MIR crew home, I'd pull all the stops and get exactitude! 6) I hope you're also aware that anything you do outside the FPU will generally slow your computations by _many_ orders of magnitude. The above may be obvious to most but I hope its helpful. Malome Khomo