Boost logo

Boost :

From: Peder Holt (peder.holt_at_[hidden])
Date: 2005-10-31 13:42:18


On 10/31/05, Cromwell Enage <sponage_at_[hidden]> wrote:
> I've now added a BOOST_MPL_CFC_NO_MATH_DOUBLE macro
> that is defined in
> <boost/mpl/aux_/config/math_double.hpp> when it is
> known that BOOST_MPL_MATH_DOUBLE won't compile.
> Please send me your compiler-platform configuration if
> BOOST_MPL_MATH_DOUBLE doesn't work for you.
>
> Peder, The double_::aux::get_value function still
> returns a number 2^16 times too big on MSVC 7.1 when
> the input is a whole number.

I do not observe this on my VC7.1 compiler. What I see, is another effect:
Using setprecision(40) causes some overflow in the iostream formatting
of double, so that
800.0 is outputted as 8000000. This error is only present for whole numbers.
Reducing setprecision to 36 eliminates the problem, and for every
extra digit of precision you specify, you get another 0 appended.

Also, BOOST_MPL_MATH_DOUBLE is very unstable on VC7.1, For whole
numbers between 10 and 100 it ICE's (Not so for negative whole numbers
between -100 and -10)
Adding a . at the end of the number, prevents the ICE.
typedef BOOST_MPL_MATH_DOUBLE(56) type; <-ICE
typedef BOOST_MPL_MATH_DOUBLE(56.) type; <-OK

I also found a continued fraction representation for tangent that
converges much faster (and better) than any of the series
representation I have found:

http://functions.wolfram.com/ElementaryFunctions/Tan/10/

Here is an implementation of this series. It is much faster on the
tangent.cpp test file, and doesn't give warnings for double_....
Works in the range -pi/2,pi/2
(Remove the double/tangent.hpp overload first :)

    template <typename NumericTag>
    struct tangent_impl
    {
        /*
         * Continued fraction representation
(http://functions.wolfram.com/ElementaryFunctions/Tan/10)
         */
        template <
            typename AngleSquare
          , typename I
          , typename FractionCount
>
        struct fraction
        {
         private:
            typedef typename eval_if<
                        less<plus<int_<1>,I>,FractionCount>
                      , fraction<AngleSquare,plus<int_<1>,I>,FractionCount>
                      , mpl::int_<1>
>::type
                    next_term;

         public:
            typedef typename minus<
                        plus<
                            times<int_<2>,I>,int_<1>
>
                      , divides<AngleSquare,next_term>
>::type
                    type;
        };

        template <
            typename Angle
          , typename SeriesCount
>
        struct apply
#if !defined BOOST_MPL_CFG_NO_NESTED_FORWARDING
          : divides<Angle,typename
fraction<times<Angle,Angle>,int_<0>,SeriesCount>::type>
        {
#else
        {
            /*
             * Metafunction class return type.
             */
            typedef typename divides<
                        Angle
                      , typename
series<times<Angle,Angle>,int_<0>,SeriesCount>::type
>::type
                    type;
#endif /* BOOST_MPL_CFG_NO_NESTED_FORWARDING */
        };
    };

Regards,
Peder.

>
> Cromwell D. Enage
>
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk