コード例 #1
0
ファイル: cifs.c プロジェクト: Nurb432/plan9front
CIFStreeconnect(Session *s, char *cname, char *tree, Share *sp)
{
	int len;
	char *resp, *path;
	char zeros[24];
	Pkt *p;

	resp = Sess->auth->resp[0];
	len  = Sess->auth->len[0];
	if((s->secmode & SECMODE_USER) != SECMODE_USER){
		memset(zeros, 0, sizeof zeros);
		resp = zeros;
		len = sizeof zeros;
	}

	p = cifshdr(s, nil, SMB_COM_TREE_CONNECT_ANDX);
	p8(p, 0xFF);			/* Secondary command */
	p8(p, 0);			/* Reserved */
	pl16(p, 0);			/* Offset to next Word Count */
	pl16(p, 0);			/* Flags */

	if((s->secmode & SECMODE_PW_ENCRYPT) == 0){
		pl16(p, len+1);		/* password len, including null */
		pbytes(p);
		pascii(p, resp);
	}else{
		pl16(p, len);
		pbytes(p);
		pmem(p, resp, len);
	}

	path = smprint("//%s/%s", cname, tree);

	ppath(p, path);			/* path */
	free(path);

	pascii(p, "?????");		/* service type any (so we can do RAP calls) */

	if(cifsrpc(p) == -1){
		free(p);
		return -1;
	}
	g8(p);				/* Secondary command */
	g8(p);				/* Reserved */
	gl16(p);			/* Offset to next command */
	sp->options = g8(p);		/* options supported */
	sp->tid = p->tid;		/* get received TID from packet header */
	free(p);
	return 0;
}
コード例 #2
0
ファイル: tailcall-8-run.c プロジェクト: MaxKellermann/gcc
int
main (void)
{
  struct s g6_s = { 106 };

  start (1, 0);
  g1 (tmp);

  start (2, 0);
  g2 (&tmp);

  start (3, 0);
  g3 (&tmp);

  start (4, 0);
  g4 (&tmp);

  start (5, 0);
  g5 (tmp);

  start (6, &g6_s);
  g6 (tmp);

  start (7, 0);
  g7 (tmp);

  start (8, 0);
  g8 (&tmp);

  start (9, 0);
  g9 (&tmp);

  return 0;
}
コード例 #3
0
ファイル: color.hpp プロジェクト: maxteufel/supertux
 inline uint32_t rgba() const
 {
   return ((a8() << 24) |
           (b8() << 16) |
           (g8() <<  8) |
           (r8() <<  0));
 }
