//计算DNA k-mer的哈希索引,但是这个索引的长度为0 - 3*sigma(4^(k-1))(k=1...k) //当kmer的长度为3时,索引的范围是0-63 int indexOfKmer(char* kmer) { int idx = 0; int i; int l = strlen(kmer); int *N; //calloc会把内存初始化为0 N = (int*)calloc(256, sizeof(int)); //使用ascii码作为索引 N['A'] = 0; N['C'] = 1; N['T'] = 2; N['G'] = 3; for (i=0; i<l; i++) { idx += N[ (int)(kmer[i]) ] * powint(4,(l - i - 1)); } free(N); return idx; }
VOID InitRayTreeStack(INT TreeDepth, INT pid) { raystruct[pid].StackSize = powint(2, TreeDepth) - 1; raystruct[pid].StackSize += NumSubRays; raystruct[pid].Stack = (RAY *)LocalMalloc(raystruct[pid].StackSize*sizeof(RAY), "raystack.c"); raystruct[pid].StackTop = -1; /* Empty condition. */ }
RCP<const Number> Integer::pow_negint(const Integer &other) const { RCP<const Number> tmp = powint(*other.neg()); if (is_a<Integer>(*tmp)) { mpq_class q(sgn(rcp_static_cast<const Integer>(tmp)->i), abs(rcp_static_cast<const Integer>(tmp)->i)); return make_rcp<const Rational>(q); } else { throw std::runtime_error("powint returned non-integer"); } }
RCP<const Number> Integer::pow_negint(const Integer &other) const { RCP<const Number> tmp = powint(*other.neg()); if (is_a<Integer>(*tmp)) { const integer_class &j = down_cast<const Integer &>(*tmp).i; #if SYMENGINE_INTEGER_CLASS == SYMENGINE_BOOSTMP // boost::multiprecision::cpp_rational lacks an (int, cpp_int) // constructor. must use cpp_rational(cpp_int,cpp_int) rational_class q(integer_class(mp_sign(j)), mp_abs(j)); #else rational_class q(mp_sign(j), mp_abs(j)); #endif return Rational::from_mpq(std::move(q)); } else { throw SymEngineException("powint returned non-integer"); } }
// doubledouble^int doubledouble powint(const doubledouble& u, const int c) { if (c<0) return recip(powint(u,-c)); switch (c) { case 0: return u.h()==0.0?doubledouble(pow(0.0,0.0)):doubledouble(1.0); // let math.h handle 0^0. case 1: return u; case 2: return sqr(u); case 3: return sqr(u)*u; default: { // binary method int n=c, m; doubledouble y=1.0, z=u; if (n<0) n=-n; while (1) { m=n; n/=2; if (n+n!=m) { // if m odd y*=z; if (0==n) return y; } z=sqr(z); } } } }