[math/special_functions] newbie question
I did the following 'hello-world'-level test of the factorial function and get the following error.
cat test.cpp
#include "boost/math/special_functions/factorials.hpp" int main() { unsigned int i = 6; printf("%d\n", boost::math::factorial(i)); }
g++ -I/home/sakaiek/ext/src/boost_1_35_0/ test.cpp
test.cpp: In function int main(): test.cpp:5: error: no matching function for call to factorial(unsigned int&) I think I set up the include directory correctly:
ls /home/sakaiek/ext/src/boost_1_35_0/boost/math/special_functions
acosh.hpp beta.hpp detail ellint_3.hpp ellint_rj.hpp fpclassify.hpp laguerre.hpp math_fwd.hpp sinhc.hpp asinh.hpp binomial.hpp digamma.hpp ellint_rc.hpp erf.hpp gamma.hpp lanczos.hpp powm1.hpp sin_pi.hpp atanh.hpp cbrt.hpp ellint_1.hpp ellint_rd.hpp expm1.hpp hermite.hpp legendre.hpp sign.hpp spherical_harmonic.hpp bessel.hpp cos_pi.hpp ellint_2.hpp ellint_rf.hpp factorials.hpp hypot.hpp log1p.hpp sinc.hpp sqrt1pm1.hpp Any help would be greatly appreciated. Thanks! =================================== P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S. News & World Report (2007). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use only by the individual or entity to which it is addressed and may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. Thank you.
AMDG Sakaie, Ken wrote:
I did the following 'hello-world'-level test of the factorial function and get the following error.
cat test.cpp
#include "boost/math/special_functions/factorials.hpp" int main() { unsigned int i = 6; printf("%d\n", boost::math::factorial(i)); }
Here's one way: #include "boost/math/special_functions/factorials.hpp" int main() { unsigned int i = 6; printf("%d\n", static_cast<unsigned>(boost::math::factorial<double>(i))); } In Christ, Steven Watanabe
Steven Watanabe wrote:
Here's one way:
#include "boost/math/special_functions/factorials.hpp" int main() { unsigned int i = 6; printf("%d\n", static_cast<unsigned>(boost::math::factorial<double>(i))); }
Ah, yes I missed that he was formatting the result as an integer: note that there are *very few* factorials that will fit inside an integer result, so this isn't really safe :-( John.
Sakaie, Ken wrote:
I did the following 'hello-world'-level test of the factorial function and get the following error.
cat test.cpp
#include "boost/math/special_functions/factorials.hpp" int main() { unsigned int i = 6; printf("%d\n", boost::math::factorial(i)); }
g++ -I/home/sakaiek/ext/src/boost_1_35_0/ test.cpp
test.cpp: In function 'int main()': test.cpp:5: error: no matching function for call to 'factorial(unsigned int&)'
Since the factorial function takes an integer argument and returns a floating point value, you need to tell the compiler what type of result you are expecting: boost::math::factorial<double>(6); The error message wasn't especially helpful though :-( HTH, John.
participants (3)
-
John Maddock
-
Sakaie, Ken
-
Steven Watanabe