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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,6a8952cbe009f3ed X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.68.253.99 with SMTP id zz3mr264157pbc.4.1358535584109; Fri, 18 Jan 2013 10:59:44 -0800 (PST) X-Received: by 10.50.242.3 with SMTP id wm3mr1071846igc.2.1358535583877; Fri, 18 Jan 2013 10:59:43 -0800 (PST) Path: s9ni24pbb.0!nntp.google.com!ld4no9151572pbb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 18 Jan 2013 10:59:43 -0800 (PST) In-Reply-To: <3l3jf85ae05qgsl2l0avomebmg2ogl17rq@invalid.netcom.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: <4905b963-0036-4129-8050-fb26ef0154d6@googlegroups.com> <32314026-23ae-45b8-a4c5-e589e7d79de2@googlegroups.com> <3l3jf85ae05qgsl2l0avomebmg2ogl17rq@invalid.netcom.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <13febf5c-4e3c-4275-8ff4-0a3a9e885d31@googlegroups.com> Subject: Re: Numerical calculations: Why not use fixed point types for everything? From: Adam Beneschan Injection-Date: Fri, 18 Jan 2013 18:59:44 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-01-18T10:59:43-08:00 List-Id: 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. >=20 > 25 * 25 =3D> 725 >=20 > 2.5 * 2.5 =3D> 7.25 -- but if the data type is only one decimal place thi= s > now has to be rounded and shifted to become 7.3. Perhaps. But I tend to assume my computer is going to return correct arith= metical results, which none of the above are. :( In general, of course you're right that if your values aren't represented w= ith enough precision, or with a scale factor that will require rounding, yo= u're going to run into problems. But of course that's a problem with float= ing-point as well as with fixed-point. If the range of values is small eno= ugh, you can actually declare fixed-point types that have greater precision= than the available floating-point types. And how much precision is necess= ary depends on the problem domain. And there's no reason to assume that al= l 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 operand= s, and rounding can wait until the final expression result is computed. -- Adam