[mpl::math] exponential metafunction for complex types
Hi,
I am getting the wrong result for the exponential of complex numbers
such as the following:
#include
::type minus_two_pi; typedef boost::mpl::math::complex_number
imag_minus_two_pi; std::cout << imag_minus_two_pi() << std::endl;
std::cout << boost::mpl::math::exponential
"Chris Weed"
Hi, I am getting the wrong result for the exponential of complex numbers such as the following:
#include
#include #include <iostream> int main() { typedef boost::mpl::math::string_c_to_double<'-',2,'.',0>::type minus_two;
I don't know anything about Boost.MPLMath, but I suspect that the 2 and the 0 need to be quoted also. -- Dave Abrahams Boost Consulting www.boost-consulting.com
On 2/21/07, David Abrahams
"Chris Weed"
writes: Hi, I am getting the wrong result for the exponential of complex numbers such as the following:
#include
#include #include <iostream> int main() { typedef boost::mpl::math::string_c_to_double<'-',2,'.',0>::type minus_two;
I don't know anything about Boost.MPLMath, but I suspect that the 2 and the 0 need to be quoted also.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Hi, I tried that, and got the same result. Chris
--- Chris Weed wrote:
Hi, I am getting the wrong result for the exponential of complex numbers such as the following:
#include
#include #include <iostream> int main() { typedef
boost::mpl::math::string_c_to_double<'-',2,'.',0>::type
minus_two; typedef
boost::mpl::times
::type minus_two_pi; typedef
boost::mpl::math::complex_number
imag_minus_two_pi; std::cout << imag_minus_two_pi() << std::endl;
std::cout <<
boost::mpl::math::exponential
<< 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
--- Cromwell Enage wrote:
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).
Sorry, I meant [-pi,pi]. Cromwell D. Enage ____________________________________________________________________________________ Don't pick lemons. See all the new 2007 cars at Yahoo! Autos. http://autos.yahoo.com/new_cars.html
Thanks,
that works great.
I also noticed that there is a problem with the double exponential metafunction.
For example:
#include
::type minus_two_pi;
std::cout << boost::mpl::math::exponential
--- Cromwell Enage wrote:
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).
Sorry, I meant [-pi,pi].
Cromwell D. Enage
____________________________________________________________________________________ Don't pick lemons. See all the new 2007 cars at Yahoo! Autos. http://autos.yahoo.com/new_cars.html _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
--- Chris Weed wrote:
I increased BOOST_MPL_LIMIT_MATH_EXPONENTIAL_SERIES to 32, but I am not sure what exactly this should be.
the example program outputs: 0.00186744
This is the correct output, verified by std::exp(-6.283185307) Unfortunately, increasing the value of the macro also results in an exponential increase in compile time (+10 min on my Pentium 4 workstation), but that's an issue for another thread. Cromwell D. Enage ____________________________________________________________________________________ Cheap talk? Check out Yahoo! Messenger's low PC-to-Phone call rates. http://voice.yahoo.com
participants (3)
-
Chris Weed
-
Cromwell Enage
-
David Abrahams