本文整理汇总了C++中IsZero函数的典型用法代码示例。如果您正苦于以下问题:C++ IsZero函数的具体用法?C++ IsZero怎么用?C++ IsZero使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsZero函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: m_mul
void BaseShadowRenderImage::getTerrPolys( SimTerrain * terr)
{
float rad = shadow.getShadowRadius();
GridFile *terrFile = terr->getGridFile();
const TMat3F & terrInv = terr->getInvTransform();
// get the light direction in terrain space
Point3F lightInTerr;
m_mul(lastLight,(RMat3F&)terr->getInvTransform(),&lightInTerr);
if (IsZero(lightInTerr.z,0.01f))
return; // light parallel to x-y plane
// center of shape in world coords
Point3F shapeInWorld,preC;
m_mul(shape->getShape().fCenter,shape->fRootDeltaTransform,&preC);
m_mul(preC,transform,&shapeInWorld);
// feet of shape in world coords
Point3F feetInTerr;
m_mul(transform.p,terrInv,&feetInTerr);
// first task is to find plane on ground where light hits
// this plane will be used to decide how big to make box
// to grab terrain polys from
Point3F n,p;
float dot;
bool gotIt = false;
// first, are we standing on the terrain...if so, use this plane
CollisionSurface cs;
if (terrFile->getSurfaceInfo(feetInTerr,&cs))
{
if (IsZero(feetInTerr.z-cs.position.z,rad))
{
n = cs.normal;
p = cs.position;
dot = m_dot(n,lightInTerr);
if (dot < -0.2f)
gotIt = true;
}
}
// now project in direction of light down from top of shape
Point3F ta, a = shapeInWorld;
a.z += rad;
m_mul(a,terrInv,&ta);
Point3F tb = lightInTerr;
tb *= ShadowFeelerLength;
tb += ta;
GridCollision coll(terrFile,NULL);
if (coll.collide(ta,tb) && terrFile->getSurfaceInfo(coll.surface.position,&cs))
{
float thisDot = m_dot(lightInTerr,coll.surface.normal);
if (!gotIt || (thisDot > dot && thisDot < -0.2f))
{
n = coll.surface.normal;
p = coll.surface.position;
dot = thisDot;
gotIt = true;
}
}
if (!gotIt)
return; // no terrain polys
// shape center in terrain space
Point3F shapeInTerr;
m_mul(shapeInWorld,terrInv,&shapeInTerr);
// we now have light, shape center, and a plane all in terrain space
// build a box around projection of shape center onto plane
Point3F shapeOnGround;
float k = 1.0f / dot;
float t = m_dot(n,p-shapeInTerr) * k;
shapeOnGround = lightInTerr;
shapeOnGround *= t;
shapeOnGround += shapeInTerr;
// make the box
Box2F shadowBox;
shadowBox.fMin = shadowBox.fMax = shapeOnGround;
float tx = -rad * n.x * k;
float ty = -rad * n.y * k;
float tz = -rad * n.z * k;
shadowBox.fMin.x -= rad + tx*lightInTerr.x +
fabs(ty*lightInTerr.x) +
fabs(tz*lightInTerr.x);
shadowBox.fMax.x += rad - tx*lightInTerr.x +
fabs(ty*lightInTerr.x) +
fabs(tz*lightInTerr.x);
shadowBox.fMin.y -= rad + ty*lightInTerr.y +
fabs(tx*lightInTerr.y) +
fabs(tz*lightInTerr.y);
shadowBox.fMax.y += rad - ty*lightInTerr.y +
fabs(tx*lightInTerr.y) +
fabs(tz*lightInTerr.y);
int maxPolys = min(shadow.projectionList.size() + BaseShadowRenderImage::maxTerrainPolys,
//.........这里部分代码省略.........
示例2: inv
void inv(zz_pE& d, mat_zz_pE& X, const mat_zz_pE& A)
{
long n = A.NumRows();
if (A.NumCols() != n)
Error("inv: nonsquare matrix");
if (n == 0) {
set(d);
X.SetDims(0, 0);
return;
}
long i, j, k, pos;
zz_pX t1, t2;
zz_pX *x, *y;
const zz_pXModulus& p = zz_pE::modulus();
vec_zz_pX *M = newNTL_NEW_OP vec_zz_pX[n];
for (i = 0; i < n; i++) {
M[i].SetLength(2*n);
for (j = 0; j < n; j++) {
M[i][j].rep.SetMaxLength(2*deg(p)-1);
M[i][j] = rep(A[i][j]);
M[i][n+j].rep.SetMaxLength(2*deg(p)-1);
clear(M[i][n+j]);
}
set(M[i][n+i]);
}
zz_pX det;
set(det);
for (k = 0; k < n; k++) {
pos = -1;
for (i = k; i < n; i++) {
rem(t1, M[i][k], p);
M[i][k] = t1;
if (pos == -1 && !IsZero(t1)) {
pos = i;
}
}
if (pos != -1) {
if (k != pos) {
swap(M[pos], M[k]);
negate(det, det);
}
MulMod(det, det, M[k][k], p);
// make M[k, k] == -1 mod p, and make row k reduced
InvMod(t1, M[k][k], p);
negate(t1, t1);
for (j = k+1; j < 2*n; j++) {
rem(t2, M[k][j], p);
MulMod(M[k][j], t2, t1, p);
}
for (i = k+1; i < n; i++) {
// M[i] = M[i] + M[k]*M[i,k]
t1 = M[i][k]; // this is already reduced
x = M[i].elts() + (k+1);
y = M[k].elts() + (k+1);
for (j = k+1; j < 2*n; j++, x++, y++) {
// *x = *x + (*y)*t1
mul(t2, *y, t1);
add(*x, *x, t2);
}
}
}
else {
clear(d);
goto done;
}
}
X.SetDims(n, n);
for (k = 0; k < n; k++) {
for (i = n-1; i >= 0; i--) {
clear(t1);
for (j = i+1; j < n; j++) {
mul(t2, rep(X[j][k]), M[i][j]);
add(t1, t1, t2);
}
sub(t1, t1, M[i][n+k]);
conv(X[i][k], t1);
}
}
conv(d, det);
done:
//.........这里部分代码省略.........
示例3: kernel
void kernel(mat_zz_pE& X, const mat_zz_pE& A)
{
long m = A.NumRows();
long n = A.NumCols();
mat_zz_pE M;
long r;
transpose(M, A);
r = gauss(M);
X.SetDims(m-r, m);
long i, j, k, s;
zz_pX t1, t2;
zz_pE T3;
vec_long D;
D.SetLength(m);
for (j = 0; j < m; j++) D[j] = -1;
vec_zz_pE inverses;
inverses.SetLength(m);
j = -1;
for (i = 0; i < r; i++) {
do {
j++;
} while (IsZero(M[i][j]));
D[j] = i;
inv(inverses[j], M[i][j]);
}
for (k = 0; k < m-r; k++) {
vec_zz_pE& v = X[k];
long pos = 0;
for (j = m-1; j >= 0; j--) {
if (D[j] == -1) {
if (pos == k)
set(v[j]);
else
clear(v[j]);
pos++;
}
else {
i = D[j];
clear(t1);
for (s = j+1; s < m; s++) {
mul(t2, rep(v[s]), rep(M[i][s]));
add(t1, t1, t2);
}
conv(T3, t1);
mul(T3, T3, inverses[j]);
negate(v[j], T3);
}
}
}
}
示例4: IsEqual
AUR_BOOL IsEqual( AUR_FLOAT32 p_Left, AUR_FLOAT32 p_Right )
{
return IsZero( p_Left - p_Right );
}
示例5: NotZero
bool NotZero() const { return !IsZero(); }
示例6: NullSpace
static
void NullSpace(long& r, vec_long& D, vec_ZZVec& M, long verbose)
{
long k, l, n;
long i, j;
long pos;
ZZ t1, t2;
ZZ *x, *y;
const ZZ& p = ZZ_p::modulus();
n = M.length();
D.SetLength(n);
for (j = 0; j < n; j++) D[j] = -1;
r = 0;
l = 0;
for (k = 0; k < n; k++) {
if (verbose && k % 10 == 0) cerr << "+";
pos = -1;
for (i = l; i < n; i++) {
rem(t1, M[i][k], p);
M[i][k] = t1;
if (pos == -1 && !IsZero(t1))
pos = i;
}
if (pos != -1) {
swap(M[pos], M[l]);
// make M[l, k] == -1 mod p, and make row l reduced
InvMod(t1, M[l][k], p);
NegateMod(t1, t1, p);
for (j = k+1; j < n; j++) {
rem(t2, M[l][j], p);
MulMod(M[l][j], t2, t1, p);
}
for (i = l+1; i < n; i++) {
// M[i] = M[i] + M[l]*M[i,k]
t1 = M[i][k]; // this is already reduced
x = M[i].elts() + (k+1);
y = M[l].elts() + (k+1);
for (j = k+1; j < n; j++, x++, y++) {
// *x = *x + (*y)*t1
mul(t2, *y, t1);
add(*x, *x, t2);
}
}
D[k] = l; // variable k is defined by row l
l++;
}
else {
r++;
}
}
}
示例7: MakeLinearList
//.........这里部分代码省略.........
goto error;
in[0] = (Object)compstr;
in[1] = (Object)start;
in[3] = (Object)end;
in[2] = (Object)DXNewArray(TYPE_INT, CATEGORY_REAL, 0);
if (!in[2])
goto error;
if (!DXAddArrayData((Array)in[2], 0, 1, (Pointer)&count))
goto error;
DXReference((Object)compstr);
DXReference(in[2]);
rc = m_Compute(in, &out);
DXDelete((Object)compstr);
compstr = NULL;
DXDelete(in[2]);
in[2] = NULL;
if (rc == ERROR)
goto error;
delta = (Array)out;
deldelta++;
/* try to catch the case where delta ends up being 0 (like
* because the inputs are int and the count is larger than
* the difference between start and end). allow it to be zero
* only if start == end; i suppose if you ask for 10 things
* where start == end you should be able to get them.
*/
if (IsZero(delta) && !IsEqual(start, end)) {
DXSetError(ERROR_BAD_PARAMETER,
"count too large to generate list between start and end");
goto error;
}
}
/* if all three arrays are there, count must be missing */
if (i == 3) {
char tbuf[512];
int firsttime = 1;
int lastcount = 0;
/* this loop allows us to to handle vectors or matricies as
* well as scalars. it requires that the deltas compute to
* a consistent count. like start=[0 2 4], end=[4 8 16],
* would work if delta=[1 2 4] but not if delta was [1 2 2].
*/
for (j=0; j < nitems; j++) {
/* i think this code only works for vectors - i'm not sure
* what it will do with rank=2 data.
*/
/* this point of this next compute expression:
* if the delta is 0, don't divide by zero - the count is 1.
* if the end is smaller than the start, the delta has to be
* negative. if it's not, return -1. you can't generate a
* negative count from the equations, so this is a safe signal.
*/
sprintf(tbuf,
"float($2.%d) == 0.0 ? "
" 1 : "
示例8: resultant
void resultant(ZZ_p& rres, const ZZ_pX& u, const ZZ_pX& v)
{
if (deg(u) <= NTL_ZZ_pX_GCD_CROSSOVER || deg(v) <= NTL_ZZ_pX_GCD_CROSSOVER) {
PlainResultant(rres, u, v);
return;
}
ZZ_pX u1, v1;
u1 = u;
v1 = v;
ZZ_p res, t;
set(res);
if (deg(u1) == deg(v1)) {
rem(u1, u1, v1);
swap(u1, v1);
if (IsZero(v1)) {
clear(rres);
return;
}
power(t, LeadCoeff(u1), deg(u1) - deg(v1));
mul(res, res, t);
if (deg(u1) & 1)
negate(res, res);
}
else if (deg(u1) < deg(v1)) {
swap(u1, v1);
if (deg(u1) & deg(v1) & 1)
negate(res, res);
}
// deg(u1) > deg(v1) && v1 != 0
vec_ZZ_p cvec;
vec_long dvec;
cvec.SetMaxLength(deg(v1)+2);
dvec.SetMaxLength(deg(v1)+2);
append(cvec, LeadCoeff(u1));
append(dvec, deg(u1));
while (deg(u1) > NTL_ZZ_pX_GCD_CROSSOVER && !IsZero(v1)) {
ResHalfGCD(u1, v1, cvec, dvec);
if (!IsZero(v1)) {
append(cvec, LeadCoeff(v1));
append(dvec, deg(v1));
rem(u1, u1, v1);
swap(u1, v1);
}
}
if (IsZero(v1) && deg(u1) > 0) {
clear(rres);
return;
}
long i, l;
l = dvec.length();
if (deg(u1) == 0) {
// we went all the way...
for (i = 0; i <= l-3; i++) {
power(t, cvec[i+1], dvec[i]-dvec[i+2]);
mul(res, res, t);
if (dvec[i] & dvec[i+1] & 1)
negate(res, res);
}
power(t, cvec[l-1], dvec[l-2]);
mul(res, res, t);
}
else {
for (i = 0; i <= l-3; i++) {
power(t, cvec[i+1], dvec[i]-dvec[i+2]);
mul(res, res, t);
if (dvec[i] & dvec[i+1] & 1)
negate(res, res);
}
power(t, cvec[l-1], dvec[l-2]-deg(v1));
mul(res, res, t);
if (dvec[l-2] & dvec[l-1] & 1)
negate(res, res);
PlainResultant(t, u1, v1);
mul(res, res, t);
}
rres = res;
}
示例9: HalfGCD
void HalfGCD(ZZ_pXMatrix& M_out, const ZZ_pX& U, const ZZ_pX& V, long d_red)
{
if (IsZero(V) || deg(V) <= deg(U) - d_red) {
set(M_out(0,0)); clear(M_out(0,1));
clear(M_out(1,0)); set(M_out(1,1));
return;
}
long n = deg(U) - 2*d_red + 2;
if (n < 0) n = 0;
ZZ_pX U1, V1;
RightShift(U1, U, n);
RightShift(V1, V, n);
if (d_red <= NTL_ZZ_pX_HalfGCD_CROSSOVER) {
IterHalfGCD(M_out, U1, V1, d_red);
return;
}
long d1 = (d_red + 1)/2;
if (d1 < 1) d1 = 1;
if (d1 >= d_red) d1 = d_red - 1;
ZZ_pXMatrix M1;
HalfGCD(M1, U1, V1, d1);
mul(U1, V1, M1);
long d2 = deg(V1) - deg(U) + n + d_red;
if (IsZero(V1) || d2 <= 0) {
M_out = M1;
return;
}
ZZ_pX Q;
ZZ_pXMatrix M2;
DivRem(Q, U1, U1, V1);
swap(U1, V1);
HalfGCD(M2, U1, V1, d2);
ZZ_pX t(INIT_SIZE, deg(M1(1,1))+deg(Q)+1);
mul(t, Q, M1(1,0));
sub(t, M1(0,0), t);
swap(M1(0,0), M1(1,0));
swap(M1(1,0), t);
t.kill();
t.SetMaxLength(deg(M1(1,1))+deg(Q)+1);
mul(t, Q, M1(1,1));
sub(t, M1(0,1), t);
swap(M1(0,1), M1(1,1));
swap(M1(1,1), t);
t.kill();
mul(M_out, M2, M1);
}
示例10: KarMul
void KarMul(ZZX& c, const ZZX& a, const ZZX& b)
{
if (IsZero(a) || IsZero(b)) {
clear(c);
return;
}
if (&a == &b) {
KarSqr(c, a);
return;
}
vec_ZZ mem;
const ZZ *ap, *bp;
ZZ *cp;
long sa = a.rep.length();
long sb = b.rep.length();
if (&a == &c) {
mem = a.rep;
ap = mem.elts();
}
else
ap = a.rep.elts();
if (&b == &c) {
mem = b.rep;
bp = mem.elts();
}
else
bp = b.rep.elts();
c.rep.SetLength(sa+sb-1);
cp = c.rep.elts();
long maxa, maxb, xover;
maxa = MaxBits(a);
maxb = MaxBits(b);
xover = 2;
if (sa < xover || sb < xover)
PlainMul(cp, ap, sa, bp, sb);
else {
/* karatsuba */
long n, hn, sp, depth;
n = max(sa, sb);
sp = 0;
depth = 0;
do {
hn = (n+1) >> 1;
sp += (hn << 2) - 1;
n = hn;
depth++;
} while (n >= xover);
ZZVec stk;
stk.SetSize(sp,
((maxa + maxb + NumBits(min(sa, sb)) + 2*depth + 10)
+ NTL_ZZ_NBITS-1)/NTL_ZZ_NBITS);
KarMul(cp, ap, sa, bp, sb, stk.elts());
}
c.normalize();
}
示例11: BerlekampMassey
void BerlekampMassey(ZZ_pX& h, const vec_ZZ_p& a, long m)
{
ZZ_pX Lambda, Sigma, Temp;
long L;
ZZ_p Delta, Delta1, t1;
long shamt;
// cerr << "*** " << m << "\n";
Lambda.SetMaxLength(m+1);
Sigma.SetMaxLength(m+1);
Temp.SetMaxLength(m+1);
L = 0;
set(Lambda);
clear(Sigma);
set(Delta);
shamt = 0;
long i, r, dl;
for (r = 1; r <= 2*m; r++) {
// cerr << r << "--";
clear(Delta1);
dl = deg(Lambda);
for (i = 0; i <= dl; i++) {
mul(t1, Lambda.rep[i], a[r-i-1]);
add(Delta1, Delta1, t1);
}
if (IsZero(Delta1)) {
shamt++;
// cerr << "case 1: " << deg(Lambda) << " " << deg(Sigma) << " " << shamt << "\n";
}
else if (2*L < r) {
div(t1, Delta1, Delta);
mul(Temp, Sigma, t1);
Sigma = Lambda;
ShiftSub(Lambda, Temp, shamt+1);
shamt = 0;
L = r-L;
Delta = Delta1;
// cerr << "case 2: " << deg(Lambda) << " " << deg(Sigma) << " " << shamt << "\n";
}
else {
shamt++;
div(t1, Delta1, Delta);
mul(Temp, Sigma, t1);
ShiftSub(Lambda, Temp, shamt);
// cerr << "case 3: " << deg(Lambda) << " " << deg(Sigma) << " " << shamt << "\n";
}
}
// cerr << "finished: " << L << " " << deg(Lambda) << "\n";
dl = deg(Lambda);
h.rep.SetLength(L + 1);
for (i = 0; i < L - dl; i++)
clear(h.rep[i]);
for (i = L - dl; i <= L; i++)
h.rep[i] = Lambda.rep[L - i];
}
示例12: IsX
long IsX(const ZZX& a)
{
return deg(a) == 1 && IsOne(LeadCoeff(a)) && IsZero(ConstTerm(a));
}
示例13: ClonePolicy
// Create new local-bridge
BRIDGE *BrNewBridge(HUB *h, char *name, POLICY *p, bool local, bool monitor, bool tapmode, char *tapaddr, bool limit_broadcast, LOCALBRIDGE *parent_local_bridge)
{
BRIDGE *b;
POLICY *policy;
THREAD *t;
// Validate arguments
if (h == NULL || name == NULL || parent_local_bridge == NULL)
{
return NULL;
}
if (p == NULL)
{
policy = ClonePolicy(GetDefaultPolicy());
}
else
{
policy = ClonePolicy(p);
}
b = ZeroMalloc(sizeof(BRIDGE));
b->Cedar = h->Cedar;
b->Hub = h;
StrCpy(b->Name, sizeof(b->Name), name);
b->Policy = policy;
b->Local = local;
b->Monitor = monitor;
b->TapMode = tapmode;
b->LimitBroadcast = limit_broadcast;
b->ParentLocalBridge = parent_local_bridge;
if (b->TapMode)
{
if (tapaddr != NULL && IsZero(tapaddr, 6) == false)
{
Copy(b->TapMacAddress, tapaddr, 6);
}
else
{
GenMacAddress(b->TapMacAddress);
}
}
if (monitor)
{
// Enabling monitoring mode
policy->MonitorPort = true;
}
if (b->LimitBroadcast == false)
{
// Disable broadcast limiter
policy->NoBroadcastLimiter = true;
}
// Start thread
t = NewThread(BrBridgeThread, b);
WaitThreadInit(t);
ReleaseThread(t);
return b;
}
示例14: AddLocalBridge
// Add a local-bridge
void AddLocalBridge(CEDAR *c, char *hubname, char *devicename, bool local, bool monitor, bool tapmode, char *tapaddr, bool limit_broadcast)
{
UINT i;
HUB *h = NULL;
LOCALBRIDGE *br = NULL;
// Validate arguments
if (c == NULL || hubname == NULL || devicename == NULL)
{
return;
}
if (OS_IS_UNIX(GetOsInfo()->OsType) == false)
{
tapmode = false;
}
LockList(c->HubList);
{
LockList(c->LocalBridgeList);
{
bool exists = false;
// Ensure that the same configuration local-bridge doesn't exist already
for (i = 0;i < LIST_NUM(c->LocalBridgeList);i++)
{
LOCALBRIDGE *br = LIST_DATA(c->LocalBridgeList, i);
if (StrCmpi(br->DeviceName, devicename) == 0)
{
if (StrCmpi(br->HubName, hubname) == 0)
{
if (br->TapMode == tapmode)
{
exists = true;
}
}
}
}
if (exists == false)
{
// Add configuration
br = ZeroMalloc(sizeof(LOCALBRIDGE));
StrCpy(br->HubName, sizeof(br->HubName), hubname);
StrCpy(br->DeviceName, sizeof(br->DeviceName), devicename);
br->Bridge = NULL;
br->Local = local;
br->TapMode = tapmode;
br->LimitBroadcast = limit_broadcast;
br->Monitor = monitor;
if (br->TapMode)
{
if (tapaddr != NULL && IsZero(tapaddr, 6) == false)
{
Copy(br->TapMacAddress, tapaddr, 6);
}
else
{
GenMacAddress(br->TapMacAddress);
}
}
Add(c->LocalBridgeList, br);
// Find the hub
for (i = 0;i < LIST_NUM(c->HubList);i++)
{
HUB *hub = LIST_DATA(c->HubList, i);
if (StrCmpi(hub->Name, br->HubName) == 0)
{
h = hub;
AddRef(h->ref);
break;
}
}
}
}
UnlockList(c->LocalBridgeList);
}
UnlockList(c->HubList);
// Start the local-bridge immediately
if (h != NULL && br != NULL && h->Type != HUB_TYPE_FARM_DYNAMIC)
{
Lock(h->lock_online);
{
if (h->Offline == false)
{
LockList(c->LocalBridgeList);
{
if (IsInList(c->LocalBridgeList, br))
{
if (br->Bridge == NULL)
{
br->Bridge = BrNewBridge(h, br->DeviceName, NULL, br->Local, br->Monitor, br->TapMode, br->TapMacAddress, br->LimitBroadcast, br);
}
}
}
UnlockList(c->LocalBridgeList);
}
//.........这里部分代码省略.........
示例15: XHalfGCD
void XHalfGCD(ZZ_pXMatrix& M_out, ZZ_pX& U, ZZ_pX& V, long d_red)
{
if (IsZero(V) || deg(V) <= deg(U) - d_red) {
set(M_out(0,0)); clear(M_out(0,1));
clear(M_out(1,0)); set(M_out(1,1));
return;
}
long du = deg(U);
if (d_red <= NTL_ZZ_pX_HalfGCD_CROSSOVER) {
IterHalfGCD(M_out, U, V, d_red);
return;
}
long d1 = (d_red + 1)/2;
if (d1 < 1) d1 = 1;
if (d1 >= d_red) d1 = d_red - 1;
ZZ_pXMatrix M1;
HalfGCD(M1, U, V, d1);
mul(U, V, M1);
long d2 = deg(V) - du + d_red;
if (IsZero(V) || d2 <= 0) {
M_out = M1;
return;
}
ZZ_pX Q;
ZZ_pXMatrix M2;
DivRem(Q, U, U, V);
swap(U, V);
XHalfGCD(M2, U, V, d2);
ZZ_pX t(INIT_SIZE, deg(M1(1,1))+deg(Q)+1);
mul(t, Q, M1(1,0));
sub(t, M1(0,0), t);
swap(M1(0,0), M1(1,0));
swap(M1(1,0), t);
t.kill();
t.SetMaxLength(deg(M1(1,1))+deg(Q)+1);
mul(t, Q, M1(1,1));
sub(t, M1(0,1), t);
swap(M1(0,1), M1(1,1));
swap(M1(1,1), t);
t.kill();
mul(M_out, M2, M1);
}