Skip to content

Instantly share code, notes, and snippets.

@sjhalayka
Created June 22, 2018 23:43
Show Gist options
  • Save sjhalayka/16fe33f2f9399237effbfada7e61b2c2 to your computer and use it in GitHub Desktop.
Save sjhalayka/16fe33f2f9399237effbfada7e61b2c2 to your computer and use it in GitHub Desktop.
double mp_to_double(cpp_dec_float_100 &b)
{
ostringstream oss;
oss << b;
double ret;
istringstream iss(oss.str());
iss >> ret;
return ret;
}
long long unsigned mp_to_int(cpp_dec_float_100 &b)
{
ostringstream oss;
oss << b;
long long unsigned ret;
istringstream iss(oss.str());
iss >> ret;
return ret;
}
vector<cpp_dec_float_100> fact_lut;
void init_fact_lut(long long unsigned int n_max)
{
fact_lut.resize(n_max + 1);
for (long long unsigned int i = 0; i <= n_max; i++)
{
cpp_dec_float_100 ret = 1;
for (cpp_dec_float_100 k = i; k > 0; k--)
ret *= k;
fact_lut[i] = ret;
}
}
cpp_dec_float_100 fact(cpp_dec_float_100 n)
{
return fact_lut[mp_to_int(n)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment