comp.lang.ada
 help / color / mirror / Atom feed
* Large Integers: Summary
@ 1995-01-18 10:59 Andre Spiegel
  0 siblings, 0 replies; only message in thread
From: Andre Spiegel @ 1995-01-18 10:59 UTC (permalink / raw)


I want to thank all those who replied -- either in this group or by
personal e-mail -- to my question concerning large integer values in 
Ada:

[...]
> Thus, I'm looking for a package that implements large positive
> integers. Range 0 .. 2**32-1 ("unsigned word") would not be enough, I'd
> rather need at least range 0 .. 2**40. An "unsigned double word" 
> (0 .. 2**64-1) would save me from overflows for a few thousand
> years.
>
> The package should simply define a new type, say "Large_Natural", and
> provide operations to add, subtract, divide and multiply the values
> (also with odinary "Naturals"), and I also want to be able to do I/O,
> using procedures with profiles identical to Integer_IO.Put and Get.
[...]
> I want to simply "with" and "use" the package, replace "Natural" by 
> "Large_Natural" (or whatever), and that should be it.


I received several pointers and also complete, ready-to-compile
packages, of which I think I can recommend most the ADAR package
mentioned by Robert I. Eachus. It can be found, for instance, in the
Public Ada Library (PAL), under languages/ada/swcomps/adar, though I
received a more recent revision directly from David Emery.

I was, however, pretty impressed by Robert I. Eachus' suggestion to
simply use long floating point values, which would provide at least
the 40 bits I needed, and even accurately, because Integers up to 
size 2**Float_Type'Mantissa are "model numbers". Of course this changes
the characteristics of particularly division operations in subtle
ways, and it also introduces the risk of _silent_ loss of precision
instead of overflows, but this doesn't matter for my type of 
application. (If I only have 40+ bits, there won't be any risk of 
overflow.) 

The only thing I had to do was to write a simple I/O package, which
provides a few similar subprograms as Text_IO.Integer_IO does, with
simply the type of the values changed to a (generic) floating point
type, like

   Put (File  : in File_Type; 
	Item  : in Float_Type; 
	Width : in Field := 0);

Those routines get and put float values with no trailing fractional
parts (".0"). It took me probably one hour to write the package (which
I can e-mail to anyone who's interested), and after that, I had to
simply "with" it, instantiate it, change my type definitions from
"Natural" to "Long_Float", and add a ".0" suffix to a few literal
numbers in the code. That was it.

I find this a rather impressing example for good software
maintainability achieved through use of Ada. (And also for quick and
easy cooperation within the Ada community!) Thanks again, also to
those not explicitly mentioned in this summary.

Regards,

--
Andre Spiegel                     |  This life is a test. It is only a test.
                                  |  Had this been an actual life, you would
University of Stuttgart, Germany  |  have received further instructions as to
Computer Science                  |  where to go and what to do.
                                                            -- Author unknown

	   email: spiegel@bruessel.informatik.uni-stuttgart.de




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-01-18 10:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-01-18 10:59 Large Integers: Summary Andre Spiegel

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