In Boost ODEINT library, you can find a lot of static_cast
keyword such as:
template<
class State ,
class Value = double ,
class Deriv = State ,
class Time = Value ,
class Algebra = typename algebra_dispatcher< State >::algebra_type ,
class Operations = typename operations_dispatcher< State >::operations_type ,
class Resizer = initially_resizer
>
class runge_kutta_dopri5: ....
{
...
typedef typename stepper_base_type::value_type value_type;
...
template< class System , class StateIn , class DerivIn , class StateOut , class DerivOut >
void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt_in , time_type t ,
StateOut &out , DerivOut &dxdt_out , time_type dt )
{
const value_type a2 = static_cast<value_type> ( 1 ) / static_cast<value_type>( 5 );
const value_type a3 = static_cast<value_type> ( 3 ) / static_cast<value_type> ( 10 );
const value_type a4 = static_cast<value_type> ( 4 ) / static_cast<value_type> ( 5 );
const value_type a5 = static_cast<value_type> ( 8 )/static_cast<value_type> ( 9 );
....
Where value_type
is determined by template.
My question is that if value_type
is a simple type like double
, is there any difference between static_cast<value_type> ( 5 )
and (double)5
? I wonder why they have used such casting. Is it the same if value_type
is double&
or double&&
?