comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: fixed point types over an interface
Date: 1997/02/07
Date: 1997-02-07T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680000702972114430001@news.ni.net> (raw)
In-Reply-To: 32FBB550.41C67EA6@efogm.msd.ray.com


In article <32FBB550.41C67EA6@efogm.msd.ray.com>, Allen Krell
<jak@efogm.msd.ray.com> wrote:

>With Ada83, is it safe to assume that two different
>compilers will store a fixed point type in the same way?

No.

The only requirment (in the absence  of a specification of small) is that
the actual delta be smaller (power of 2) less than what was specified in
the type.

If you are sending the data over an interface, it is Very Strongly
Recommended that you specify Small for the type.

Also, (I think) it's also true that a compiler is allowed to reject a
specification of small that is not a power of 2, so you're better off only
using that power (if you can).  Note that that will also be more efficient.

The syntax is

type T is delta D range F .. L;
for T'Small use D;

This specifies the value of the LSB.


>Two processors are communicating over an interface.  The
>applications for each processor are written/compiled
>using compilers from two different vendors.

A ripe environment for problems.

>
>If each application has
>
>type FX_PT_TYPE is delta .001 range -100 .. +100;
>Variable : FX_PT_TYPE := 1.345;
>
>Will the binary representation of 'Variable' 
>be the same with both compilers?

Not necessarily.  You really should do this:

F_Delta : constant := 0.001;
type F is delta F_Delta range -100.0 .. 100.0;
for F'Small use F_Delta;

And while you're at it, put a size clause on there, too.

for F'Size use 32;  -- or whatever

If possible, use a power of 2 as the delta, as it'll be more portable.

F_Delta : constant := 1.0 / 1024;

Send the data over the interface using a fixed point type with a power of 2
delta, and convert it to whatever "internal" type is appropriate (be it
another fixed point type, or more likely some floating point type) when
it's received.

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




  reply	other threads:[~1997-02-07  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-07  0:00 fixed point types over an interface Allen Krell
1997-02-07  0:00 ` Matthew Heaney [this message]
1997-02-07  0:00 ` Robert Dewar
1997-02-10  0:00   ` Mats Weber
1997-02-10  0:00     ` Robert Dewar
1997-02-11  0:00       ` nassera
1997-02-12  0:00         ` Samuel Tardieu
1997-02-12  0:00   ` Laurent Pautet
1997-02-12  0:00   ` Jon S Anthony
1997-02-12  0:00   ` Laurent Pautet
1997-02-12  0:00     ` Robert Dewar
1997-02-12  0:00       ` Mats Weber
1997-02-17  0:00     ` Jacob Sparre Andersen
1997-02-18  0:00       ` Robert Dewar
1997-02-13  0:00   ` Jon S Anthony
replies disabled

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