comp.lang.ada
 help / color / mirror / Atom feed
* Help on deciding a data type.
@ 1996-09-03  0:00 Sreedhar Chintalapaty
  1996-09-04  0:00 ` Stephen Bull
  0 siblings, 1 reply; 3+ messages in thread
From: Sreedhar Chintalapaty @ 1996-09-03  0:00 UTC (permalink / raw)



Hi,

I am writing an Ada program to simulate error control codes in which I
need to decide upon a data type to represent entries in the so called
Zech's Logarithm tables. These tables are of the following format:
(I am giving an actual example for whatever it is worth)
______________________________________________________________________
	LOG_A		|	LOG_A_PLUS_ONE
------------------------|---------------------------------------------
	0		|		*
	1		|		3
	2		|		6
	3		|		1
	4		|		5
	5		|		4
	6		|		2
----------------------------------------------------------------------

Except for the first entry, the numbers are all mod N, with N=7 here.
Also, the arithmetic operations (*) adn (/) are done mod N, so the
data type could be defined as
	
	type Symbol is mod N;  	-- (N = 7 here)

The problem is with the * in the first entry: Generally, it is 
represented as -1. In reality, it is indeterminate.

Is there a way to define some data type here that would let me 
exploit the modular mathematics capability of Ada while at the same
time having some representation for the * in the first entry? Or do
I have to resort to definig it as, for instance

	type Symbol is Integer range -1..N;

and write my own methods to overload the multiplication and division
functions?

I would be grateful for any help/pointers to help in this regard.

Sree

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/						 		    _/
_/ SREEDHAR CHINTALAPATY		1555, FairLane Dr. Ste.300  _/
_/ SDRC - PIM Deployment		AllenPark MI 48101 	    _/	
_/								    _/
_/ Phone: 313.317.6098       Email: Sreedhar.Chintalapaty@sdrc.com  _/
_/ WWW: http://www.ee.memphis.edu/~sreedhar/Upanisad/upanisad.html  _/
_/								    _/
_/ 		           - = o 0 o = -			    _/
_/								    _/
_/ 	  I am having amnesia and deja vu at the same time!	    _/
_/	     I think I have forgotten all this before!!		    _/
_/								    _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Help on deciding a data type.
  1996-09-03  0:00 Help on deciding a data type Sreedhar Chintalapaty
@ 1996-09-04  0:00 ` Stephen Bull
  1996-09-05  0:00   ` Robert I. Eachus
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Bull @ 1996-09-04  0:00 UTC (permalink / raw)




Sreedhar Chintalapaty <Sreedhar.Chintalapaty@sdrc.com> writes:

   Is there a way to define some data type here that would let me 
   exploit the modular mathematics capability of Ada while at the same
   time having some representation for the * in the first entry? Or do
   I have to resort to definig it as, for instance

	   type Symbol is Integer range -1..N;

   and write my own methods to overload the multiplication and division
   functions?


I would suggest defining a record type with two fields: the first is a flag
indicating whether the second is a valid value:

type T is record
  Valid : Boolean;
  Value : Symbol;
end record;

-- 
-----------------------------------------------------------------------------
 Stephen Bull  Praxis Critical Systems  20 Manvers Street  BATH  BA1 1PX  UK
    +1225 444700 (switchboard)  +1225 739286 (direct)  +1225 739281 (fax)
-----------------------------------------------------------------------------
-- 
-----------------------------------------------------------------------------
 Stephen Bull  Praxis Critical Systems  20 Manvers Street  BATH  BA1 1PX  UK
    +1225 444700 (switchboard)  +1225 739286 (direct)  +1225 739281 (fax)
-----------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Help on deciding a data type.
  1996-09-04  0:00 ` Stephen Bull
@ 1996-09-05  0:00   ` Robert I. Eachus
  0 siblings, 0 replies; 3+ messages in thread
From: Robert I. Eachus @ 1996-09-05  0:00 UTC (permalink / raw)



In article <ytc20gicxob.fsf@erlang.praxis.co.uk> sgb@erlang.praxis.co.uk (Stephen Bull) writes:

  > I would suggest defining a record type with two fields: the first is a flag
  > indicating whether the second is a valid value:

  > type T is record
  >   Valid : Boolean;
  >   Value : Symbol;
  > end record;

   There are two choices here.  The one I would recommend if
efficiency is an issue is to go through the pain of redefining all of
the operations in a generic package, then instantiating that package
for all moduli of interest.

   If however you want a simple, useable method that will never steer
you wrong try:

   type Real_Mod7 is mod 7;
   type Mod7 is access Mod7;

   Indeterminate: Mod7 := null;

   ...

   function "+" (L,R: Mod7) return Mod7 is
   begin
     return new Real_Mod7'(L.all + R.all);
   exception
     when others return Indeterminate;
   end "+";

   ...and so on.

   Notice that even on a garbage collecting Ada implementation you are
going to spend a lot of extra CPU cycles over a more sophisitcated
solution.  But you will get the correct answers.

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-09-05  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-03  0:00 Help on deciding a data type Sreedhar Chintalapaty
1996-09-04  0:00 ` Stephen Bull
1996-09-05  0:00   ` Robert I. Eachus

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