headmyshoulder / odeint-v2

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

Bug in ODEint Stepper controlled_runge_kutta header file #80

Closed ragatwi closed 11 years ago

ragatwi commented 11 years ago

I noticed a bug in one of the files and wanted to report it to you. I was compiling my code on two different machines and found out that it wasn't working one machine when I switched my value_type from double to float. I was able to compile my code on one machine, but not on another. Then I found out I was using two different versions of ODEint. The error came from the line 723 in controlled_runge_kutta.hpp in folder boost/numeric/odeint/stepper. The line is:

max_rel_err = max BOOST_PREVENT_MACRO_SUBSTITUTION ( pow( 5.0 , -m_stepper.stepper_order() ) , max_rel_err )

The error during compilation was: /usr/include/boost/numeric/odeint/stepper/controlled_runge_kutta.hpp(723): error: no instance of overloaded function "max" matches the argument list argument types are: (double, value_type)

This I thought was coming from determining max of double and float as I noticed the static_cast declarations within the file to take care of value type declarations being either float or double and I just switched line 723 to

max_rel_err = max BOOST_PREVENT_MACRO_SUBSTITUTION ( static_cast( pow( 5.0 , -m_stepper.stepper_order() ) ), max_rel_err )

or

max_rel_err = max BOOST_PREVENT_MACRO_SUBSTITUTION ( pow( static_cast( 5.0 ), static_cast( -m_stepper.stepper_order()) ) , max_rel_err )

and it worked.

mariomulansky commented 11 years ago

I reproduced the problem, created a test case and fixed it by adding the static casts from the second version above. If you want you can update from github, this should fix the error. Thanks for reporting