1

I'm trying to use boost in oder to calculate a factorial. I don't know why, but VS2013 show me a compiling error.

Anyone have some ideas please ?

int nLgCombi = 12;
std::vector<std::string>   NbrToPlay;
...
int ne = NbrToPlay.size();
int calcnc = boost::math::factorial<int>(ne + 1) / boost::math::factorial<int>(nLgCombi);

Error message :

Erreur 1 error C2338: !boost::is_integral::value d:\users\XXXXXX\downloads\boost_1_55_0b1\boost_1_55_0b1\boost\math\special_functions\factorials.hpp 32 1 APPS

EDIT :

Code replace int by double:

double dcalcnc = boost::math::factorial<double>(ne +1) / boost::math::factorial<double>(nLgCombi);

Error message :

Erreur 1 error C2039: 'assert_not_arg' : n'est pas membre de 'boost::mpl' d:\users\XXXXX\downloads\boost_1_55_0b1\boost_1_55_0b1\boost\mpl\aux_\preprocessed\plain\arg.hpp 45 1

Erreur 2 error C3861: 'assert_not_arg' : identificateur introuvable d:\users\XXXXX\downloads\boost_1_55_0b1\boost_1_55_0b1\boost\mpl\aux_\preprocessed\plain\arg.hpp 45 1

Thanks a lot,

Best regards,

Nixeus

Walter Fabio Simoni
  • 5,671
  • 15
  • 55
  • 80

1 Answers1

4

According to Boost documentation about factorial :

 BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); 
 // factorial<unsigned int>(n) is not implemented 
 // because it would overflow integral type T for too small n 
 // to be useful. Use instead a floating-point type, 
 // and convert to an unsigned type if essential, for example: 
 // unsigned int nfac = static_cast<unsigned int>(factorial<double>(n)); 
 // See factorial documentation for more detail.

The factorial version for int and unsigned int are not yet implemented because even for small values it would lead to an overflow.

For example, the factorial of 13 is 6227020800, which exceeds the maximum limit of an unsigned int (4294967295 if ints are 4 bytes long).

You must use double or float to calculate the factorial.

xorguy
  • 2,594
  • 1
  • 16
  • 14
  • Hello, you're right, i saw this a few minutes ago ! I modifty my code in order to deal with double but i have another error message. Erreur 1 error C2039: 'assert_not_arg' : n'est pas membre de 'boost::mpl' d:\users\XXXXX\downloads\boost_1_55_0b1\boost_1_55_0b1\boost\mpl\aux_\preprocessed\plain\arg.hpp – Walter Fabio Simoni Oct 23 '13 at 15:04
  • It seems that Visual Studio is not compatible with that certain feature according to this question: http://stackoverflow.com/questions/17440810/how-do-i-build-boost-with-new-visual-studio-2013-preview – xorguy Oct 23 '13 at 15:28
  • Yes, i saw this too, using boost 1.53,and, it's ok ! – Walter Fabio Simoni Oct 23 '13 at 15:39