コード例 #4
0
bool sanity()
{  
   GameState g0(5, 7, 7);    // Not a valid game state 
   GameState g1(1, 2, 254);  // Finish in 1 round
   GameState g2(2, 3, 254);  //   ...  in 2 rounds
   GameState g3(3, 4, 254);  //   ...  in 3 rounds
   GameState g4(4, 5, 254);  //
   GameState g5(4, 9, 254);  // These come from a (slower) python implementation
   GameState g6(8, 11, 254);
   GameState g7(12, 19, 254);
   GameState g8(8, 35, 254);
   
   GameState g9(1, 4, 6);   // From webpage, known to finish in 15 minutes = at round 2
   
   if (explore_game(g0)!=0) return false; // Verify that we get the expected number
   if (explore_game(g1)!=1) return false; // of rounds for given input states
   if (explore_game(g2)!=2) return false; //
   if (explore_game(g3)!=3) return false; // report an error if not
   if (explore_game(g4)!=4) return false;
   if (explore_game(g5)!=5) return false;
   if (explore_game(g6)!=6) return false;
   if (explore_game(g7)!=7) return false;
   if (explore_game(g8)!=8) return false;
   if (explore_game(g9)!=2) return false;
   
   return true;
}
コード例 #5
0
ファイル: mywidget.cpp プロジェクト: gehirn/lab3
qreal MyWidget::g(qreal x, qreal y, qreal z)
{
    switch (variant)
    {
    case 5: return g5(x, y, z);
    case 8: return g8(x, y, z);
    }
    return 0;
}
コード例 #6
0
ファイル: altivec-cell-2.C プロジェクト: 0day-ci/gcc
int main1(void)
{ 
  int i;
  /* Check vec_extract with a non constant element numbering */
  for(i=0;i<10;i++)
    { 
      if (f(a, i) != (i&0x3))
        abort ();
    }
  
  /* Check vec_extract with a constant element numbering */
  if (f0(a) != 0)
    abort ();
  if (f1(a) != 1)
    abort ();
  if (f2(a) != 2)
    abort ();
  if (f3(a) != 3)
    abort ();
  /* Check that vec_extract works with a constant element higher than
     the number of elements.  */
  if (f4(a) != 0)
    abort ();

  /* Check vec_extract with a non constant element numbering */
  for(i=0;i<10;i++)
    {
      if (g(b, i) != (i&0x7))
        abort ();
    }
  
  /* Check vec_extract with a constant element numbering */
  if (g0(b) != 0)
    abort ();
  if (g1(b) != 1)
    abort ();
  if (g2(b) != 2)
    abort ();
  if (g3(b) != 3)
    abort ();
  if (g4(b) != 4)
    abort ();
  if (g5(b) != 5)
    abort ();
  if (g6(b) != 6)
    abort ();
  if (g7(b) != 7)
    abort ();
  /* Check that vec_extract works with a constant element higher than
     the number of elements.  */
  if (g8(b) != 0)
    abort ();
  
  return 0;
}
コード例 #7
0
ファイル: cifs.c プロジェクト: Nurb432/plan9front
int
CIFSsession(Session *s)
{
	char os[64], *q;
	Rune r;
	Pkt *p;
	enum {
		mycaps = CAP_UNICODE | CAP_LARGE_FILES | CAP_NT_SMBS |
			CAP_NT_FIND | CAP_STATUS32,
	};

	s->seqrun = 1;	/* activate the sequence number generation/checking */

	p = cifshdr(s, nil, SMB_COM_SESSION_SETUP_ANDX);
	p8(p, 0xFF);			/* No secondary command */
	p8(p, 0);			/* Reserved (must be zero) */
	pl16(p, 0);			/* Offset to next command */
	pl16(p, MTU);			/* my max buffer size */
	pl16(p, 1);			/* my max multiplexed pending requests */
	pl16(p, 0);			/* Virtual connection # */
	pl32(p, 0);			/* Session key (if vc != 0) */


	if((s->secmode & SECMODE_PW_ENCRYPT) == 0) {
		pl16(p, utflen(Sess->auth->resp[0])*2 + 2); /* passwd size */
		pl16(p, utflen(Sess->auth->resp[0])*2 + 2); /* passwd size (UPPER CASE) */
		pl32(p, 0);			/* Reserved */
		pl32(p, mycaps);
		pbytes(p);

		for(q = Sess->auth->resp[0]; *q; ){
			q += chartorune(&r, q);
			pl16(p, toupperrune(r));
		}
		pl16(p, 0);

		for(q = Sess->auth->resp[0]; *q; ){
			q += chartorune(&r, q);
			pl16(p, r);
		}
		pl16(p, 0);
	}else{
		pl16(p, Sess->auth->len[0]);	/* LM passwd size */
		pl16(p, Sess->auth->len[1]);	/* NTLM passwd size */
		pl32(p, 0);			/* Reserved  */
		pl32(p, mycaps);
		pbytes(p);

		pmem(p, Sess->auth->resp[0], Sess->auth->len[0]);
		pmem(p, Sess->auth->resp[1], Sess->auth->len[1]);
	}

	pstr(p, Sess->auth->user);	/* Account name */
	pstr(p, Sess->auth->windom);	/* Primary domain */
	pstr(p, "plan9");		/* Client OS */
	pstr(p, argv0);			/* Client LAN Manager type */

	if(cifsrpc(p) == -1){
		free(p);
		return -1;
	}

	g8(p);				/* Reserved (0) */
	gl16(p);			/* Offset to next command wordcount */
	Sess->isguest = gl16(p) & 1;	/* logged in as guest */

	gl16(p);
	gl16(p);
	/* no security blob here - we don't understand extended security anyway */
	gstr(p, os, sizeof os);
	s->remos = estrdup9p(os);

	free(p);
	return 0;
}
コード例 #8
0
ファイル: cifs.c プロジェクト: Nurb432/plan9front
/*
 * Some older servers (old samba) prefer to talk older
 * dialects but if given no choice they will talk the
 * more modern ones, so we don't give them the choice.
 */
