| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | num | |||
| real(kind=dp), | intent(in) | :: | r |
elemental function stochastic_round_r(num, r) result(i) ! Perform the stochastic rounding of the above function where the ! random number is already specified. real(dp), intent(in) :: num, r integer :: i real(dp) :: res i = int(num) res = num - real(i, dp) if(abs(res) >= 1.0e-12_dp) then if(abs(res) > r) & i = i + nint(sign(1.0_dp, num)) end if end function stochastic_round_r