int main(int argc, char **argv) { std::string folder; int i; omp_set_num_threads(8); //assert(argc == 2); //folder = std::string(argv[1]); folder = std::string("images"); sumPositive = new mpf_class[1024]; sumSqPositive = new mpf_class[1024]; sumNegative = new mpf_class[1024]; sumSqNegative = new mpf_class[1024]; for (i = 0; i < 1024; i++) { sumPositive[i] = mpf_class(0.); sumSqPositive[i] = mpf_class(0.); sumNegative[i] = mpf_class(0.); sumSqNegative[i] = mpf_class(0.); } readDirectory(folder, functionFilePositive, functionFileNegative); calculateValues(sumPositive, sumSqPositive, sumNegative, sumSqNegative, numberOfPositive, numberOfNegatives); std::cout << numberOfPositive << " " << numberOfNegatives << std::endl; return EXIT_SUCCESS; }
void Portfolio::action( std::string company, mpz_class amount, mpf_class price ) { #ifdef __DEBUG__ mp_exp_t exp = 24; std::cout << "value before: " << _value.get_str(exp) << std::endl; #endif _value = _value - mpf_class( price * amount ); #ifdef __DEBUG__ std::cout << "value after subtracting " << mpf_class( price * amount ).get_str(exp) << " : " << _value.get_str(exp) << std::endl; #endif std::unordered_map<std::string, mpz_class>::iterator got = _holdings.find( company ); if( got == _holdings.end() ) { _holdings.emplace( company, amount ); } else { got->second += amount; } } /* end Portfolio::action() */
expression_tree numeric_Power(const expression_tree::operands_t& ops, enviroment& env) { if ( ops.size() != 2 ) { env.raise_error("numeric Power", "called with invalid arguments"); return expression_tree::make_operator( "Power", ops ); } //double powering mpf_class base; switch ( ops[0].get_type() ) { case expression_tree::EXACT_NUMBER : base = ops[0].get_exact_number(); break; case expression_tree::APPROXIMATE_NUMBER : base = ops[0].get_approximate_number(); break; default: return expression_tree::make_operator("Power", ops); } //if exp is an integral value, then use pow(double, int) version const bool approx_num = ops[1].get_type() == expression_tree::APPROXIMATE_NUMBER; const bool rational_num = ops[1].get_type() == expression_tree::EXACT_NUMBER && !is_mpq_integer(ops[1].get_exact_number()); if (approx_num || rational_num) { const mpf_class exp = ops[1].get_number_as_mpf(); if ( base < 0 || (base == 0 && exp < 0) ) { env.raise_error( "numeric Power", "Indeterminate expression encountered" ); return expression_tree::make_symbol("Indeterminate"); } else if ( base == 0 && exp < 0 ) { return expression_tree::make_symbol("Infinity"); } return expression_tree::make_approximate_number( mpf_class(std::pow(base.get_d(), exp.get_d())) ); } else if ( ops[1].get_type() == expression_tree::EXACT_NUMBER ) { long exp = 0; if ( !mpz_get_si_checked( exp, ops[1].get_exact_number() ) ) { env.raise_error("numeric Power", "exponent overflow"); return expression_tree::make_operator("Power", ops); } if ( base == 0 && exp < 0 ) { return expression_tree::make_symbol("Infinity"); } return expression_tree::make_approximate_number( mpf_class(std::pow(base.get_d(), exp)) ); } else { return expression_tree::make_operator("Power", ops); } }
long long int real_l_t::makeInt() const { #if USE_GMPLIB return mpf_class(_data).get_si(); #else return _data; #endif }
std::ostream & operator << (std::ostream & out, real_l_t const & in) { #if USE_GMPLIB return out << mpf_class(in._data); #else return out << in._data; #endif }
void real_l_t::encodeText(std::ostream & out) { out.precision(256); #if USE_GMPLIB out << mpf_class(_data); #else out << _data; #endif }
mpf_class MpfFromMpq(Signal &sig, const mpq_class &num) { mpf_class numer = num.get_num(); mpf_class denom = num.get_den(); if (denom == 0) { Operator::SetError_DivideByZero(sig); return mpf_class(0); } return numer / denom; }
mpf_class MpfFromRational(Signal &sig, const Rational &ratio) { if (ratio.denom == 0) { Operator::SetError_DivideByZero(sig); return mpf_class(0); } mpq_class numer(ratio.numer); mpq_class denom(ratio.denom); return numer / denom; }
real_l_t sqrt(const real_l_t& x) { #if USE_GMPLIB return real_l_t(sqrt(mpf_class(x._data))); /* real_t epsilon(1, option_precision * 8); real_t guess(1); while (abs((guess * guess) - x) >= epsilon) guess = (x / guess + guess) / 2; return guess; */ #else return real_l_t(sqrt(x._data)); #endif }
int SSG_Planet::load(const XMLReader& reader) { //SFG::Util::printLog(SFG::Util::Development, __FILE__, __LINE__, "Still to do"); //Load values accordingly this->m_name = reader.getValue("name."); bool real = false; this->setMass(PE::Mass(reader.asDouble("mass/", real))); if(!real) { //Failed to load mass SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to load Mass"); } sf::FloatRect r = reader.asFloatRect("PosAndVel/", real); if(!real) { //Failed to load pos and Velocity SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to load PosAndVel"); } //this->setPosition(r.left, r.top); this->setPosition(mpf_class(r.left), mpf_class(r.top)); this->setVelocity(PE::Velocity(r.width, r.height)); auto radius = reader.asDouble("radius/", real); if(!real) { SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to get radius for planet %s", this->m_name.toAnsiString().c_str()); } this->getShape().setRadius(radius); SFG::FloatRect rect(this->getShape().getLocalBounds()); this->getShape().setOrigin(rect.center()); m_planet_surface.reset(new SSG_PlanetSurface(radius)); m_planet_surface->load(); //Get Moons reader.for_all("Moon", [=](const XMLGroup* g){ SFG::Pointer<SSG_Planet> ptr(new SSG_Planet()); ptr->m_parentSys = this->m_parentSys; ptr->setGuiDesktop(this->desktop()); int ret = ptr->load(XMLReader(*g)); if(ret != 0) { SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to load moon"); return; } printf("Position: %f + %f | %f + %f\n", getShape().getPosition().x , ptr->getShape().getPosition().x, getShape().getPosition().y, ptr->getShape().getPosition().y); //Correct relative values //ptr->setPosition(getShape().getPosition().x + ptr->getShape().getPosition().x, // getShape().getPosition().y + ptr->getShape().getPosition().y); ptr->setPosition(x() + ptr->x(), y() + ptr->y()); ptr->setVelocity(getVelocity() + ptr->getVelocity()); //Add to system this->m_parentSys->addSpecificToSystem(ptr); SFG::Util::printLog(SFG::Util::Information, __FILE__, __LINE__, "Moon \"%s\" has been added", ptr->getName().toAnsiString().c_str()); }); //TESTING this->getShape().setFillColor(sf::Color(255, 255, 255)); //!TESTING return 0; }
ConstantNode::ConstantNode(const std::string &str) { m_value = mpf_class(str, m_value.get_prec()); }
ConstantNode::ConstantNode(double op) { m_value = mpf_class(op, m_value.get_prec()); }
TEST(String, FromMPF) { ASSERT_EQ("123.45", util::str(mpf_class(123.45))); ASSERT_EQ("12.345", util::str(mpf_class(12.345))); ASSERT_EQ("1.2345", util::str(mpf_class(1.2345))); }
/// print MpqReal with limited floating point precision std::ostream& operator<<(std::ostream& os, const MpqReal& q) { os << mpf_class(q); return os; }