Re: [eigen] compile-time sqrt |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] compile-time sqrt*From*: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>*Date*: Wed, 10 Feb 2010 19:57:33 -0500*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=RzT0r/CZtk9cFcZeEn7+IyKUBQDqSi+KaBDuE0Tb/Zk=; b=Me5gePQzNsoo0JyrqONG6s5NbXloj61RGy44/2ejy9rtKVWstFG3k7IGMl65Fj85Ab 4bJmo7yw0Z8GYssZ3SwxOsp1twjIS8uTw1deN5ZhXp4ikEf5Nxm4zbgTSFVmMuRlsvY8 ww0/kemvVyMPshKzOq6eEu7Hg8wStg5PcIvuU=*Domainkey-signature*: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=USKZshsItSWFo3AerECyGObPzBQTVlUnNTXwmul1XwfUXUqUQmNsiOnX4/bq6vTPIe 6NJlCMHYeHNczBAVD5JTbP0cpaVo0J1zJGxh5JzQiPIx8I4vFqZk5r9M7Iqbjau3SUg5 XFmYwqlfQXsDgN+3YuAKZk3P2tT/hGMfXIsqs=

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 > > >

**Follow-Ups**:**Re: [eigen] compile-time sqrt***From:*Benoit Jacob

**References**:**[eigen] compile-time sqrt***From:*Thomas Capricelli

**Messages sorted by:**[ date | thread ]- Prev by Date:
**[eigen] compile-time sqrt** - Next by Date:
**[eigen] good news from the alignment front** - Previous by thread:
**[eigen] compile-time sqrt** - Next by thread:
**Re: [eigen] compile-time sqrt**

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