|
Boost Users : |
From: Cromwell Enage (sponage_at_[hidden])
Date: 2007-01-24 09:12:30
--- Michael Marcin wrote:
> I hadn't heard of MPL.Math before...
>
> I was actually looking for a way the other day of
> computing a fixed-point sin lookup table at
> compile-time using Taylor series approximation for
> a fixed-point class I have templated on magnitude
> and fractional bit count. I ended up getting lost
> and wrote a small program to generate a table and
> copy & pasted the output into a source file for
> the fixed-point precision I was using at present.
>
> It seems that it would be nice to be able to
> generate a new table for say 8.24 fixed-point
> without needed to rerun an external tool.
#include <iostream>
#include <boost/mpl/math/double.hpp>
#include <boost/mpl/math/sine.hpp>
#include <boost/mpl/runtime_cast.hpp>
using namespace boost;
using namespace mpl;
using namespace math;
int main()
{
sine<string_c_to_double<8,'.',2,4> >::type
your_answer;
// The runtime_cast function template
// converts the internal representation
// to the template argument type
// for readability.
std::cout
<< runtime_cast<double>(your_answer)
<< std::endl;
return 0;
}
> Does this seem like the sort of thing MPL.Math
> could help with?
You can look at the sine.cpp example program and see
for yourself. As for the sine metafunction
implementation, the Taylor series is actually built
using a combination of Boost.Preprocessor macros and
intermediary typedefs instead of template recursion.
> Thanks,
No problem.
> Michael Marcin
Cromwell D. Enage
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net