Program to calculate 2^128 accurately?

Solo177

Junior Member
Dec 16, 2000
19
0
0
Anyone know of a such a program that can do that calculation? Or, better yet, does anyone know how to write such a program in VB/VC++? Thanks.

-Mike
 

Adrian Tung

Golden Member
Oct 10, 1999
1,370
1
0
Well, the highest integer value that VC++ can go would be 2^32 - 1 using a DWORD. Supposedly you could write a program which uses five DWORD values to get 2^128, but you'll have to write your own class and methods to support the mathematical operations for this new data type.

On the other hand, you could try writing a BigInt class (which I think is a hot university programming question) which supports multiplication or indices.


:)atwl
 

Moohooya

Senior member
Oct 10, 1999
677
0
0
340282366920938463463374607431768211456

My quick and dirty program follows

Moohoo

#include <iostream.h>

struct BigInt
{
enum { parts = 5 };
unsigned part[parts];

BigInt (void)
{
for (int p = parts -1; p >= 0; --p)
part[p] = 0;
}

unsigned Divide (unsigned rhs)
{
unsigned __int64 remainder = 0;
for (int p = parts -1; p >= 0; --p)
{
unsigned __int64 temp = remainder * 0x100000000ui64 + part[p];
remainder = temp % rhs;
part[p] = unsigned (temp / rhs);
}

return unsigned (remainder);
}

operator bool (void) const
{
for (int p = parts -1; p >= 0; --p)
if (part[p])
return true;

return false;
}
};

main ()
{
BigInt b;
int digits[50];
b.part[4] = 1;
for (int i = 0; b; ++i)
digits = b.Divide (10);

while (--i >= 0)
cout << digits;

cout << endl;
return 0;
}
 

zzzz

Diamond Member
Sep 1, 2000
5,498
1
76
what? 2^128 is 2^128.
now solve this

x^(x^x)= (x^x)^x analytically..
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
3849032842038432904829304823048239429348290348932420384920384092571476206829058349205820957267283583429058492358239067258349058329058320852367582394583258342905


I just did it in head.... ;););):p:p:p:p:p:p:p
 

thEnEuRoMancER

Golden Member
Oct 30, 2000
1,415
0
71
zzzz:

x^(x^x)=(x^x)^x=x^(x^2) /log

log (x^(x^x))= log (x^(x^2))

x^x log x = x^2 log x

first solution: log x = 0 -> x = 1 , check: 1^(1^1) = (1^1)^1

second solution:

x^x = x^2 /log

x log x = 2 log x

assuming we already know x = 1 is one solution it's safe to divide both sides by log x and get

x = 2

So we have two solutions:

x1 = 1, x2 = 2

edit: and of course, the third solution x3 = 0 . If I remember correctly, 0^0 = 1 by definition.


 

Mday

Lifer
Oct 14, 1999
18,647
1
81
yeah argo, that is an odd number =) it ends in a 5 =)

lol

you need a lot of accuracy to calculate 2^128 correctly. one can easily calculate that with a simple program... ;-)