int
CIFSnegotiate(Session *s, long *svrtime, char *domain, int domlen, char *cname,
	int cnamlen)
{
	int d, i;
	char *ispeak = "NT LM 0.12";
	static char *dialects[] = {
//		{ "PC NETWORK PROGRAM 1.0"},
//		{ "MICROSOFT NETWORKS 1.03"},
//		{ "MICROSOFT NETWORKS 3.0"},
//		{ "LANMAN1.0"},
//		{ "LM1.2X002"},
//		{ "NT LANMAN 1.0"},
		{ "NT LM 0.12" },
	};
	Pkt *p;

	/*
	 * This should not be necessary, however the XP seems to use
	 * Unicode strings in its Negoiate response, but not set the
	 * Flags2 UNICODE flag.
	 *
	 * It does however echo back the FL_UNICODE flag we set in the
	 * flags2 negoiate request.
	 *
	 * The bodge is to force FL_UNICODE for this single request, 
	 * clearing it after. Later we set FL2_UNICODE if the server 
	 * agrees to CAP_UNICODE as it "should" be done.
	 */
	s->flags2 |= FL2_UNICODE;
	p = cifshdr(s, nil, SMB_COM_NEGOTIATE);
	s->flags2 &= ~FL2_UNICODE;

	pbytes(p);
	for(i = 0; i < nelem(dialects); i++){
		p8(p, STR_DIALECT);
		pascii(p, dialects[i]);
	}

	if(cifsrpc(p) == -1){
		free(p);
		return -1;
	}

	d = gl16(p);
	if(d < 0 || d > nelem(dialects)){
		werrstr("no CIFS dialect in common");
		free(p);
		return -1;
	}

	if(strcmp(dialects[d], ispeak) != 0){
		werrstr("%s dialect unsupported", dialects[d]);
		free(p);
		return -1;
	}

	s->secmode = g8(p);			/* Security mode */

	gl16(p);				/* Max outstanding requests */
	gl16(p);				/* Max VCs */
	s->mtu = gl32(p);			/* Max buffer size */
	gl32(p);				/* Max raw buffer size (depricated) */
	gl32(p);				/* Session key */
	s->caps = gl32(p);			/* Server capabilities */
	*svrtime = gvtime(p);			/* fileserver time */
	s->tz = (short)gl16(p) * 60; 		/* TZ in mins, is signed (SNIA doc is wrong) */
	s->challen = g8(p);			/* Encryption key length */
	gl16(p);
	gmem(p, s->chal, s->challen);		/* Get the challenge */
	gstr(p, domain, domlen);		/* source domain */

	{		/* NetApp Filer seem not to report its called name */
		char *cn = emalloc9p(cnamlen);

		gstr(p, cn, cnamlen);		/* their name */
		if(strlen(cn) > 0)
			memcpy(cname, cn, cnamlen);
		free(cn);
	}

	if(s->caps & CAP_UNICODE)
		s->flags2 |= FL2_UNICODE;

	free(p);
	return 0;
}
コード例 #9
0
ファイル: cifs.c プロジェクト: Nurb432/plan9front
int
cifsrpc(Pkt *p)
{
	int reply, got, err;
	uint tid, uid, seq;
	uchar *pos;
	char m[nelem(magic)];


	pos = p->pos;
	if(p->bytebase){
		p->pos = p->bytebase;
		pl16(p, pos - (p->bytebase + 2)); /* 2 = sizeof bytecount */
	}
	p->pos = pos;

	if(p->s->secmode & SECMODE_SIGN_ENABLED)
		macsign(p, p->seq);

	qlock(&p->s->rpclock);
	got = nbtrpc(p);
	qunlock(&p->s->rpclock);

	if(got < 32+NBHDRLEN){
		werrstr("cifs packet too small (%d < %d)\n", got, 32+NBHDRLEN);
		return -1;
	}

	gmem(p, m, nelem(magic));
	if(memcmp(m, magic, nelem(magic)) != 0){
		werrstr("cifsrpc: bad magic number in packet 0x%02ux%02ux%02ux%02ux",
			m[0], m[1], m[2], m[3]);
		return -1;
	}

	reply = g8(p);			/* cmd */
	err = gl32(p);			/* errcode */
	g8(p);				/* flags */
	p->flags2 = gl16(p);		/* flags2 */
	gl16(p);			/* PID MS bits */
	seq = gl32(p);			/* reserved */
	gl32(p);			/* MAC (if in use) */
	gl16(p);			/* Padding */
	tid = gl16(p);			/* TID */
	gl16(p);			/* PID lsbs */
	uid = gl16(p);			/* UID */
	gl16(p);			/* mid */
	g8(p);				/* word count */

	if(reply != p->request){
		fprint(2, "unexpected reply (cmd=%x/%x seq=%d/%d)\n",
			reply, p->request, seq, p->seq);
		return -1;
	}

	if(p->s->secmode & SECMODE_SIGN_ENABLED){
		if(macsign(p, p->seq+1) != 0 && p->s->seqrun){
			werrstr("cifsrpc: invalid packet signature");
print("MAC signature bad\n");
// FIXME: for debug only			return -1;
		}
	}else{
		/*
		 * We allow the sequence number of zero as some old samba
		 * servers seem to fall back to this unexpectedly
		 * after reporting sequence numbers correctly for a while.
		 *
		 * Some other samba servers seem to always report a sequence
		 * number of zero if MAC signing is disabled, so we have to
		 * catch that too.
		 */
		if(p->s->seqrun && seq != p->seq && seq != 0){
			werrstr("bad sequence number (%d != %d)\n", p->seq, seq);
			return -1;
		}
	}

	p->tid = tid;
	if(p->s->uid == NO_UID)
		p->s->uid = uid;

	if(p->flags2 & FL2_NT_ERRCODES){
		/* is it a real error rather than info/warning/chatter? */
		if((err & 0xF0000000) == 0xC0000000){
			werrstr("%s", nterrstr(err));
			return -1;
		}
	}else{
		if(err){
			werrstr("%s", doserrstr(err));
			return -1;
		}
	}
	return got;
}
コード例 #10
0
ファイル: skipjack.c プロジェクト: BlueFireworks/rtems-libbsd
void
skipjack_forwards(u_int8_t *plain, u_int8_t *cipher, u_int8_t **key_tables)
{
	u_int8_t wh1 = plain[0];  u_int8_t wl1 = plain[1];
	u_int8_t wh2 = plain[2];  u_int8_t wl2 = plain[3];
	u_int8_t wh3 = plain[4];  u_int8_t wl3 = plain[5];
	u_int8_t wh4 = plain[6];  u_int8_t wl4 = plain[7];

	u_int8_t * k0 = key_tables [0];
	u_int8_t * k1 = key_tables [1];
	u_int8_t * k2 = key_tables [2];
	u_int8_t * k3 = key_tables [3];
	u_int8_t * k4 = key_tables [4];
	u_int8_t * k5 = key_tables [5];
	u_int8_t * k6 = key_tables [6];
	u_int8_t * k7 = key_tables [7];
	u_int8_t * k8 = key_tables [8];
	u_int8_t * k9 = key_tables [9];

	/* first 8 rounds */
	g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 1; wh4 ^= wh1;
	g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 2; wh3 ^= wh4;
	g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 3; wh2 ^= wh3;
	g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 4; wh1 ^= wh2;
	g6 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 5; wh4 ^= wh1;
	g0 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 6; wh3 ^= wh4;
	g4 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 7; wh2 ^= wh3;
	g8 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 8; wh1 ^= wh2;

	/* second 8 rounds */
	wh2 ^= wh1; wl2 ^= wl1 ^ 9 ; g2 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 10; g6 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 11; g0 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 12; g4 (wh2,wl2, wh2,wl2);
	wh2 ^= wh1; wl2 ^= wl1 ^ 13; g8 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 14; g2 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 15; g6 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 16; g0 (wh2,wl2, wh2,wl2);

	/* third 8 rounds */
	g4 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 17; wh4 ^= wh1;
	g8 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 18; wh3 ^= wh4;
	g2 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 19; wh2 ^= wh3;
	g6 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 20; wh1 ^= wh2;
	g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 21; wh4 ^= wh1;
	g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 22; wh3 ^= wh4;
	g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 23; wh2 ^= wh3;
	g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 24; wh1 ^= wh2;

	/* last 8 rounds */
	wh2 ^= wh1; wl2 ^= wl1 ^ 25; g6 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 26; g0 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 27; g4 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 28; g8 (wh2,wl2, wh2,wl2);
	wh2 ^= wh1; wl2 ^= wl1 ^ 29; g2 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 30; g6 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 31; g0 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 32; g4 (wh2,wl2, wh2,wl2);

	/* pack into byte vector */
	cipher [0] = wh1;  cipher [1] = wl1;
	cipher [2] = wh2;  cipher [3] = wl2;
	cipher [4] = wh3;  cipher [5] = wl3;
	cipher [6] = wh4;  cipher [7] = wl4;
}
コード例 #11
0
ファイル: skipjack.c プロジェクト: Wmaia/bloc
void Encrypt( Skipjack_CTX *ctx, u8 *in, u8 *out )
{
	u8 wh1 = in[0];  u8 wl1 = in[1];
	u8 wh2 = in[2];  u8 wl2 = in[3];
	u8 wh3 = in[4];  u8 wl3 = in[5];
	u8 wh4 = in[6];  u8 wl4 = in[7];

	u8 * k0 = ctx->key_tables [0];
	u8 * k1 = ctx->key_tables [1];
	u8 * k2 = ctx->key_tables [2];
	u8 * k3 = ctx->key_tables [3];
	u8 * k4 = ctx->key_tables [4];
	u8 * k5 = ctx->key_tables [5];
	u8 * k6 = ctx->key_tables [6];
	u8 * k7 = ctx->key_tables [7];
	u8 * k8 = ctx->key_tables [8];
	u8 * k9 = ctx->key_tables [9];

	/* first 8 rounds */
	g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 1; wh4 ^= wh1;
	g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 2; wh3 ^= wh4;
	g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 3; wh2 ^= wh3;
	g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 4; wh1 ^= wh2;
	g6 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 5; wh4 ^= wh1;
	g0 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 6; wh3 ^= wh4;
	g4 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 7; wh2 ^= wh3;
	g8 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 8; wh1 ^= wh2;

	/* second 8 rounds */
	wh2 ^= wh1; wl2 ^= wl1 ^ 9 ; g2 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 10; g6 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 11; g0 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 12; g4 (wh2,wl2, wh2,wl2);
	wh2 ^= wh1; wl2 ^= wl1 ^ 13; g8 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 14; g2 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 15; g6 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 16; g0 (wh2,wl2, wh2,wl2);

	/* third 8 rounds */
	g4 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 17; wh4 ^= wh1;
	g8 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 18; wh3 ^= wh4;
	g2 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 19; wh2 ^= wh3;
	g6 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 20; wh1 ^= wh2;
	g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 21; wh4 ^= wh1;
	g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 22; wh3 ^= wh4;
	g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 23; wh2 ^= wh3;
	g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 24; wh1 ^= wh2;

	/* last 8 rounds */
	wh2 ^= wh1; wl2 ^= wl1 ^ 25; g6 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 26; g0 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 27; g4 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 28; g8 (wh2,wl2, wh2,wl2);
	wh2 ^= wh1; wl2 ^= wl1 ^ 29; g2 (wh1,wl1, wh1,wl1);
	wh1 ^= wh4; wl1 ^= wl4 ^ 30; g6 (wh4,wl4, wh4,wl4);
	wh4 ^= wh3; wl4 ^= wl3 ^ 31; g0 (wh3,wl3, wh3,wl3);
	wh3 ^= wh2; wl3 ^= wl2 ^ 32; g4 (wh2,wl2, wh2,wl2);

	/* pack into byte vector */
	out [0] = wh1;  out [1] = wl1;
	out [2] = wh2;  out [3] = wl2;
	out [4] = wh3;  out [5] = wl3;
	out [6] = wh4;  out [7] = wl4;
}
コード例 #12
0
ファイル: color.hpp プロジェクト: maxteufel/supertux
 SDL_Color to_sdl_color() const
 {
   return { r8(), g8(), b8(), a8() };
 }
