fixed_point cos(fixed_point fp){ fixed_point tmp(0); for( int i = 0; i <= 3; i++){ int32_t tmpSi = (std::pow(-1,i)*0x10000); fixed_point si(tmpSi); fixed_point divend = pow(fp, (2*i)); int32_t fac = factorial(2*i); fixed_point divsor(fac*0x10000); tmp = tmp + si * (divend/divsor); } return tmp; }
BigInt& BigInt::operator /= (const BigInt &bi) { if( bi == 0 ) throw std::logic_error("can't div 0"); bool sign = m_sign; m_sign = false; BigInt res(0); BigInt divsor(bi), count(1); while( absCompare(divsor) >= 0 ) { divsor.selfLeftShift(10);//fast count.selfLeftShift(10); } while(absCompare(bi) >= 0) { while(absCompare(divsor) < 0) { divsor.selfRightShift(1);//slow count.selfRightShift(1); } res += count; (*this) -= divsor; } m_vec = std::move(res.m_vec); if( m_vec.size() == 1 && m_vec[0] == 0 ) m_sign = false; else m_sign = sign ^ bi.m_sign; return *this; }