Mail Archives: djgpp/2001/08/08/13:16:52
Kai Dietrich <toepferei DOT dietrich AT t-online DOT de> wrote in message news:<9krgph$496$04$1 AT news DOT t-online DOT com>...
> Hmm, obviosly I havn't said enough. GMP is not exactly what I
> want. I need a constant size like
> class int128
> {
> public:
> long long v[2];
> };
[snip]
> I want the solution to behave like long long but with 128 bits
> (256 or more would be OK, too) instead of 64. I know that it is
> possible, it is the same solution like getting long long working
> on a 32bit machine. I would be able to combined two long long
> but I can only write + not - :-(. I need a little bit help
> writing
> int128 add( int128 a, int128 b);
> int128 sub( int128 a, int128 b);
Well, if you are going to use classes, you might as well use operators, so:
int128 operator - (const int128& a, const int128& b)
{
return a + -b;
}
Then implement unary minus something like (warning: untested code):
int128 operator - (const int128& b)
{
int128 ret(b);
ret.v[0] = ~ret.v[0];
ret.v[1] = ~ret.v[1];
return ret+1;
}
- Raw text -