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.224.192.199 with SMTP id dr7mr3505867qab.4.1358439931009; Thu, 17 Jan 2013 08:25:31 -0800 (PST) X-Received: by 10.49.87.9 with SMTP id t9mr1326321qez.16.1358439930896; Thu, 17 Jan 2013 08:25:30 -0800 (PST) Path: k2ni675qap.0!nntp.google.com!p13no1031495qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 17 Jan 2013 08:25:30 -0800 (PST) In-Reply-To: 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: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4905b963-0036-4129-8050-fb26ef0154d6@googlegroups.com> Subject: Re: Numerical calculations: Why not use fixed point types for everything? From: Adam Beneschan Injection-Date: Thu, 17 Jan 2013 16:25:30 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-01-17T08:25:30-08:00 List-Id: On Thursday, January 17, 2013 2:33:28 AM UTC-8, Ada novice wrote: > Hello, >=20 > I have been thinking that since with floating-point representation t= he distribution of model numbers gets worse (more and more wider spacing) w= ith large numbers leading to less accurate representation of a number, is i= t better to just go for fixed-point types e.g. in >=20 >=20 > type Position is delta 1.0**(-12) range 0.0 to 100_000 This must be a typo ... 1.0**(-12) is just 1, isn't it? > and define every variable similarly so that we have an equally spaced dis= tribution of the model numbers between the lower and upper bounds? >=20 > Why not just fixed-point types in numerical calculations? >=20 > And why not just use decimal fixed point types as in >=20 > type Velocity is delta 1E-10 digits 15=20 >=20 > for example if we know what magnitudes of the Velocity are to be expected= ? >=20 > I understand that it is a question of portability as well as the actual d= elta that would be used would perhaps not be the same for all machines and = for all compilers. I can think of two reasons why using floating-point may be better, but this= depends on the application: (1) Floating-point numbers have a greater range, because the exponent is pa= rt of the number. Thus, an IEEE 64-bit floating-point value can represent = positive numbers as large as 1.7*10**308 or as small as 2.2*10**(-308); a f= ixed-point number that represented all those possible values would have to = have a whole lot of bits. =20 (2) Many processors have built-in support for mathematical functions on flo= ating-point values (square root, trig functions, log, e**x). If your progr= am does lots of those, you'll probably want to use floating-point numbers i= nstead of calling library functions to do the computation (slow) or constan= tly converting back and forth between fixed- and floating-point. If neither of those is an issue, then it may be better to use fixed point. -- Adam