comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: What about big integers in Ada 2005?
Date: 04 Oct 2005 15:44:53 -0400
Date: 2005-10-04T15:44:53-04:00	[thread overview]
Message-ID: <wcck6gtcbii.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: Hhd+t5UnRx8i@eisner.encompasserve.org

clubley@remove_me.eisner.decus.org-Earth.UFP (Simon Clubley) writes:

> > I think the only reason to use BCD these days (instead of binary) is to
> > interface to something that uses BCD.  In the old days, another reason
> > was to avoid the cost of converting strings to binary integers and
> > vice-versa, but that seems like an obsolete reason at this 
> > 
> > Am I right?
> 
> How would you choose to implement big number packages ?

I have implemented such a thing, and I used all manner of low-level
trickery to make it efficient.  Of course what's "efficient" depends on
typical usage patterns, such as:

    1. Almost all numbers are small (fit comfortably in one machine
       word).

    2. Extremely large numbers are common.  Lots of arithmetic,
       comparisons, etc.

    3. Not so much arithmetic, etc.  Lots of conversions back and forth
       to human-readable text strings.

My scanario was number 1.  I won't go into all the details, but
basically a big int is a word, containing a small number, plus
some flag bits, or a pointer to a big number, plus some flag bits.
The pointer points to a heap-allocated array of "super digits".
Each super digit is half a 32-bit word.  In other words,
we're using base 2**16.

It would be more efficient to use base 2**32, but that would have
required non-portable machine code inserts or something, because Ada
doesn't give access to the necessary machine instructions (double-length
multiply, for example).

For scenario 2, I suppose the small-int hack would be a waste -- just
make it a pointer to the array.

For scenario 3, base 1_000_000_000 would be more efficient.
Or base 10_000, if you're doing the half-word thing.

I still don't see a really good reason to use base 10.

- Bob



  reply	other threads:[~2005-10-04 19:44 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-15 17:06 What about big integers in Ada 2005? jtg
2005-09-15 17:26 ` Pascal Obry
2005-09-15 17:30   ` Martin Dowie
2005-09-15 17:26 ` Martin Krischik
2005-09-15 19:37   ` Martin Dowie
2005-09-15 21:08     ` Larry Kilgallen
2005-09-15 20:33   ` jtg
2005-09-15 21:10     ` Larry Kilgallen
2005-09-18  0:46   ` adaworks
2005-09-30 17:41     ` Robert A Duff
2005-09-30 20:18       ` Jeffrey R. Carter
2005-10-02  0:27       ` adaworks
     [not found]         ` <imsuj1h8vevg4un71rmh0nc41pnee5ihjl@4ax.com>
2005-10-02 10:33           ` Martin Krischik
2005-10-02 16:20             ` adaworks
2005-10-04  5:24           ` adaworks
2005-10-04  7:22             ` tmoran
2005-10-04  8:25             ` Dmitry A. Kazakov
2005-10-04 11:57               ` Simon Clubley
2005-10-04 16:10                 ` Robert A Duff
2005-10-04 17:24                   ` Simon Clubley
2005-10-04 19:44                     ` Robert A Duff [this message]
2005-10-04 13:46               ` adaworks
2005-10-04 16:38                 ` Robert A Duff
2005-10-04 16:52                   ` Martin Dowie
2005-10-04 17:16                     ` Robert A Duff
2005-10-04 13:50               ` adaworks
2005-10-04 14:59                 ` Larry Kilgallen
2005-10-04 16:03                 ` Robert A Duff
2005-10-04 18:56                   ` adaworks
2005-10-10  5:36                     ` Dave Thompson
2005-10-14  0:31                       ` adaworks
2005-10-06 14:21             ` Adrian Hoe
2005-10-07  6:48               ` Martin Krischik
2005-10-02  0:48   ` Brian May
2005-10-02 10:28     ` Martin Krischik
2005-10-02 10:52       ` Brian May
2005-10-02 15:12       ` Simon Wright
2005-10-02 17:11         ` Martin Dowie
2005-09-16 14:33 ` gautier_niouzes
2005-09-17  3:43   ` Craig Carey <research@ijs.co.nz>
replies disabled

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