comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Numerical calculations: Why not use fixed point types for everything?
Date: Thu, 17 Jan 2013 08:25:30 -0800 (PST)
Date: 2013-01-17T08:25:30-08:00	[thread overview]
Message-ID: <4905b963-0036-4129-8050-fb26ef0154d6@googlegroups.com> (raw)
In-Reply-To: <db7b4d36-6c49-4501-954e-68ecc55c3d32@googlegroups.com>

On Thursday, January 17, 2013 2:33:28 AM UTC-8, Ada novice wrote:
> Hello,
> 
>      I have been thinking that since with floating-point representation the distribution of model numbers gets worse (more and more wider spacing) with large numbers leading to less accurate representation of a number, is it better to just go for fixed-point types e.g. in
> 
> 
> 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 distribution of the model numbers between the lower and upper bounds?
> 
> Why not just fixed-point types in numerical calculations?
> 
> And why not just use decimal fixed point types as in
> 
> type Velocity is delta 1E-10 digits 15 
> 
> for example if we know what magnitudes of the Velocity are to be expected?
> 
> I understand that it is a question of portability as well as the actual delta 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 part 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 fixed-point number that represented all those possible values would have to have a whole lot of bits.  

(2) Many processors have built-in support for mathematical functions on floating-point values (square root, trig functions, log, e**x).  If your program does lots of those, you'll probably want to use floating-point numbers instead of calling library functions to do the computation (slow) or constantly 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




  parent reply	other threads:[~2013-01-17 16:25 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-17 10:33 Numerical calculations: Why not use fixed point types for everything? Ada novice
2013-01-17 14:40 ` Nasser M. Abbasi
2013-01-17 16:16   ` Adam Beneschan
2013-01-17 17:00     ` Georg Bauhaus
2013-01-17 16:25 ` Adam Beneschan [this message]
2013-01-18  9:17   ` Ada novice
2013-01-18 17:24     ` J-P. Rosen
2013-01-18 17:52       ` Jeffrey Carter
2013-01-18 18:15     ` Dennis Lee Bieber
2013-01-18 18:59       ` Adam Beneschan
2013-01-19  4:41         ` Dennis Lee Bieber
2013-01-19  6:26           ` Jeffrey Carter
2013-01-19 14:14             ` Robert A Duff
2013-01-25 12:16               ` Paul Colin Gloster
2013-01-24 10:55             ` Ada novice
2013-01-24 11:47               ` Simon Wright
2013-01-24 14:21                 ` Ada novice
2013-01-20  0:05           ` Robin Vowels
2013-01-18 23:06       ` Robin Vowels
2013-01-18 19:09     ` Adam Beneschan
2013-01-18 21:39       ` Randy Brukardt
2013-01-19  7:02         ` Ada novice
2013-01-25 12:09         ` Paul Colin Gloster
2013-01-25 12:23     ` Paul Colin Gloster
2013-01-28  9:09       ` Ada novice
2013-02-01 10:53         ` Ada novice
2013-02-01 15:01           ` Shark8
2013-02-02 18:55             ` Ada novice
2013-02-03  4:05               ` Shark8
2013-02-04  6:23                 ` Ada novice
2013-02-04  6:43                   ` Niklas Holsti
2013-02-04  7:27                     ` Ada novice
2013-02-04  9:37                       ` Niklas Holsti
2013-02-04 10:09                         ` Ada novice
2013-02-04 14:24                           ` Niklas Holsti
2013-02-04 16:44                             ` Jeffrey Carter
2013-02-04 21:12                               ` Niklas Holsti
2013-02-04 17:31                             ` Robert A Duff
2013-02-04 21:20                               ` Niklas Holsti
2013-02-02 21:08           ` Nasser M. Abbasi
2013-02-04  6:17             ` Ada novice
2013-02-05  2:27               ` Randy Brukardt
2013-02-06  7:11                 ` Ada novice
2013-02-07  6:03                   ` Randy Brukardt
2013-02-07  8:43                     ` Shark8
2013-02-08  3:17                       ` Randy Brukardt
2013-02-08  6:20                     ` Ada novice
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox