delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/08/13:16:52

From: Endlisnis AT yahoo DOT com (Rolf Campbell)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: 128 bit integer
Date: 8 Aug 2001 10:09:53 -0700
Organization: http://groups.google.com/
Lines: 33
Message-ID: <2e314290.0108080909.155b8f66@posting.google.com>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1010808155014 DOT 25973A-100000 AT is> <9krgph$496$04$1 AT news DOT t-online DOT com>
NNTP-Posting-Host: 209.202.99.50
X-Trace: posting.google.com 997290593 30618 127.0.0.1 (8 Aug 2001 17:09:53 GMT)
X-Complaints-To: groups-abuse AT google DOT com
NNTP-Posting-Date: 8 Aug 2001 17:09:53 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019