[Issue 5971] Some BigInt ideas

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 22 00:14:37 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5971


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug at yahoo.com.au


--- Comment #2 from Don <clugdbug at yahoo.com.au> 2012-06-22 00:16:57 PDT ---
Re idea 5:

To find number of digits of x, use
p = x.ulonglength();
m = peekUlong(p-1);

then number of digits is between
lowerbound = log10(m) + p*log10(ulong.sizeof*8*2).
upperbound = log10(m+1) + p*log10(ulong.sizeof*8*2)

Make sure that there are enough digits in m that 
(upperbound-lowerbound) < 1.

Optionally use m = m*(ulong+1) + peekUlong(p-2), p-- 
to get a better value for m, which will reduce the probability that an exact
calculation must be performed.

If the range includes an exact integer (eg, the range is 1547.8 .. 1548.2) then
it's necessary to do a full calculation.

if (trunc(lowerbound) == trunc(upperbound)) return lowerbound
else
{
    y = 10^^(lowerbound+1);
    if (x < y) return lowerbound;
    return lowerbound+1;
}
The problem is, that if the number is close to 10^^d, there is no way to avoid
the full calculation. And unfortunately, although the hard case it is
numerically rare, it is a very common case in practice.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list