Line data Source code
1 : module m_ExpSave 2 : 3 : contains 4 : 5 0 : pure real function exp_save( x ) 6 : ! replace exp by a function that does not under/overflow dw09 7 : implicit none 8 : real, intent(in) :: x 9 : real, parameter :: maxexp = log( 2.0 ) * maxexponent( 2.0 ) 10 : real, parameter :: minexp = log( 2.0 ) * minexponent( 2.0 ) 11 : 12 0 : if ( abs( x ) > minexp .and. abs( x ) < maxexp ) then 13 0 : exp_save = exp( x ) 14 : else 15 0 : if ( x > 0 ) then 16 0 : if ( x > minexp ) then 17 : exp_save = exp( maxexp ) 18 : else 19 0 : exp_save = exp( minexp ) 20 : endif 21 : else 22 0 : if ( - x > minexp ) then 23 : exp_save = exp( - maxexp ) 24 : else 25 0 : exp_save = exp( - minexp ) 26 : endif 27 : endif 28 : endif 29 : 30 0 : end function exp_save 31 : 32 : end module m_ExpSave