comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: fixed point vs floating point
Date: 1997/11/22
Date: 1997-11-22T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680002211970739180001@news.ni.net> (raw)



Matthew asks:

<<Can you elaborate on that?  I've often observed that floating point is
used when fixed point is clearly called for, ie a bearing or latitude.
What are the specific reasons to avoid fixed point?>>

Robert replies:

<<Most obviously, on most architectures, fixed-point is drastically slower 
than flowting-point.>>


Matthew asks

<<Well, can you elaborate on that?  Isn't fixed-point arithematic
implemented using integers?  What are the specific reasons why it would
be slower?  Is it because floating point can be done in parallel on many
machines?

My real reason for all these questions is because I still don't
understand why someone declares heading as

   type Heading_In_Degrees is digits 6 range 0.0 .. 360.0;

when a better fit to the problem seems to be

   type Heading_In_Degrees is delta 0.1 range 0.0 .. 360.0;

The error in my value is the same no matter which way I'm pointing, so
why wouldn't I declare the type as a fixed point type?  However, almost
universally, programmers use a floating point type, but I suspect the
reason has nothing to do with efficiency considerations.  Any ideas?>>

Robert replies:

<<Probably this is no longer GNAT specific enough to be here, this thread
should be moved to CLA. Briefly, fpt is faster than integer because chips
are designed that way (I am specifically thinking of multiplication and
division here). Second your definition for Heading_In_Degrees is wrong,
a small of 0.0625 seems quite inappropriate. Third, I think you should
look at generated code to better undertasnd fixed-point issues.>>

Matthew replies, and then asks:

OK, OK, I was being lazy.  How about this definition of heading:

   type Heading_In_Degrees_Base is 
      delta 512.0 * System.Fine_Delta range -512.0 .. 512.0;

   subtype Heading_In_Degrees is 
      Heading_In_Degrees_Base range 0.0 .. 360.0;

Now I know on GNAT that the delta is considerably smaller than 0.0625. (I
really do wish implementations would give me extra accuracy and not extra
range.  Why do they do that?)

Anyway, I'll accept that fixed point operations are slower, but the
question remains: Why do most programmers insist on using floating point
when a fixed point better models the abstraction?  Is the reason solely
based on efficiency?

By the way, are there off-the-shelf subprograms (in Ada preferably, but I'd
take any language) for computing the elementary functions (sin, cos, etc)
of a fixed point angle?

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




             reply	other threads:[~1997-11-22  0:00 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-22  0:00 Matthew Heaney [this message]
1997-11-22  0:00 ` fixed point vs floating point Tucker Taft
1997-11-22  0:00   ` Robert Dewar
1997-11-22  0:00     ` Matthew Heaney
1997-11-23  0:00 ` Geert Bosch
1997-11-23  0:00   ` Tom Moran
1997-11-25  0:00     ` John A. Limpert
1997-11-25  0:00       ` Robert Dewar
1997-11-25  0:00       ` Robert Dewar
1997-11-23  0:00   ` Matthew Heaney
1997-11-23  0:00     ` Robert Dewar
1997-11-24  0:00       ` Herman Rubin
1997-11-24  0:00         ` Robert Dewar
1997-11-25  0:00           ` Joe Gwinn
1997-11-25  0:00             ` Matthew Heaney
1997-11-25  0:00             ` Robert Dewar
1997-11-25  0:00               ` Joe Gwinn
1997-11-25  0:00                 ` Robert Dewar
1997-11-26  0:00                   ` Joe Gwinn
1997-11-26  0:00                     ` Robert Dewar
1997-12-01  0:00                       ` Joe Gwinn
1997-12-01  0:00                         ` Robert Dewar
1997-12-01  0:00                           ` Joe Gwinn
1997-12-03  0:00                           ` robin
1997-11-26  0:00             ` William A Whitaker
1997-11-24  0:00     ` Geert Bosch
1997-11-24  0:00 ` Vince Del Vecchio
1997-11-24  0:00 ` Vince Del Vecchio
1997-12-03  0:00 ` robin
  -- strict thread matches above, loose matches on Subject: below --
2011-09-29 10:25 RasikaSrinivasan@gmail.com
2011-09-29 10:49 ` AdaMagica
2011-09-29 13:38   ` Martin
2011-09-30 10:17 ` Stephen Leake
2011-09-30 16:25   ` tmoran
2011-09-30 16:52     ` Dmitry A. Kazakov
2011-10-01 11:09     ` Stephen Leake
2011-09-30 19:26   ` tmoran
2011-09-30 22:31   ` tmoran
2011-10-01 13:37   ` RasikaSrinivasan@gmail.com
2011-10-02 14:19     ` Stephen Leake
1997-12-02  0:00 Robert Dewar
1997-12-02  0:00 ` Joe Gwinn
1997-12-02  0:00   ` Robert Dewar
1997-12-02  0:00     ` Matthew Heaney
1997-12-03  0:00       ` Robert Dewar
1997-12-03  0:00     ` Shmuel (Seymour J.) Metz
1997-12-03  0:00       ` Robert Dewar
1997-12-03  0:00       ` Matthew Heaney
1997-12-04  0:00         ` Shmuel (Seymour J.) Metz
1997-12-04  0:00           ` Robert Dewar
1997-12-03  0:00       ` Robert Dewar
1997-12-03  0:00     ` robin
1997-12-03  0:00       ` Robert Dewar
1997-12-02  0:00   ` Ken Garlington
1997-12-03  0:00     ` Joe Gwinn
1997-12-04  0:00       ` Robert Dewar
1997-12-04  0:00         ` Shmuel (Seymour J.) Metz
1997-12-03  0:00 ` robin
1997-11-28  0:00 tmoran
1997-11-28  0:00 ` Robert Dewar
1997-11-27  0:00 tmoran
1997-11-27  0:00 ` Robert Dewar
1997-11-29  0:00   ` Tarjei T. Jensen
     [not found] <9711221603.AA03295@nile.gnat.com>
1997-11-22  0:00 ` Ken Garlington
replies disabled

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