• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Program to calculate 2^128 accurately?

Solo177

Junior Member
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
 
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
 
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;
}
 
3849032842038432904829304823048239429348290348932420384920384092571476206829058349205820957267283583429058492358239067258349058329058320852367582394583258342905


I just did it in head.... 😉😉😉😛😛😛😛😛😛😛
 
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.


 
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... ;-)
 
Back
Top