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

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


On 05.05.2016 at 14:36, Ilja Honkonen wrote:
std::pow(float, int) actually gets promoted to std::pow(double, double).

Note that this is correct as of c++11:
http://en.cppreference.com/w/cpp/numeric/math/pow

Yes, I looked that up as well. I don't know what gave me the idea that there were pow(float, int) and pow(double, int) overloads.

This is especially bad for std::pow(x, 2). Inside Eigen we can use

Does pow(x, 2.0) fix it? If not, pow(x, float(2)) at least should...

Yes that would work, but it is inefficient. 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. But I admit that would either cause a branch or an inefficient power by squaring in case the exponent is big. I guess evaluating pow(x,2147483647) by repeated squaring is less efficient than exp2(log2(x)*2147483647) [which actually is a case where casting the exponent to float loses a tiny bit of precision].

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/