Re: [eigen] fix double-promotion in 3.3 Core/SpecialFunctions.h

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


On 2016-05-05 15:39, Marc Glisse wrote:
On Thu, 5 May 2016, Christoph Hertzberg wrote:
I (wrongfully) expected pow(x, 2) to be evaluated to x*x, at least if
the exponent is known at compile time and small. That could work, if
pow(float, int) got evaluated to some __builtin_pow function and the
compiler decides depending on the size of the exponent how to evaluate
it.

That is the case. Gcc has __builtin_pow (takes 2 double) and expands it
when the second argument is a small integer (though in this case it
produces (float)((double)x*(double)x)). More relevant builtins are
__builtin_powf (takes 2 floats) and __builtin_powif (takes a float and
an int).

Ok, my memory is not as bad as I thought. I recalled that something like that existed once. And as Ilja pointed out, at least gcc used to do that prior to C++11 (and apparently I missed the C++03 part when I looked it up).

However, writing pow(x,2) should really be avoided...

Yes, it is kind of annoying though to implement trivial square, cube, etc, functions for the few cases you need them (or to add a boost-dependency, unless you already do).


Christoph



--
 Dipl. Inf., Dipl. Math. Christoph Hertzberg

 Universität Bremen
 FB 3 - Mathematik und Informatik
 AG Robotik
 Robert-Hooke-Straße 1
 28359 Bremen, Germany

 Zentrale: +49 421 178 45-6611

 Besuchsadresse der Nebengeschäftsstelle:
 Robert-Hooke-Straße 5
 28359 Bremen, Germany

 Tel.:    +49 421 178 45-4021
 Empfang: +49 421 178 45-6600
 Fax:     +49 421 178 45-4150
 E-Mail:  chtz@xxxxxxxxxxxxxxxxxxxxxxxx

 Weitere Informationen: http://www.informatik.uni-bremen.de/robotik



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