Re: [eigen] compile-time sqrt

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

The problem lies even deeper than that: ei_meta_sqrt takes an integer,
and actually floats can't be template parameters. So you can't use
ei_meta_sqrt for that.

In contexts where you're happy with just GCC, it's been able to
evaluate sqrt at compile time for a while. Since GCC 4.3, a lot more
functions are evaluated at compile time using MPFR. GCC 4.5 introduces
the same thing for complex numbers.

Thus, for lack of a better solution, you might just do a sqrt call and
rely on the compiler to optimize it at compile time.

An alternative is to compare x*x < eps instead of comparing x < sqrt(eps).

Benoit

2010/2/10 Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>:
>
> Hi.
>
> I sometimes need to use sqrt of epsilon (typically in unsupported/Eigen/src/NonLinearOptimization/chkder.h)
> Currently i do
> const Scalar eps = ei_sqrt(NumTraits<Scalar>::epsilon());
>
> but i'd like to have it computed at compile-time.. i'm not sure how to do this. I've tried :
> const Scalar eps = ei_meta_sqrt<NumTraits<Scalar>::epsilon()>::ret;
>
> but the compiler complais that epsilon() is a function call hence the template can't be done.
>
> Thomas
> --
> Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>
> http://www.freehackers.org/thomas
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/