Boost logo

Boost Users :

From: Chris Weed (chrisweed_at_[hidden])
Date: 2007-01-24 09:39:29


I don't think this is what he means by 8.24 fixed-point.
I think he is looking for representing a number by 8 bits to the left
of the decimal, and 24 bits after the decimal, thus creating a special
32-bit number format.

I suspect you could use this library to do what you want, but I think
you would need a way to convert the MPL::Math floating-point
representation to your representation. It has been a while since I
looked at the code, but I recall that MPL::Math is essentially an
implementation of IEEE floating-point representation in a templated
class.

Chris

On 1/24/07, Cromwell Enage <sponage_at_[hidden]> wrote:
> --- 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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