
--- Chris Weed wrote:
Hi, I am getting the wrong result for the exponential of complex numbers such as the following:
#include <boost/mpl/math/double.hpp> #include <boost/mpl/math/complex_number.hpp> #include <iostream>
int main() { typedef
boost::mpl::math::string_c_to_double<'-',2,'.',0>::type
minus_two; typedef
boost::mpl::times<minus_two,boost::mpl::math::pi<boost::mpl::math::double_tag>
::type minus_two_pi; typedef
boost::mpl::math::complex_number<double_zero,minus_two_pi>
imag_minus_two_pi; std::cout << imag_minus_two_pi() << std::endl;
std::cout <<
boost::mpl::math::exponential<imag_minus_two_pi>::type()
<< std::endl; return 0; }
This prints: 0-6.28319i 1.0329-0.0109834i
which should be 0-6.28319i 1.0000-0.00000i
Chris
The problem was in the sine and cosine functions, which by default lose their accuracy when the angle is beyond tha range (-pi/2,pi/2). I've fixed their implementations to take advantage of the fact that they are periodic functions; however, this also reintroduces recursive template instantiation. Your program now resides in the example directory as complex_exponential.cpp; note that I've changed the semantics of the tagged constants. The metafunctions pi<> et al. take in primitive numeric types, e.g. int, double; if you wish to pass in numeric tags, use pi_dispatch<>, etc. Cromwell D. Enage ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com