コード例 #13
0
int main()
{
    tQ4 a4( 1.1 );
    tQ4 b4( 1 );
    tQ12 a12( 3.3 );
    tQ12 b12( 3 );
    tQ18 a18;
    double ad;
    double bd;
    
    tQ8 a8( -2.3 );
    tQ8 b8( 2 );
    tQ8 c8( Q8CONST( -2,3 ) );
    tQ8 d8( a8 );
    tQ8 e8( a4 );
//  tQ8 f8( a12 );      // Warning: left shift count is negative
    tQ8 g8( a12.roundedTo< tQ8 >() );
    tQ8 h8( a12.roundedTo< 8 >() );
    
//  a8 = a4.roundedTo( h8 );  //Warning: left/right shift is negative
    
    a8 = 1;
    a8 = -2;
    a8 = 3;
    a8 = Q8CONST( 3,001 );
    a8 = tQ8( 3.001 );
    a8 = tQ8::truncated( 3.001 );
    a8 = tQ8::rounded( 3.001 );
    a8.setTruncated( 3.2 );
    a8.setRounded( 3.3 );
    a8 = tQ8( 123, 8 );
    a8 = tQ8::create( 123 << 8 );
    
    a8 = a4;
    a8 = a8;
//  a8 = a12;          // Warning: left shift count is negative
    a8 = a12.roundedTo< tQ8 >();
    a8 = a12.roundedTo( a8 );
    a8.setRounded( a12 );
    a8 = -a4;
    a8 = -a8;

    a8 += 3;
    a8 += 4u;
    a8 += 5l;
    a8 += 6lu;
    a8 += tQ8( 3.2 );
    a8 += truncatedTo( a8, 3.3 );
    a8 += roundedTo( a8, 3.4 );
    a8 += a4;
//  a8 += a12;          // Warning: left shift count is negative
    a8 += a12.roundedTo< tQ8 >();
    a8 += a12.roundedTo( a8 );
    a8 = a8 + 2;
    a8 = 3 + a8;
    a8 = a8 + a4;
//  a8 = a4 + a8;       // Warning: left shift count is negative
    
    a8 -= 3;
    a8 -= 4u;
    a8 -= 5l;
    a8 -= 6lu;
    a8 -= roundedTo< tQ8::cQBits >( 3.2 );
    a8 -= roundedTo( a8, 3.3 );
    a8 -= a4;
//  a8 -= a12;          // Warning: left shift count is negative
    a8 -= a12.roundedTo< tQ8 >();
    a8 -= a12.roundedTo( a8 );
    a8 = a8 - 2;
    a8 = 3 - a8;
    a8 = a8 - a4;
//  a8 = a4 - a8;       // Warning: left shift count is negative
    
    a8 *= 3;
    a8 *= 4u;
    a8 *= 5l;
    a8 *= 6lu;
//  a8 *= 3.2;          // Warning: converting to int from double
    a8 *= a4;
    a8 *= a12;
    a8 = a8 * 2;
    a8 = 3 * a8;
    a12 = a8 * a4;
    a12 = a4 * a8;
    
    a8 /= 3;
    a8 /= 4u;
    a8 /= 5l;
    a8 /= 6lu;
//  a8 /= 3.2;          // Warning: converting to int from double
    a8 /= a4;           // Note: possible overflow due to pre-shifting "(a8 << 4) / a4"
//  a8 /= a12;          // Warning: left shift count is negative
    a8 = a8.increasedBy( a12 ) / a12;
    a8 = a8 / 2;
//  a8 = 3 / a8;        // Error: no match for 'operator/'
    a8 = tQ16( 3 ) / a8;
    a12 = a8 / a4;
    a12 = a4 / a8;
    
    a8 == 3;
    a8 == 4u;
    a8 == 5l;
    a8 == 6lu;
    a8 == tQ8( 3.2 );
    a8 == truncatedTo( a8, 3.3 );
    a8 == roundedTo( a8, 3.4 );
    a8 == a4;
//  a8 == a12;          // Warning: left shift count is negative
    a8 == a12.roundedTo< tQ8 >();
    a8 == a12.roundedTo( a8 );
    3 == a8;
    int(4u) == a8;
    int(5l) == a8;
    int(6lu) == a8;
    
    a8 < 3;
    a8 < 4u;
    a8 < 5l;
    a8 < 6lu;
    a8 < tQ8( 3.2 );
    a8 < a4;
//  a8 < a12;          // Warning: left shift count is negative
    3 < a8;
    int(4u) < a8;
    int(5l) < a8;
    int(6lu) < a8;
    
    a8 > 3;
    a8 > 4u;
    a8 > 5l;
    a8 > 6lu;
    a8 > tQ8( 3.2 );
    a8 > a4;
//  a8 > a12;          // Warning: left shift count is negative
    3 > a8;
    int(4u) > a8;
    int(5l) > a8;
    int(6lu) > a8;
    
    !a8;
    int intPart = a8.intPart();
    int fracPart = a8.fracPart();
    int fracPlaces = a8.fracPlaces( 3 );
    unsigned abs = a8.absolute();

    ad = a8.toDouble();
    a8 = ad;
//  a8.set( ad );    // Warning: conversion from int to double, possible loss of data
    a8.setRounded( ad );
    a8 = truncatedTo( a8, ad );
    a8 = truncatedTo<8>( ad );
    a8 = truncatedTo<tQ8>( ad );
    
//  tBigQ36 aB36( 123567890 );     // Error: ambiguous
    tBigQ36 aB36( 123567890ll );
    tBigQ36 bB36( a8 );
    
    aB36 = tBigQ18( a18 ) * a18;
}