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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: num2.nntp.dca.giganews.com!num1.nntp.dca.giganews.com!number.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 18 Jan 2013 22:41:06 -0600 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: Numerical calculations: Why not use fixed point types for everything? Date: Fri, 18 Jan 2013 23:41:15 -0500 Organization: > Bestiaria Support Staff < Message-ID: References: <4905b963-0036-4129-8050-fb26ef0154d6@googlegroups.com> <32314026-23ae-45b8-a4c5-e589e7d79de2@googlegroups.com> <3l3jf85ae05qgsl2l0avomebmg2ogl17rq@invalid.netcom.com> <13febf5c-4e3c-4275-8ff4-0a3a9e885d31@googlegroups.com> X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 76.249.25.55 X-Trace: sv3-xPcwufxYAA2qDj2CT3WcJ1vw9Z1UMG9Z64PsllgHlgmtHuthAZwmP+X+8vaoxkqjUdORw2aYuUYC2M7!OLoSPmFIXOYL4p/YP4nEeG8cESVFtIuHok7/2TpYXPR5UrfziNJ/cJQh0qJSjFvZZC9eKYoxmwaX!hXJDk9Es+S8giKe7AfIpFDLH6OrUQifhwMbNq9Ff X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3512 Xref: number.nntp.dca.giganews.com comp.lang.ada:179981 Date: 2013-01-18T23:41:15-05:00 List-Id: On Fri, 18 Jan 2013 10:59:43 -0800 (PST), Adam Beneschan declaimed the following in comp.lang.ada: > On Friday, January 18, 2013 10:15:06 AM UTC-8, Dennis Lee Bieber wrote: > > > Integer operations may be faster than floating point... But fixed > > point with a non-zero decimal place add in the overhead of having to > > track where the point is and shifting results to match the declared data > > type. > > > > 25 * 25 => 725 > > > > 2.5 * 2.5 => 7.25 -- but if the data type is only one decimal place this > > now has to be rounded and shifted to become 7.3. > > Perhaps. But I tend to assume my computer is going to return correct arithmetical results, which none of the above are. :( > Okay... I carried one extra for the leading digit... > In general, of course you're right that if your values aren't represented with enough precision, or with a scale factor that will require rounding, you're going to run into problems. But of course that's a problem with floating-point as well as with fixed-point. If the range of values is small enough, you can actually declare fixed-point types that have greater precision than the available floating-point types. And how much precision is necessary depends on the problem domain. And there's no reason to assume that all values in your program have to have the same scale factor--in fact, Ada's definition of fixed-point multiplication and division operations supports cases where an intermediate result may have more precision than the operands, and rounding can wait until the final expression result is computed. My emphasis was that, lacking true hardware fixed point operations, the compiler has to track the position of the implied point and insert operations to (for lack of better term) normalize the results back into the declared type. Those the negative impact of those normalization instructions may cancel out any expected gain from using integer arithmetic operations. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/