headmyshoulder / odeint-v2

odeint - solving ordinary differential equations in c++ v2
http://headmyshoulder.github.com/odeint-v2/
Other
337 stars 102 forks source link

Switch fabs for std::abs in new adaptive Adams-Bashforth-Moulton stepper #214

Closed ds283 closed 6 years ago

ds283 commented 6 years ago

I have been experimenting with the new adaptive Adams-Bashforth-Moulton stepper recently merged into odeint-v2. However, I've noticed that it doesn't play so well with floating-point value types other than double because some code in controlled_adams_bashforth_moulton.hpp, adaptive_adams_coefficients.hpp and pid_step_adjuster.hpp extract absolute values using fabs() without a namespace qualifier.

My understanding is that unqualified fabs() doesn't have overloads for types other than double (eg. http://www.cplusplus.com/reference/cmath/fabs/) — for example, at least on my platform there is already a problem at the level of using long double which clang warns will be implicitly narrowed to double. My understanding is that only std::fabs() or std::abs() have overloads for other types, and this seems to fit with the rest of odeint-v2 where std::abs() is normally used except for some parts of the vexcl interface.

This patch changes the uses of fabs() for std::abs() in just the three files mentioned at the top.

mariomulansky commented 6 years ago

You are correct, std::abs should be used.