comp.lang.ada
 help / color / mirror / Atom feed
* Large Integers?
@ 1995-01-10 10:56 Andre Spiegel
  1995-01-10 19:47 ` Ken Anderson
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Andre Spiegel @ 1995-01-10 10:56 UTC (permalink / raw)


I am writing a network monitor program in Ada. Since, among other
things, it counts the number of bytes flowing through the cable, I'll
sooner or later run into integer overflows (the number might well
exceed 2**31-1, which is the upper limit of Natural).

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 don't think this is too difficult to implement, it would probably
take me a day or two to do it myself, but this is unfortunately
more than I have at the moment. But I assume such a thing has already
been done by someone on the net. It is critical that the package
provides all the operations in the same fashion as Ada does for
ordinary integers, because it would also take me a day or two to
change my code accordingly. I want to simply "with" and "use" the
package, replace "Natural" by "Large_Natural" (or whatever), and 
that should be it. 

Has anyone written such a package? Forgive me for being so demanding,
it's just that I think I know precisely what I need.

Thanks for any help.

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

	   e-mail: spiegel@bruessel.informatik.uni-stuttgart.de




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

* Re: Large Integers?
  1995-01-10 10:56 Large Integers? Andre Spiegel
@ 1995-01-10 19:47 ` Ken Anderson
  1995-01-10 20:45 ` Charles H. Sampson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Ken Anderson @ 1995-01-10 19:47 UTC (permalink / raw)


In comp.lang.ada you write:

>I am writing a network monitor program in Ada. Since, among other
>things, it counts the number of bytes flowing through the cable, I'll
>sooner or later run into integer overflows (the number might well
>exceed 2**31-1, which is the upper limit of Natural).

>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.

I believe

type Large_Natural is range 0 .. 2**64-1;

should do the trick if your compiler is smart enough and your machine
can handle it.

The syntax might be wrong (I don't have the ALRM handy) but I think
that gives you the idea...

Ken
--
--------------------------------------------------------------------------------
-Ken Anderson            Ken_Anderson@acm.org                       U.C. Irvine-
- "A knowledge of C is probably better than nothing." -- J.G.P. Barnes         -
--------------------------------------------------------------------------------



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

* Re: Large Integers?
  1995-01-10 10:56 Large Integers? Andre Spiegel
  1995-01-10 19:47 ` Ken Anderson
@ 1995-01-10 20:45 ` Charles H. Sampson
  1995-01-11  2:39   ` Robert Dewar
       [not found] ` <EACHUS.95Jan11095036@spectre.mitre.org>
       [not found] ` <SPIEGEL.95Jan11111040@berlin.bruessel.informatik.uni-stuttgart.de>
  3 siblings, 1 reply; 6+ messages in thread
From: Charles H. Sampson @ 1995-01-10 20:45 UTC (permalink / raw)


     Gerry Fisher published a package for doing universal (arbitrarily long)
arithmetic in the early days of Ada, either in an issue of the AdaTech news-
letter (whatever it was called) or one of the first issues of Ada Letters.
I don't have the citation available at the moment.  I could email a copy of
the package to you.

     The package is reasonably efficient but it has one drawback that Gerry
acknowledges: it leaks memory like a sieve.  That can be fixed, but it might
take more than the two days you have available.

     I have another package of my own that does 64-bit fixed-point arithme-
tic.  I think I can let you have that one too, but there's a small question
of data rights.  If you're interested, I'll check out that issue.

				Charlie



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

* Re: Large Integers?
  1995-01-10 20:45 ` Charles H. Sampson
@ 1995-01-11  2:39   ` Robert Dewar
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1995-01-11  2:39 UTC (permalink / raw)


Note that you can also find arbitrary precision integer arithmetic and
ratoinal arithmetic packages in the GNAT sources, in files uintp and
urealp respectively.




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

* Re: Large Integers?
       [not found] ` <EACHUS.95Jan11095036@spectre.mitre.org>
@ 1995-01-13 15:56   ` Andre Spiegel
  0 siblings, 0 replies; 6+ messages in thread
From: Andre Spiegel @ 1995-01-13 15:56 UTC (permalink / raw)


In article <EACHUS.95Jan11095036@spectre.mitre.org> eachus@spectre.mitre.org (Robert I. Eachus) writes:

>     If all you are doing is counting, ANY 64-bit floating point type
> will fill your needs.  Integers are always model numbers, and thus
> exact, up to 2**Float_Type'MANTISSA, which should give more than your
> required 40 bits.  You only need the ADAR packages if you need integer
> semantics for division.

  That's an interesting suggestion. I really hadn't thought of this,
probably because of a general mistrust concerning floating point
arithmetic. It's just that it requires minor changes to my I/O
routines, because I don't want the trailing ".0". So I would have to
strip it before actually writing the "Image" of the number, and supply
such a suffix before trying to read it back. A little unelegant. Or is
there any way to configure Float_IO such that it doesn't add/expect
the zero fractional part? I don't think so. It might also be a
somewhat less efficient than using an integer package.

  Thanks a lot, though. Seems like I didn't *really* know precisely
what I need...

--
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] 6+ messages in thread

* Re: Large Integers?
       [not found]   ` <3fhjr1$4h8@rational.rational.com>
@ 1995-01-18 23:22     ` Robert Dewar
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1995-01-18 23:22 UTC (permalink / raw)


Kent, do you know which compilers supported 64-bit integers, it is my
impression that yes indeed, it is true that very few 83 compilers have
such support. Of course no quarrel with your observation that this is not
a REQUIRED limitation.




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

end of thread, other threads:[~1995-01-18 23:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-01-10 10:56 Large Integers? Andre Spiegel
1995-01-10 19:47 ` Ken Anderson
1995-01-10 20:45 ` Charles H. Sampson
1995-01-11  2:39   ` Robert Dewar
     [not found] ` <EACHUS.95Jan11095036@spectre.mitre.org>
1995-01-13 15:56   ` Andre Spiegel
     [not found] ` <SPIEGEL.95Jan11111040@berlin.bruessel.informatik.uni-stuttgart.de>
     [not found]   ` <3fhjr1$4h8@rational.rational.com>
1995-01-18 23:22     ` Robert Dewar

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