Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Boost library multiprecision feature in C++ - Can not convert integer constant

Avatar of Pra Sys
Pra SysFlag for India asked on
C++Windows OS
10 Comments1 Solution1514 ViewsLast Modified:

I was doing some test programming with Boost C++ library and was trying use new feature of multiprecision as given below -

#include <\boost\multiprecision\cpp_int.hpp>
#include <iostream>

using boost::multiprecision::int1024_t;
using namespace std;

int1024_t Factorial(int num);

int main()
    int1024_t i = 51090942171709440000;//Factorial(21);
    cout << i << " " << sizeof(i) << endl;

int1024_t Factorial(int num)
    int1024_t fact = 1;
    for(int i=num; i>1; --i)
        fact *= i;

    return fact;
However, when I run this program it gives me below error -

error: conversion from '<unnamed-signed:128>' to non-scalar type 'boost::multiprecision::int1024_t {aka boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<1024u, 1024u, (boost::multiprecision::cpp_integer_type)1u, (boost::multiprecision::cpp_int_check_type)0u, void> >}' requested

But if instead of assigning value directly to variable i, if I assign function call factorial(21) then it calculates and prints the same big integer value correctly? Why such a behavior?? sizeof operator returns 136 bytes.
Avatar of phoffric
phoffricSoftware Engineering and Matlab Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answers