From c0d4e5e1a4a859bc040046c15112e79bae2bc06d Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Wed, 2 May 2012 22:29:32 +0200 Subject: [PATCH] fixed interger overflow error in dopri5, also changed some constant definitions to integers --- .../odeint/stepper/modified_midpoint.hpp | 12 +++--- boost/numeric/odeint/stepper/runge_kutta4.hpp | 40 +++++++++---------- .../odeint/stepper/runge_kutta4_classic.hpp | 8 ++-- .../odeint/stepper/runge_kutta_dopri5.hpp | 8 ++-- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/boost/numeric/odeint/stepper/modified_midpoint.hpp b/boost/numeric/odeint/stepper/modified_midpoint.hpp index 92cef6b7..3d461962 100644 --- a/boost/numeric/odeint/stepper/modified_midpoint.hpp +++ b/boost/numeric/odeint/stepper/modified_midpoint.hpp @@ -60,13 +60,13 @@ public : template< class System , class StateIn , class DerivIn , class StateOut > void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , const time_type &t , StateOut &out , const time_type &dt ) { - static const value_type val1 = static_cast< value_type >( 1.0 ); - static const value_type val05 = static_cast< value_type >( 0.5 ); + static const value_type val1 = static_cast< value_type >( 1 ); + static const value_type val05 = static_cast< value_type >( 1 ) / static_cast< value_type >( 2 ); m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ); const time_type h = dt / static_cast( m_steps ); - const time_type h2 = static_cast( 2.0 ) * h; + const time_type h2 = static_cast( 2 ) * h; typename odeint::unwrap_reference< System >::type &sys = system; @@ -184,13 +184,13 @@ public : state_type &x_mp , deriv_table_type &derivs ) { - static const value_type val1 = static_cast< value_type >( 1.0 ); - static const value_type val05 = static_cast< value_type >( 0.5 ); + static const value_type val1 = static_cast< value_type >( 1 ); + static const value_type val05 = static_cast< value_type >( 1 ) / static_cast< value_type >( 2 ); m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize< StateIn > , detail::ref( *this ) , detail::_1 ) ); const time_type h = dt / static_cast( m_steps ); - const time_type h2 = static_cast( 2.0 ) * h; + const time_type h2 = static_cast( 2 ) * h; typename odeint::unwrap_reference< System >::type &sys = system; diff --git a/boost/numeric/odeint/stepper/runge_kutta4.hpp b/boost/numeric/odeint/stepper/runge_kutta4.hpp index f10ef57d..64e937c5 100644 --- a/boost/numeric/odeint/stepper/runge_kutta4.hpp +++ b/boost/numeric/odeint/stepper/runge_kutta4.hpp @@ -42,7 +42,7 @@ struct rk4_coefficients_a1 : boost::array< Value , 1 > { rk4_coefficients_a1( void ) { - (*this)[0] = static_cast< Value >( 0.5 ); + (*this)[0] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); } }; @@ -50,10 +50,10 @@ template< class Value = double > struct rk4_coefficients_a2 : boost::array< Value , 2 > { rk4_coefficients_a2( void ) - { - (*this)[0] = static_cast(0.0); - (*this)[1] = static_cast(0.5); - } + { + (*this)[0] = static_cast(0); + (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); + } }; @@ -62,9 +62,9 @@ struct rk4_coefficients_a3 : boost::array< Value , 3 > { rk4_coefficients_a3( void ) { - (*this)[0] = static_cast(0.0); - (*this)[1] = static_cast(0.0); - (*this)[2] = static_cast(1.0); + (*this)[0] = static_cast(0); + (*this)[1] = static_cast(0); + (*this)[2] = static_cast(1); } }; @@ -72,24 +72,24 @@ template< class Value = double > struct rk4_coefficients_b : boost::array< Value , 4 > { rk4_coefficients_b( void ) - { - (*this)[0] = static_cast(1.0)/static_cast(6.0); - (*this)[1] = static_cast(1.0)/static_cast(3.0); - (*this)[2] = static_cast(1.0)/static_cast(3.0); - (*this)[3] = static_cast(1.0)/static_cast(6.0); - } + { + (*this)[0] = static_cast(1)/static_cast(6); + (*this)[1] = static_cast(1)/static_cast(3); + (*this)[2] = static_cast(1)/static_cast(3); + (*this)[3] = static_cast(1)/static_cast(6); + } }; template< class Value = double > struct rk4_coefficients_c : boost::array< Value , 4 > { rk4_coefficients_c( void ) - { - (*this)[0] = static_cast(0.0); - (*this)[1] = static_cast(0.5); - (*this)[2] = static_cast(0.5); - (*this)[3] = static_cast(1.0); - } + { + (*this)[0] = static_cast(0); + (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); + (*this)[2] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); + (*this)[3] = static_cast(1); + } }; diff --git a/boost/numeric/odeint/stepper/runge_kutta4_classic.hpp b/boost/numeric/odeint/stepper/runge_kutta4_classic.hpp index 783bf186..06093960 100644 --- a/boost/numeric/odeint/stepper/runge_kutta4_classic.hpp +++ b/boost/numeric/odeint/stepper/runge_kutta4_classic.hpp @@ -65,13 +65,13 @@ public : { // ToDo : check if size of in,dxdt,out are equal? - static const value_type val1 = static_cast< value_type >( 1.0 ); + static const value_type val1 = static_cast< value_type >( 1 ); m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ); typename odeint::unwrap_reference< System >::type &sys = system; - const time_type dh = static_cast< value_type >( 0.5 ) * dt; + const time_type dh = dt / static_cast< value_type >( 2 ); const time_type th = t + dh; // dt * dxdt = k1 @@ -98,8 +98,8 @@ public : // dt * m_dxh = k4 sys( m_x_tmp.m_v , m_dxh.m_v , t + dt ); //x += dt/6 * ( m_dxdt + m_dxt + val2*m_dxm ) - time_type dt6 = dt / static_cast< value_type >( 6.0 ); - time_type dt3 = dt / static_cast< value_type >( 3.0 ); + time_type dt6 = dt / static_cast< value_type >( 6 ); + time_type dt3 = dt / static_cast< value_type >( 3 ); stepper_base_type::m_algebra.for_each6( out , in , dxdt , m_dxt.m_v , m_dxm.m_v , m_dxh.m_v , typename operations_type::template scale_sum5< value_type , time_type , time_type , time_type , time_type >( 1.0 , dt6 , dt3 , dt3 , dt6 ) ); } diff --git a/boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp b/boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp index 377f49d7..cc9a109e 100644 --- a/boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp +++ b/boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp @@ -193,10 +193,10 @@ public : time_type dt = ( t_new - t_old ); value_type theta = ( t - t_old ) / dt; - value_type X1 = static_cast< value_type >( 5 ) * ( static_cast< value_type >( 2558722523 ) - static_cast< value_type >( 31403016 ) * theta ) / static_cast< value_type >( 11282082432 ); - value_type X3 = static_cast< value_type >( 100 ) * ( static_cast< value_type >( 882725551 ) - static_cast< value_type >( 15701508 ) * theta ) / static_cast< value_type >( 32700410799 ); - value_type X4 = static_cast< value_type >( 25 ) * ( static_cast< value_type >( 443332067 ) - static_cast< value_type >( 31403016 ) * theta ) / static_cast< value_type >( 1880347072 ) ; - value_type X5 = static_cast< value_type >( 32805 ) * ( static_cast< value_type >( 23143187 ) - static_cast< value_type >( 3489224 ) * theta ) / static_cast< value_type >( 199316789632 ); + value_type X1 = static_cast< value_type >( 5 ) * ( static_cast< value_type >( 2558722523LL ) - static_cast< value_type >( 31403016 ) * theta ) / static_cast< value_type >( 11282082432LL ); + value_type X3 = static_cast< value_type >( 100 ) * ( static_cast< value_type >( 882725551 ) - static_cast< value_type >( 15701508 ) * theta ) / static_cast< value_type >( 32700410799LL ); + value_type X4 = static_cast< value_type >( 25 ) * ( static_cast< value_type >( 443332067 ) - static_cast< value_type >( 31403016 ) * theta ) / static_cast< value_type >( 1880347072LL ) ; + value_type X5 = static_cast< value_type >( 32805 ) * ( static_cast< value_type >( 23143187 ) - static_cast< value_type >( 3489224 ) * theta ) / static_cast< value_type >( 199316789632LL ); value_type X6 = static_cast< value_type >( 55 ) * ( static_cast< value_type >( 29972135 ) - static_cast< value_type >( 7076736 ) * theta ) / static_cast< value_type >( 822651844 ); value_type X7 = static_cast< value_type >( 10 ) * ( static_cast< value_type >( 7414447 ) - static_cast< value_type >( 829305 ) * theta ) / static_cast< value_type >( 29380423 );