ISTFLOAT GetDet(ISTFLOAT a[4][4], ISTSHORT n) { ISTSHORT i, j, j1, j2; ISTFLOAT det = 0; ISTFLOAT mat[4][4] = {{0}}; if (n == 2) { /* terminate recursion */ det = _sub(_mul(a[0][0], a[1][1]), _mul(a[1][0], a[0][1])); } else { det = 0; for (j1 = 0; j1 < n; j1++) { /* do each column */ for (i = 1; i < n; i++) { /* create minor */ j2 = 0; for (j = 0; j < n; j++) { if (j == j1) { continue; } mat[i-1][j2] = a[i][j]; j2++; } } /* sum (+/-)cofactor * minor */ if ((j1 % 2) == 0) { det = _add(det, _mul(a[0][j1], GetDet(mat, n-1))); } else { det = _sub(det, _mul(a[0][j1], GetDet(mat, n-1))); } } } return det; }
point computeLyapunov (point p, point pe, struct attractor *a) { point p2, dl, np; GLdouble dl2, df, rs; struct lyapu *lyapu = a->lyapunov; p2 = eval (pe, a->polynom); dl = _sub (p2, p); dl2 = _modulus (dl); if (dl2 == 0) { fprintf (stderr, "Unable to compute Lyapunov exponent, trying to go on...\n"); free (dl); free (p2); return pe; } df = dl2 / (LYAPU_DELTA * LYAPU_DELTA); rs = 1 / sqrt (df); lyapu->lsum += log (df); lyapu->n++; lyapu->ly = lyapu->lsum / lyapu->n / log (2); np = _sub (p, _scalar_mul (dl, rs)); free (dl); free (p2); return np; }
ISTVOID Get4Points(struct sphere_model *model) { ISTFLOAT dv[IST_SPHERE_DATAMAX][3]; ISTFLOAT cross[3] = {0}; ISTFLOAT tmpv[3] = {0}; ISTSHORT ndata = model->num; ISTSHORT i, j; ISTFLOAT dist, tmp; // Point 0 for (j = 0; j < 3; ++j) { model->p4s[0][j] = model->data[0][j]; } // Point 1 dist = 0; for (i = 1; i < ndata; i++) { tmp = GetDistance(model->data[i], model->p4s[0]); if (_lt(dist, tmp)) { dist = tmp; for (j = 0; j < 3; j++) { model->p4s[1][j] = model->data[i][j]; } } } // Point 2 dist = 0; for (j = 0; j < 3; j++) { dv[0][j] = _sub(model->p4s[1][j], model->p4s[0][j]); } for (i = 1; i < ndata; i++) { for (j = 0; j < 3; j++) { dv[i][j] = _sub(model->data[i][j], model->p4s[0][j]); } tmpv[0] = _sub(_mul(dv[0][1], dv[i][2]), _mul(dv[0][2], dv[i][1])); tmpv[1] = _sub(_mul(dv[0][2], dv[i][0]), _mul(dv[0][0], dv[i][2])); tmpv[2] = _sub(_mul(dv[0][0], dv[i][1]), _mul(dv[0][1], dv[i][0])); tmp = _add3(_pow2(tmpv[0]), _pow2(tmpv[1]), _pow2(tmpv[2])); if (_lt(dist, tmp)) { dist = tmp; for (j = 0; j < 3; j++) { model->p4s[2][j] = model->data[i][j]; cross[j] = tmpv[j]; } } } // Point 3 dist = 0; for (i = 1; i < ndata; i++) { tmp = _add3(_mul(dv[i][0], cross[0]), _mul(dv[i][1], cross[1]), _mul(dv[i][2], cross[2])); tmp = _abs(tmp); if (_lt(dist, tmp)) { dist = tmp; for (j = 0; j < 3; j++) { model->p4s[3][j] = model->data[i][j]; } } } return; }
void _sub(TreeNode* root, int sum){ if(root == NULL) return ; record_.push_back(root->val); if(root->left == NULL && root->right == NULL){ if(root->val == sum){ res_.push_back(record_); } record_.pop_back(); return; } sum -= root->val; _sub(root->left, sum); _sub(root->right, sum); record_.pop_back(); }
/* Remove the ids in SUB from those in UGIDS. */ error_t ugids_subtract (struct ugids *ugids, const struct ugids *sub) { error_t err = _sub (&ugids->eff_uids, &ugids->eff_gids, &ugids->imp_eff_gids, &sub->eff_uids, &sub->eff_gids, &sub->imp_eff_gids); if (! err) /* If this second call to _sub fails, ugids will be in an inconsistent state, but oh well. */ err = _sub (&ugids->avail_uids, &ugids->avail_gids, &ugids->imp_avail_gids, &sub->avail_uids, &sub->avail_gids, &sub->imp_avail_gids); return err; }
int cgc_bn_div(bn_t *Q, bn_t *R, const bn_t *N, const bn_t *D) { unsigned int i, len; cgc_bn_destroy(Q); cgc_bn_destroy(R); if (cgc_bn_init_bits(R, cgc_bn_length(D) + 1) != SUCCESS) return FAILURE; if (cgc_bn_length(N) > cgc_bn_length(D)) len = cgc_bn_length(N) - cgc_bn_length(D); else len = 1; if (cgc_bn_init_bits(Q, len) != SUCCESS) { cgc_bn_destroy(R); return FAILURE; } for (i = cgc_bn_length(N); i-- > 0;) { _sll(R, 1); R->data[0] |= !!(N->data[i / 32] & (1 << (i % 32))); if (cgc_bn_cmp(R, D) >= 0) { _sub(R->data, D->data, D->length); Q->data[i / 32] |= 1 << (i % 32); } } return SUCCESS; }
static Value * eval(const Ast *expr) { switch(expr->class) { case N_CALL: return call(expr); case N_ASSIGNMENT: return assignment(expr); case N_IDENTIFIER: return identifier(expr); case N_NEG: return _neg(expr); case N_NOT: return _not(expr); case N_EQ: return _eq(expr); case N_NEQ: return _neq(expr); case N_AND: return _and(expr); case N_IOR: return _ior(expr); case N_XOR: return _neq(expr); // alias case N_LT: return _lt(expr); case N_LE: return _le(expr); case N_GE: return _ge(expr); case N_GT: return _gt(expr); case N_ADD: return _add(expr); case N_SUB: return _sub(expr); case N_MUL: return _mul(expr); case N_DIV: return _div(expr); case N_POW: return _pow(expr); case N_MOD: return _mod(expr); case N_BOOLEAN: return _bool(expr); case N_INTEGER: return _int(expr); case N_FLOAT: return _float(expr); case N_STRING: return _string(expr); case N_SET: return _set(expr); case N_R: return _relation(expr); } printf("EVALFAIL %d ", expr->class); pn(expr); assert(false && "should not be reached"); }
QJSValue THREEVector3::sub(QJSValue threeVector3) { THREEVector3 *vec = getAsTHREEVector3(threeVector3); if (!vec) { qDebug() << "THREEVector3::" << __FUNCTION__ << " parameter was not THREEVector3 was " << threeVector3.toQObject(); return m_engine->newQObject(this); } return m_engine->newQObject(_sub(vec)); }
/* * Executes a given instruction, or errors out * ins - instruction to run */ void execute (unsigned short int ins) { /* seperate instruction into parts */ short int a0 = (ins >> 12) % 16; short int a1 = (ins >> 8) % 16; short int a2 = (ins >> 4) % 16; short int a3 = (ins >> 0) % 16; /* Run associated instruction */ switch(a0) { case 0x0: _add (a1, a2, a3); break; case 0x1: _sub (a1, a2, a3); break; case 0x2: _mul (a1, a2, a3); break; case 0x3: _div (a1, a2, a3); break; case 0x6: _beq (a1, a2, a3); break; case 0x7: _bgt (a1, a2, a3); break; case 0x8: _ld (a1, a2, a3); break; case 0x9: _st (a1, a2, a3); break; case 0xa: _lc (a1, a3); break; case 0xb: _jmp (a1, a3); break; case 0xc: _inc (a1, a3); break; case 0xf: _sys (a1, a3); break; default: printf ("Error: invalid opcode %#x.\n", a0); sys_dump (0x0); sys_halt (0x0); } }
/** * vsg_vector2@t@_dist: * @vec: a #VsgVector2@t@ * @other: a #VsgVector2@t@ * * Computes Euclidean norm of the substraction between @vec and @other. * * Returns: square of @vec-@other norm. */ @type@ vsg_vector2@t@_dist (const VsgVector2@t@ *vec, const VsgVector2@t@ *other) { VsgVector2@t@ tmp; #ifdef VSG_CHECK_PARAMS g_return_val_if_fail (vec != NULL, 0.); g_return_val_if_fail (other != NULL, 0.); #endif vsg_vector2@t@_sub (vec, other, &tmp); return vsg_vector2@t@_norm (&tmp); }
ISTFLOAT GetDistance(CONST ISTFLOAT x[3], CONST ISTFLOAT y[3]) { ISTSHORT i; ISTFLOAT tmp, r = 0; for (i = 0; i < 3; ++i) { tmp = _sub(x[i], y[i]); r = _add(r, _pow2(tmp)); } if (_le(r, 0)) { return 0; } return _sqrt(r); }
c4_JoinPropViewer::c4_JoinPropViewer (c4_Sequence& seq_, const c4_ViewProp& sub_, bool outer_) : _parent (&seq_), _sub (sub_), _subPos (_parent.FindProperty(sub_.GetId())), _subWidth (0) { d4_assert(_subPos >= 0); for (int k = 0; k < _parent.NumProperties(); ++k) { if (k != _subPos) _template.AddProperty(_parent.NthProperty(k)); else // if there are no rows, then this join does very little anyway //! OOPS: if this is an unattached view, then the subviews can differ if (_parent.GetSize() > 0) { c4_View view = sub_ (_parent[0]); for (int l = 0; l < view.NumProperties(); ++l) { _template.AddProperty(view.NthProperty(l)); ++_subWidth; } } } _base.SetSize(0, 5); _offset.SetSize(0, 5); for (int i = 0; i < _parent.GetSize(); ++i) { c4_View v = _sub (_parent[i]); int n = v.GetSize(); if (n == 0 && outer_) { _base.Add(i); _offset.Add(~ (t4_i32) 0); // special null entry for outer joins } else for (int j = 0; j < n; ++j) { _base.Add(i); _offset.Add(j); } } }
int isAttractorConverging (struct attractor *at) { point p, pe, pnew = NULL; int i, result = 0; p = newPoint (); pe = newPoint (); for (i = 0; i < fset.dimension; i++) p[i] = pe[i] = 0.1; pe[0] += LYAPU_DELTA; at->lyapunov->lsum = at->lyapunov->ly = at->lyapunov->n = 0; for (i = 0; i < at->convergenceIterations; i++) { pnew = eval (p, at->polynom); if (_abs (pnew) > AT_INFINITY) { /* Diverging - not an SA */ free (p); break; } point ptmp = _sub (pnew, p); if (_abs (ptmp) < 1 / AT_INFINITY) { /* Fixed point - not an SA */ free (p); free (ptmp); break; } free (ptmp); ptmp = computeLyapunov (pnew, pe, at); free (pe); pe = ptmp; if (at->lyapunov->ly < 0.005 && i >= NUM_CONVERGENCE_POINTS) { /* Limit cycle - not an SA */ free (p); break; } free (p); p = pnew; } if (i == at->convergenceIterations) result = 1; free (pnew); free (pe); return result; }
ISTBOOL GetParams(struct sphere_model *model, ISTFLOAT rad) { ISTSHORT i, j; ISTFLOAT min[3] = {0}; ISTFLOAT max[3] = {0}; ISTFLOAT mean[3] = {0}; ISTFLOAT var[3] = {0}; ISTFLOAT tmpf; ISTFLOAT two = _float(2); for (j = 0; j < 3; j++) { min[j] = model->offsets[0][j]; max[j] = model->offsets[0][j]; for (i = 1; i < IST_SPHERE_OFFSET_NUM; i++) { if (_lt(model->offsets[i][j], min[j])) { min[j] = model->offsets[i][j]; } if (_gt(model->offsets[i][j], max[j])) { max[j] = model->offsets[i][j]; } } mean[j] = _div(_add(max[j], min[j]), two); var[j] = _sub(max[j], min[j]); } tmpf = _mul(rad, model->ratio); if (_ge(var[0], tmpf) || _ge(var[1], tmpf) || _ge(var[2], tmpf)) { goto EXIT; } for (j = 0; j < 3; ++j) { model->mean[j] = mean[j]; model->var[j] = var[j]; } model->rad = rad; return ISTTRUE; EXIT: return ISTFALSE; }
int main () { int i1 = 20, i2 = 4, i3; float f1 = 1.5,f2 = 0.3,f3; i3 = _add(i1, i2); printf("add(%d, %d)=%d\n", i1, i2, i3); i3 = _sub(i1, i2); printf("sub(%d, %d)=%d\n", i1, i2, i3); i3 = _mul(i1, i2); printf("mul(%d, %d)=%d\n", i1, i2, i3); i3 = _div(i1, i2); printf("div(%d, %d)=%d\n", i1, i2, i3); f3 = _fadd(f1, f2); printf("fadd(%f, %f)=%f\n", f1, f2, f3); f3 = _fsub(f1, f2); printf("fsub(%f, %f)=%f\n", f1, f2, f3); f3 = _fmul(f1, f2); printf("fmul(%f, %f)=%f\n", f1, f2, f3); f3 = _fdiv(f1, f2); printf("fdiv(%f, %f)=%f\n", f1, f2, f3); return 0; }
//----------------------------------------------------------------------------- // // 命令コマンドを解釈してバイナリに変換 // //----------------------------------------------------------------------------- bool encode(char* instName, char* buffer, map<uint32_t, string>& labelNames, uint32_t currentLine, uint32_t& code, bool& useLabel) { uint32_t rs = 0; uint32_t rt = 0; uint32_t rd = 0; uint32_t imm = 0; double d = 0; char label[MAX_LINE_SIZE]; char dummy[MAX_LINE_SIZE]; if (eq(instName, "add")) { int n = sscanf(buffer, formRRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _add(rs, rt, rd); return true; } } if (eq(instName, "sub")) { int n = sscanf(buffer, formRRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _sub(rs, rt, rd); return true; } } if (eq(instName, "mul")) { int n = sscanf(buffer, formRRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _mul(rs, rt, rd); return true; } } if (eq(instName, "and")) { int n = sscanf(buffer, formRRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _and(rs, rt, rd); return true; } } if (eq(instName, "or")) { int n = sscanf(buffer, formRRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _or(rs, rt, rd); return true; } } if (eq(instName, "nor")) { int n = sscanf(buffer, formRRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _nor(rs, rt, rd); return true; } } if (eq(instName, "xor")) { int n = sscanf(buffer, formRRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _xor(rs, rt, rd); return true; } } if (eq(instName, "addi")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _addi(rs, rt, imm); return true; } } if (eq(instName, "subi")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _subi(rs, rt, imm); return true; } } if (eq(instName, "muli")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _muli(rs, rt, imm); return true; } } if (eq(instName, "slli")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _slli(rs, rt, imm); return true; } } if (eq(instName, "srai")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _srai(rs, rt, imm); return true; } } if (eq(instName, "andi")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _andi(rs, rt, imm); return true; } } if (eq(instName, "ori")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _ori(rs, rt, imm); return true; } } if (eq(instName, "nori")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _nori(rs, rt, imm); return true; } } if (eq(instName, "xori")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _xori(rs, rt, imm); return true; } } if (eq(instName, "fadd")) { int n = sscanf(buffer, formFFF, dummy, &rd, &rs, &rt); if (n == 4) { code = _fadd(rs, rt, rd); return true; } } if (eq(instName, "fsub")) { int n = sscanf(buffer, formFFF, dummy, &rd, &rs, &rt); if (n == 4) { code = _fsub(rs, rt, rd); return true; } } if (eq(instName, "fmul")) { int n = sscanf(buffer, formFFF, dummy, &rd, &rs, &rt); if (n == 4) { code = _fmul(rs, rt, rd); return true; } } if (eq(instName, "fmuln")) { int n = sscanf(buffer, formFFF, dummy, &rd, &rs, &rt); if (n == 4) { code = _fmuln(rs, rt, rd); return true; } } if (eq(instName, "finv")) { int n = sscanf(buffer, formFF, dummy, &rd, &rs); if (n == 3) { code = _finv(rs, rt, rd); return true; } } if (eq(instName, "fsqrt")) { int n = sscanf(buffer, formFF, dummy, &rd, &rs); if (n == 3) { code = _fsqrt(rs, rt, rd); return true; } } if (eq(instName, "fmov")) { int n = sscanf(buffer, formFF, dummy, &rd, &rs); if (n == 3) { code = _fmov(rs, rt, rd); return true; } } if (eq(instName, "fneg")) { int n = sscanf(buffer, formFF, dummy, &rd, &rs); if (n == 3) { code = _fneg(rs, rt, rd); return true; } } if (eq(instName, "imovf")) { int n = sscanf(buffer, formFR, dummy, &rt, &rs); if (n == 3) { code = _imovf(rs, rt, rd); return true; } } if (eq(instName, "fmovi")) { int n = sscanf(buffer, formRF, dummy, &rt, &rs); if (n == 3) { code = _fmovi(rs, rt, rd); return true; } } // to use ALU if (eq(instName, "mvlo")) { int n = sscanf(buffer, formRI, dummy, &rt, &imm); if (n == 3) { code = _mvlo(rt, rt, imm); return true; } } if (eq(instName, "mvhi")) { int n = sscanf(buffer, formRI, dummy, &rt, &imm); if (n == 3) { code = _mvhi(rt, rt, imm); return true; } } if (eq(instName, "fmvlo")) { int n = sscanf(buffer, formFI, dummy, &rt, &imm); if (n == 3) { code = _fmvlo(rt, rt, imm); return true; } } if (eq(instName, "fmvhi")) { int n = sscanf(buffer, formFI, dummy, &rt, &imm); if (n == 3) { code = _fmvhi(rt, rt, imm); return true; } } if (eq(instName, "j")) { int n = sscanf(buffer, formL, dummy, label); if (n == 2) { labelNames[currentLine] = string(label); // cerr << "assigned (" << currentLine << ", " << string(label) << ") in labelNames" << endl; useLabel = true; code = _j(0); return true; } } if (eq(instName, "beq")) { int n = sscanf(buffer, formRRL, dummy, &rs, &rt, label); if (n == 4) { labelNames[currentLine] = string(label); // cerr << "assigned (" << currentLine << ", " << string(label) << ") in labelNames" << endl; useLabel = true; code = _beq(rs, rt, imm); return true; } } if (eq(instName, "blt")) { int n = sscanf(buffer, formRRL, dummy, &rs, &rt, label); if (n == 4) { labelNames[currentLine] = string(label); // cerr << "assigned (" << currentLine << ", " << string(label) << ") in labelNames" << endl; useLabel = true; code = _blt(rs, rt, imm); return true; } } if (eq(instName, "ble")) { int n = sscanf(buffer, formRRL, dummy, &rs, &rt, label); if (n == 4) { labelNames[currentLine] = string(label); // cerr << "assigned (" << currentLine << ", " << string(label) << ") in labelNames" << endl; useLabel = true; code = _ble(rs, rt, imm); return true; } } if (eq(instName, "fbeq")) { int n = sscanf(buffer, formFFL, dummy, &rs, &rt, label); if (n == 4) { labelNames[currentLine] = string(label); // cerr << "assigned (" << currentLine << ", " << string(label) << ") in labelNames" << endl; useLabel = true; code = _fbeq(rs, rt, imm); return true; } } if (eq(instName, "fblt")) { int n = sscanf(buffer, formFFL, dummy, &rs, &rt, label); if (n == 4) { labelNames[currentLine] = string(label); // cerr << "assigned (" << currentLine << ", " << string(label) << ") in labelNames" << endl; useLabel = true; code = _fblt(rs, rt, imm); return true; } } if (eq(instName, "fble")) { int n = sscanf(buffer, formFFL, dummy, &rs, &rt, label); if (n == 4) { labelNames[currentLine] = string(label); // cerr << "assigned (" << currentLine << ", " << string(label) << ") in labelNames" << endl; useLabel = true; code = _fble(rs, rt, imm); return true; } } if (eq(instName, "jr")) { int n = sscanf(buffer, formR, dummy, &rs); if (n == 2) { code = _jr(rs, rt, rd); return true; } } if (eq(instName, "call")) { int n = sscanf(buffer, formL, dummy, label); if (n == 2) { labelNames[currentLine] = string(label); // cerr << "assigned (" << currentLine << ", " << string(label) << ") in labelNames" << endl; useLabel = true; code = _call(0); return true; } } if (eq(instName, "callr")) { int n = sscanf(buffer, formR, dummy, &rs); if (n == 2) { code = _callr(rs, rt, rd); return true; } } if (eq(instName, "return")) { int n = sscanf(buffer, form, dummy); if (n == 1) { code = _return(rs, rt, rd); return true; } } if (eq(instName, "ldr")) { int n = sscanf(buffer, formRRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _ldr(rs, rt, rd); return true; } } if (eq(instName, "fldr")) { int n = sscanf(buffer, formFRR, dummy, &rd, &rs, &rt); if (n == 4) { code = _fldr(rs, rt, rd); return true; } } if (eq(instName, "sti")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _sti(rs, rt, imm); return true; } } if (eq(instName, "ldi")) { int n = sscanf(buffer, formRRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _ldi(rs, rt, imm); return true; } } if (eq(instName, "fsti")) { int n = sscanf(buffer, formFRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _fsti(rs, rt, imm); return true; } } if (eq(instName, "fldi")) { int n = sscanf(buffer, formFRI, dummy, &rt, &rs, &imm); if (n == 4) { code = _fldi(rs, rt, imm); return true; } } if (eq(instName, "inputb")) { int n = sscanf(buffer, formR, dummy, &rt); if (n == 2) { code = _inputb(rs, rt, rd); return true; } } if (eq(instName, "outputb")) { int n = sscanf(buffer, formR, dummy, &rt); if (n == 2) { code = _outputb(rs, rt, rd); return true; } } if (eq(instName, "halt")) { int n = sscanf(buffer, form, dummy); if (n == 1) { code = _halt(rs, rt, rd); return true; } } if (eq(instName, "dump")) { int n = sscanf(buffer, form, dummy); if (n == 1) { code = _dump(rs, rt, rd); return true; } } return false; }
ISTBOOL GetSphereFrom4Points(struct sphere_model *model) { ISTFLOAT a[4][4] = {{0}}; ISTFLOAT ho[3] = {0}; ISTFLOAT norm = 0; ISTFLOAT rad = 0; ISTFLOAT tmpf = 0; ISTFLOAT two = _float(2); ISTFLOAT m11, m12, m13, m14, m15; ISTINT i, j; // Get sphere from 4 points for (i = 0; i < 4; i++) { /* find minor 11 */ a[i][0] = model->p4s[i][0]; a[i][1] = model->p4s[i][1]; a[i][2] = model->p4s[i][2]; a[i][3] = _one; } m11 = GetDet(a, 4); for (i = 0; i < 4; i++) { /* find minor 12 */ a[i][0] = _add(_add(_mul(model->p4s[i][0], model->p4s[i][0]), _mul(model->p4s[i][1], model->p4s[i][1])), _mul(model->p4s[i][2], model->p4s[i][2])); a[i][1] = model->p4s[i][1]; a[i][2] = model->p4s[i][2]; a[i][3] = _one; } m12 = GetDet(a, 4); for (i = 0; i < 4; i++) { /* find minor 13 */ a[i][0] = _add(_add(_mul(model->p4s[i][0], model->p4s[i][0]), _mul(model->p4s[i][1], model->p4s[i][1])), _mul(model->p4s[i][2], model->p4s[i][2])); a[i][1] = model->p4s[i][0]; a[i][2] = model->p4s[i][2]; a[i][3] = _one; } m13 = GetDet(a, 4); for (i = 0; i < 4; i++) { /* find minor 14 */ a[i][0] = _add(_add(_mul(model->p4s[i][0], model->p4s[i][0]), _mul(model->p4s[i][1], model->p4s[i][1])), _mul(model->p4s[i][2], model->p4s[i][2])); a[i][1] = model->p4s[i][0]; a[i][2] = model->p4s[i][1]; a[i][3] = _one; } m14 = GetDet(a, 4); for (i = 0; i < 4; i++) { /* find minor 15 */ a[i][0] = _add(_add(_mul(model->p4s[i][0], model->p4s[i][0]), _mul(model->p4s[i][1], model->p4s[i][1])), _mul(model->p4s[i][2], model->p4s[i][2])); a[i][1] = model->p4s[i][0]; a[i][2] = model->p4s[i][1]; a[i][3] = model->p4s[i][2]; } m15 = GetDet(a, 4); if (_eq(m11, 0)) { rad = 0; } else { /* center of sphere */ ho[0] = _div(_div(m12, m11), two); ho[1] = _neg(_div(_div(m13, m11), two)); ho[2] = _div(_div(m14, m11), two); norm = _sub(_add(_add(_mul(ho[0], ho[0]), _mul(ho[1], ho[1])), _mul(ho[2], ho[2])), _div(m15, m11)); if (_ge(norm, 0)) { rad = _sqrt(norm); } } if (_le(rad, 0)) { goto EXIT; } // Check distance for (i = 0; i < 4; i++) { for (j = (i + 1); j < 4; j++) { tmpf = GetDistance(model->p4s[i], model->p4s[j]); if (_lt(tmpf, rad) || _lt(tmpf, model->rad_min)) { goto EXIT; } } } // Update offset for (i = 1; i < IST_SPHERE_OFFSET_NUM; i++) { for (j = 0; j < 3; ++j) { model->offsets[IST_SPHERE_OFFSET_NUM - i][j] = model->offsets[IST_SPHERE_OFFSET_NUM - i - 1][j]; } } for (j = 0; j < 3; ++j) { model->offsets[0][j] = ho[j]; } for (i = (IST_SPHERE_DATAMAX >> 1); i < IST_SPHERE_DATAMAX; i++) { for (j = 0; j < 3; ++j) { model->data[i][j] = _max; } } // Check offset buffer full if (IsInitedVector(model->offsets[IST_SPHERE_OFFSET_NUM - 1])) { goto EXIT; } // Calculate mean bias and radius if (!GetParams(model, rad)) { goto EXIT; } return ISTTRUE; EXIT: return ISTFALSE; }
vector<vector<int>> pathSum(TreeNode* root, int sum) { _sub(root, sum); return res_; }
void VMDriver::execute(){ if( this->m_state == STATE_IDLE ){ printf( "Error: state is idle. \n"); return; } assert( this->currentAssembly() ); while( this->isActive() ){ if( this->isBreak() ){ break; } unsigned char content = this->getByte( m_funcAddr , m_pc ); m_pc++; switch( content ){ case EMnemonic::MovPtr : _mov_ptr(); break; case EMnemonic::Mov : _mov(); break; case EMnemonic::Add : _add(); break; case EMnemonic::Sub : _sub(); break; case EMnemonic::Mul : _mul(); break; case EMnemonic::Div : _div(); break; case EMnemonic::Rem : _rem(); break; case EMnemonic::Inc : _inc(); break; case EMnemonic::Dec : _dec(); break; case EMnemonic::Push : _push(); break; case EMnemonic::PushPtr : _push_ptr(); break; case EMnemonic::Pop : _pop(); break; case EMnemonic::Call : _call(); break; case EMnemonic::ST : _st(); break; case EMnemonic::LD : _ld(); break; case EMnemonic::EndFunc : _endFunc(); break; case EMnemonic::CmpGeq : case EMnemonic::CmpG : case EMnemonic::CmpLeq : case EMnemonic::CmpL : case EMnemonic::CmpEq : case EMnemonic::CmpNEq : _cmp( content ); break; case EMnemonic::Not : _not(); break; case EMnemonic::Minus : _minus(); break; case EMnemonic::LogOr : case EMnemonic::LogAnd : _log( content ); break; case EMnemonic::Jmp : _jmp(); break; case EMnemonic::JumpZero : _jumpzero(); break; case EMnemonic::JumpNotZero : _jumpnotzero(); break; case EMnemonic::RET : _ret(); break; } } }