本文整理汇总了C++中ROTATE函数的典型用法代码示例。如果您正苦于以下问题:C++ ROTATE函数的具体用法?C++ ROTATE怎么用?C++ ROTATE使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ROTATE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: indexToDetectorOffsetX
CVector3D CConeProjectionGeometry3D::getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const
{
float32 fSrcX = -m_fOriginSourceDistance;
float32 fSrcY = 0.0f;
float32 fSrcZ = 0.0f;
float32 fDetX = m_fOriginDetectorDistance;
float32 fDetY = 0.0f;
float32 fDetZ = 0.0f;
fDetY += indexToDetectorOffsetX(_iDetectorIndex);
fDetZ += indexToDetectorOffsetY(_iDetectorIndex);
float32 angle = m_pfProjectionAngles[_iProjectionIndex];
#define ROTATE(name,alpha) do { float32 tX = f##name##X * cos(alpha) - f##name##Y * sin(alpha); f##name##Y = f##name##X * sin(alpha) + f##name##Y * cos(alpha); f##name##X = tX; } while(0)
ROTATE(Src, angle);
ROTATE(Det, angle);
#undef ROTATE
CVector3D ret(fDetX - fSrcX, fDetY - fSrcY, fDetZ - fDetZ);
return ret;
}
示例2: chacha_round
static inline void chacha_round(uint32_t x[16], int a, int b, int c, int d)
{
x[a] += x[b]; x[d] ^= x[a]; ROTATE(x[d], 16);
x[c] += x[d]; x[b] ^= x[c]; ROTATE(x[b], 12);
x[a] += x[b]; x[d] ^= x[a]; ROTATE(x[d], 8);
x[c] += x[d]; x[b] ^= x[c]; ROTATE(x[b], 7);
}
示例3: sha1_process_block
void sha1_process_block(sha1_ctx_t *p, const byte *block)
{
static uint32 K[4] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 };
uint32 a, b, c, d, e, f, k, temp;
a = p->h[0];
b = p->h[1];
c = p->h[2];
d = p->h[3];
e = p->h[4];
uint32 w[80];
int i;
for (i = 0; i < 16; i++) {
w[i] = block[i*4+0] << 24;
w[i] |= block[i*4+1] << 16;
w[i] |= block[i*4+2] << 8;
w[i] |= block[i*4+3];
}
for (i = 16; i < 80; i++)
w[i] = ROTATE((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1);
for (i = 0; i < 80; i++) {
if (0 <= i && i < 20) {
f = (b & c) ^ ((~b) & d);
k = K[0];
} else if (20 <= i && i < 40) {
f = b ^ c ^ d;
k = K[1];
} else if (40 <= i && i < 60) {
f = (b & c) ^ (b & d) ^ (c & d);
k = K[2];
} else if (60 <= i && i < 80) {
f = b ^ c ^ d;
k = K[3];
}
temp = ROTATE(a, 5) + f + e + k + w[i];
e = d;
d = c;
c = ROTATE(b, 30);
b = a;
a = temp;
}
p->h[0] += a;
p->h[1] += b;
p->h[2] += c;
p->h[3] += d;
p->h[4] += e;
}
示例4: md5_digest
void md5_digest (md5_t* self) {
uint32_t data[16], a, b, c, d;
a = self->rawhash[0];
b = self->rawhash[1];
c = self->rawhash[2];
d = self->rawhash[3];
for (int i = 0, j = 0; i < 16; ++i, j+=4)
data[i] = (self->buffer[j] ) + (self->buffer[j + 1] << 8) +
(self->buffer[j + 2] << 16) + (self->buffer[j + 3] << 24);
for (int i = 0; i < 64; ++i) {
uint32_t func, temp;
if (i < 16) func = F(b,c,d);
else if (i < 32) func = G(b,c,d);
else if (i < 48) func = H(b,c,d);
else if (i < 64) func = I(b,c,d);
temp = d;
d = c;
c = b;
b = b + ROTATE(a + func + data[M[i]] + K[i], S[i]);
a = temp;
}
self->rawhash[0] += a;
self->rawhash[1] += b;
self->rawhash[2] += c;
self->rawhash[3] += d;
}
示例5: TERNARY
void TERNARY(stack& s) {
NULLARY(s);
ROTATE(s);
POP(s);
POP(s);
SWAP(s);
POP(s);
}
示例6: RotateBuffer
/* ---------------------------------------------------------------------------
* rotates the contents of the pastebuffer
*/
void
RotateBuffer (BufferType *Buffer, BYTE Number)
{
/* rotate vias */
VIA_LOOP (Buffer->Data);
{
r_delete_entry (Buffer->Data->via_tree, (BoxType *)via);
ROTATE_VIA_LOWLEVEL (via, Buffer->X, Buffer->Y, Number);
SetPinBoundingBox (via);
r_insert_entry (Buffer->Data->via_tree, (BoxType *)via, 0);
}
END_LOOP;
/* elements */
ELEMENT_LOOP (Buffer->Data);
{
RotateElementLowLevel (Buffer->Data, element, Buffer->X, Buffer->Y,
Number);
}
END_LOOP;
/* all layer related objects */
ALLLINE_LOOP (Buffer->Data);
{
r_delete_entry (layer->line_tree, (BoxType *)line);
RotateLineLowLevel (line, Buffer->X, Buffer->Y, Number);
r_insert_entry (layer->line_tree, (BoxType *)line, 0);
}
ENDALL_LOOP;
ALLARC_LOOP (Buffer->Data);
{
r_delete_entry (layer->arc_tree, (BoxType *)arc);
RotateArcLowLevel (arc, Buffer->X, Buffer->Y, Number);
r_insert_entry (layer->arc_tree, (BoxType *)arc, 0);
}
ENDALL_LOOP;
ALLTEXT_LOOP (Buffer->Data);
{
r_delete_entry (layer->text_tree, (BoxType *)text);
RotateTextLowLevel (text, Buffer->X, Buffer->Y, Number);
r_insert_entry (layer->text_tree, (BoxType *)text, 0);
}
ENDALL_LOOP;
ALLPOLYGON_LOOP (Buffer->Data);
{
r_delete_entry (layer->polygon_tree, (BoxType *)polygon);
RotatePolygonLowLevel (polygon, Buffer->X, Buffer->Y, Number);
r_insert_entry (layer->polygon_tree, (BoxType *)polygon, 0);
}
ENDALL_LOOP;
/* finally the origin and the bounding box */
ROTATE (Buffer->X, Buffer->Y, Buffer->X, Buffer->Y, Number);
RotateBoxLowLevel (&Buffer->BoundingBox, Buffer->X, Buffer->Y, Number);
SetCrosshairRangeToBuffer ();
}
示例7: TRANSLATE
void
SbMatrix::setTransform(const SbVec3f &translation,
const SbRotation &rotation,
const SbVec3f &scaleFactor,
const SbRotation &scaleOrientation,
const SbVec3f ¢er)
{
#define TRANSLATE(vec) m.setTranslate(vec), multLeft(m)
#define ROTATE(rot) rot.getValue(m), multLeft(m)
SbMatrix m;
makeIdentity();
if (translation != SbVec3f(0,0,0))
TRANSLATE(translation);
if (center != SbVec3f(0,0,0))
TRANSLATE(center);
if (rotation != SbRotation(0,0,0,1))
ROTATE(rotation);
if (scaleFactor != SbVec3f(1,1,1)) {
SbRotation so = scaleOrientation;
if (so != SbRotation(0,0,0,1))
ROTATE(so);
m.setScale(scaleFactor);
multLeft(m);
if (so != SbRotation(0,0,0,1)) {
so.invert();
ROTATE(so);
}
}
if (center != SbVec3f(0,0,0))
TRANSLATE(-center);
#undef TRANSLATE
#undef ROTATE
}
示例8: hash
int hash(const char * word)
{
int i;
long hv = 0;
for (i=0; i < 4 && *word != 0; i++)
hv = (hv << 8) | (*word++);
while (*word != 0) {
ROTATE(hv,ROTATE_LEN);
hv ^= (*word++);
}
return (unsigned long) hv % tablesize;
}
示例9: printit
static void
printit(const char *arg)
{
int ch, rot;
if ((rot = atoi(arg)) < 0)
errx(1, "bad rotation value");
while ((ch = getchar()) != EOF)
putchar(ROTATE(ch, rot));
exit(0);
}
示例10: ff_dct_calc_c
static void ff_dct_calc_c(DCTContext *s, FFTSample *data)
{
int n = 1<<s->nbits;
int i;
#define ROTATE(i,n) (-M_PI*((n)-0.5f)*(i)/(n))
if (s->inverse) {
for(i=0; i < n; i++) {
s->data[i].re = (float) (2 * data[i] * cos(ROTATE(i,n)));
s->data[i].im = (float) (2 * data[i] * sin(ROTATE(i,n)));
}
s->data[n].re = 0;
s->data[n].im = 0;
for(i=0; i<n-1; i++) {
s->data[n+i+1].re = (float) (-2 * data[n - (i+1)] * cos(ROTATE(n+i+1,n)));
s->data[n+i+1].im = (float) (-2 * data[n - (i+1)] * sin(ROTATE(n+i+1,n)));
}
}else{
for(i=0; i < n; i++) {
s->data[i].re = data[n - (i+1)];
s->data[i].im = 0;
s->data[n+i].re = data[i];
s->data[n+i].im = 0;
}
}
ff_fft_permute(&s->fft, s->data);
ff_fft_calc(&s->fft, s->data);
if (s->inverse) {
for(i=0; i < n; i++)
data[i] = s->data[n-(i+1)].re / (2 * n);
}else {
for(i=0; i < n; i++)
data[i] = (float) (s->data[i].re / (2 * cos(ROTATE(i,n))));
}
#undef ROTATE
}
示例11: RotateMarkedItems
/** Rotate marked items, refer to a rotation point at position offset
* Note: because this function is used in global transform,
* if force_all is true, all items will be rotated
*/
void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all )
{
#define ROTATE( z ) RotatePoint( (&z), offset, 900 )
if( module == NULL )
return;
if( module->Reference().IsSelected() || force_all )
module->Reference().Rotate( offset, 900 );
if( module->Value().IsSelected() || force_all )
module->Value().Rotate( offset, 900 );
for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
{
if( !pad->IsSelected() && !force_all )
continue;
wxPoint pos = pad->GetPos0();
ROTATE( pos );
pad->SetPos0( pos );
pad->SetOrientation( pad->GetOrientation() + 900 );
pad->SetDrawCoord();
}
for( EDA_ITEM* item = module->GraphicalItems(); item; item = item->Next() )
{
if( !item->IsSelected() && !force_all )
continue;
switch( item->Type() )
{
case PCB_MODULE_EDGE_T:
((EDGE_MODULE*) item)->Rotate( offset, 900 );
break;
case PCB_MODULE_TEXT_T:
static_cast<TEXTE_MODULE*>( item )->Rotate( offset, 900 );
break;
default:
break;
}
}
ClearMarkItems( module );
}
示例12: jacobi
int jacobi(double** a, double* d, double** v)
{
int nrot = 0;
const unsigned int nmax = 100, n = 3;
double b[nmax], z[nmax], tresh,sm,g,h,t,theta,c,s,tau;
int i,j,ip,iq;
for(ip=1;ip<=n;ip++) {
for(iq=1;iq<=n;iq++) v[ip][iq] = 0.0f;
v[ip][ip] = 1.0f;
}
for(ip=1;ip<=n;ip++) {
b[ip] = d[ip] = a[ip][ip];
z[ip] = 0.0f;
}
for(i=1;i<=50;i++) {
sm = 0.0f;
for(ip=1;ip<=n-1;ip++) {
for(iq=ip+1;iq<=n;iq++)
sm += fabs(a[ip][iq]);
}
if(sm == 0.0f)
return(0);
if(i < 4) {
tresh = 0.2f * sm / ( n*n );
}
else {
tresh = 0.0f;
}
for(ip=1;ip<=n-1;ip++) {
for(iq=ip+1;iq<=n;iq++) {
g = 100.0f*fabs(a[ip][iq]);
if( (i > 4) && (double)(fabs(d[ip])+g) == (double)fabs(d[ip]) && (double)(fabs(d[iq])+g) == (double)fabs(d[iq]))
a[ip][iq] = 0.0f;
else if( fabs(a[ip][iq]) > tresh ) {
h = d[iq] - d[ip];
if( (fabs(h)+g) == fabs(h) )
t = a[ip][iq] / h;
else {
theta = 0.5f * h / (a[ip][iq]);
t = 1.0f / (fabs(theta) + sqrt(1.0f + theta*theta));
if(theta < 0.0f) t *= -1.0f;
}
c = 1.0f / sqrt(1.0f + t*t);
s = t * c;
tau = s / (1.0f + c);
h = t * a[ip][iq];
z[ip] -= h;
z[iq] += h;
d[ip] -= h;
d[iq] += h;
a[ip][iq] = 0.0f;
for(j=1;j<=ip-1;j++) {
ROTATE(a,j,ip,j,iq);
}
for(j=ip+1;j<=iq-1;j++) {
ROTATE(a,ip,j,j,iq);
}
for(j=iq+1;j<=n;j++) {
ROTATE(a,ip,j,iq,j);
}
for(j=1;j<=n;j++) {
ROTATE(v,j,ip,j,iq);
}
++nrot;
}
}
}
for(ip=1;ip<=n;ip++) {
b[ip] += z[ip];
d[ip] = b[ip];
z[ip] = 0.0f;
}
}
assert(i<50);
return 1;
}
示例13: jacobi
void jacobi(Matrix<double> &a, int n, double* d, Matrix<double> &v, int nrot)
{
int i, j, iq, ip;
double tresh, theta, tau, t, sm, s, h, g, c;
double* b = new double[n + 1];
double* z = new double[n + 1];
for (ip = 1; ip <= n; ip++)
{
ZeroMemory(v[ip], sizeof(double) * (n + 1));
v[ip][ip]=1.0;
}
for (ip = 1; ip <= n; ip++)
{
b[ip] = d[ip] = a[ip][ip];
z[ip] = 0.0;
}
nrot = 0;
for (i = 1; i <= 50; i++)
{
sm = 0.0;
for (ip = 1; ip <= n - 1; ip++)
{
for (iq = ip + 1; iq <= n; iq++)
{
sm += fabs(a[ip][iq]);
}
}
if (sm == 0.0)
{
delete[] b;
delete[] z;
return;
}
if (i < 4)
{
tresh = 0.2 * sm / (n * n);
}
else
{
tresh = 0.0;
}
for (ip = 1;ip <= n - 1; ip++)
{
for (iq = ip + 1; iq <= n; iq++)
{
g = 100.0 * fabs(a[ip][iq]);
if ((i > 4) && (fabs(d[ip]) + g == fabs(d[ip])) && (fabs(d[iq]) + g == fabs(d[iq])))
{
a[ip][iq] = 0.0;
}
else if (fabs(a[ip][iq]) > tresh)
{
h = d[iq] - d[ip];
if (fabs(h) + g == fabs(h))
{
t = (a[ip][iq]) / h;
}
else
{
theta = 0.5 * h / (a[ip][iq]);
t = 1.0 / (fabs(theta) + sqrt(1.0 + theta * theta));
if (theta < 0.0)
{
t = -t;
}
}
c = 1.0 / sqrt(1 + t * t);
s = t * c;
tau = s / (1.0 + c);
h = t * a[ip][iq];
z[ip] -= h;
z[iq] += h;
d[ip] -= h;
d[iq] += h;
a[ip][iq]=0.0;
for (j = 1;j <= ip - 1; j++)
{
ROTATE(a, j, ip, j, iq, tau, s);
}
for (j = ip + 1; j <= iq - 1; j++)
{
ROTATE(a, ip, j, j, iq, tau, s);
}
for (j = iq + 1; j <= n; j++)
{
ROTATE(a, ip, j, iq, j, tau, s);
//.........这里部分代码省略.........
示例14: jacobi_decompose
//Algorithm from the Wikipedia entry on Jacobi decomposition
void jacobi_decompose(double cov_matrix[][NUM_PARAMS], double *eigenvalues, double orth_matrix[][NUM_PARAMS]) {
int i,j,k,l;
int max_col[NUM_PARAMS];
int changed[NUM_PARAMS]; //To keep track of eigenvalues changing
int n = NUM_PARAMS;
int max_row;
int state = 0;
double max, c, s, t, u, a;
int count = 0;
//Set up the maximum value cache
for (i=0; i<n; i++) {
max=0;
max_col[i] = i+1;
for (j=i+1; j<n; j++) {
if (fabs(cov_matrix[i][j])>max) {
max_col[i] = j;
max = fabs(cov_matrix[i][j]);
}
}
}
//Set up the orthogonal matrix as the identity:
for (i=0; i<n; i++)
for (j=0; j<n; j++)
orth_matrix[i][j] = (i==j) ? 1 : 0;
//Copy the diagonal values to the eigenvalue array:
for (i=0; i<n; i++) {
eigenvalues[i] = cov_matrix[i][i];
changed[i] = 1;
for (j=0; j<n; j++)
if (j!=i && cov_matrix[i][j]) break;
if (j==n) {
state--;
changed[i] = 0;
}
}
//Sweep time: iterate until the eigenvalues stop changing.
state += n;
while (state) {
count++;
//Find the largest nonzero element in the matrix:
max = fabs(cov_matrix[0][max_col[0]]);
max_row = 0;
for (i=1; i<n-1; i++) {
if (fabs(cov_matrix[i][max_col[i]])>max) {
max = fabs(cov_matrix[i][max_col[i]]);
max_row = i;
}
}
k = max_row; l = max_col[k];
max = cov_matrix[k][l];
//Calculate the Jacobi rotation matrix
//Tan 2phi = 2S_kl / (S_kk - S_ll)
a = (eigenvalues[l] - eigenvalues[k]) * 0.5;
t = fabsl(a) + sqrtl(max*max + a*a);
s = sqrtl(max*max + t*t);
c = t/s;
s = max/s;
t = max*max / t;
if (a<0) {
s = -s; t = -t;
}
//Update eigenvalues
#define UPDATE(x,y) \
a = eigenvalues[x]; \
eigenvalues[x] += y; \
if (changed[x] && (eigenvalues[x]==a)) { /*Eigenvalue didn't change*/ \
changed[x]=0; \
state--; \
} else if (!changed[x] && (eigenvalues[x]!=a)) { /*Egval did change*/ \
changed[x] = 1; \
state++; \
}
UPDATE(k, -t);
UPDATE(l, t);
//Update covariance matrix:
cov_matrix[k][l] = 0;
#define ROTATE(m,w,x,y,z,r) /*Perform a Jacobi rotation*/ \
t = m[w][x]; u = m[y][z]; \
m[w][x] = t*c - s*u; \
m[y][z] = s*t + c*u; \
if (r) { \
if (fabs(m[w][x])>fabs(m[w][max_col[w]])) \
max_col[w] = x; \
if (fabs(m[y][z])>fabs(m[y][max_col[y]])) \
max_col[y] = z; \
}
for (i=0; i<k; i++) { ROTATE(cov_matrix,i,k,i,l,1); }
for (i=k+1; i<l; i++) { ROTATE(cov_matrix,k,i,i,l,1); }
//.........这里部分代码省略.........
示例15: DES_encrypt1
void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
{
register DES_LONG l, r, t, u;
#ifdef DES_PTR
register const unsigned char *des_SP = (const unsigned char *)DES_SPtrans;
#endif
#ifndef DES_UNROLL
register int i;
#endif
register DES_LONG *s;
r = data[0];
l = data[1];
IP(r, l);
/*
* Things have been modified so that the initial rotate is done outside
* the loop. This required the DES_SPtrans values in sp.h to be rotated
* 1 bit to the right. One perl script later and things have a 5% speed
* up on a sparc2. Thanks to Richard Outerbridge
* <[email protected]> for pointing this out.
*/
/* clear the top bits on machines with 8byte longs */
/* shift left by 2 */
r = ROTATE(r, 29) & 0xffffffffL;
l = ROTATE(l, 29) & 0xffffffffL;
s = ks->ks->deslong;
/*
* I don't know if it is worth the effort of loop unrolling the inner
* loop
*/
if (enc) {
#ifdef DES_UNROLL
D_ENCRYPT(l, r, 0); /* 1 */
D_ENCRYPT(r, l, 2); /* 2 */
D_ENCRYPT(l, r, 4); /* 3 */
D_ENCRYPT(r, l, 6); /* 4 */
D_ENCRYPT(l, r, 8); /* 5 */
D_ENCRYPT(r, l, 10); /* 6 */
D_ENCRYPT(l, r, 12); /* 7 */
D_ENCRYPT(r, l, 14); /* 8 */
D_ENCRYPT(l, r, 16); /* 9 */
D_ENCRYPT(r, l, 18); /* 10 */
D_ENCRYPT(l, r, 20); /* 11 */
D_ENCRYPT(r, l, 22); /* 12 */
D_ENCRYPT(l, r, 24); /* 13 */
D_ENCRYPT(r, l, 26); /* 14 */
D_ENCRYPT(l, r, 28); /* 15 */
D_ENCRYPT(r, l, 30); /* 16 */
#else
for (i = 0; i < 32; i += 4) {
D_ENCRYPT(l, r, i + 0); /* 1 */
D_ENCRYPT(r, l, i + 2); /* 2 */
}
#endif
} else {
#ifdef DES_UNROLL
D_ENCRYPT(l, r, 30); /* 16 */
D_ENCRYPT(r, l, 28); /* 15 */
D_ENCRYPT(l, r, 26); /* 14 */
D_ENCRYPT(r, l, 24); /* 13 */
D_ENCRYPT(l, r, 22); /* 12 */
D_ENCRYPT(r, l, 20); /* 11 */
D_ENCRYPT(l, r, 18); /* 10 */
D_ENCRYPT(r, l, 16); /* 9 */
D_ENCRYPT(l, r, 14); /* 8 */
D_ENCRYPT(r, l, 12); /* 7 */
D_ENCRYPT(l, r, 10); /* 6 */
D_ENCRYPT(r, l, 8); /* 5 */
D_ENCRYPT(l, r, 6); /* 4 */
D_ENCRYPT(r, l, 4); /* 3 */
D_ENCRYPT(l, r, 2); /* 2 */
D_ENCRYPT(r, l, 0); /* 1 */
#else
for (i = 30; i > 0; i -= 4) {
D_ENCRYPT(l, r, i - 0); /* 16 */
D_ENCRYPT(r, l, i - 2); /* 15 */
}
#endif
}
/* rotate and clear the top bits on machines with 8byte longs */
l = ROTATE(l, 3) & 0xffffffffL;
r = ROTATE(r, 3) & 0xffffffffL;
FP(r, l);
data[0] = l;
data[1] = r;
l = r = t = u = 0;
}