有限なcharge incrementをoverflowさせずscalar accumulatorへ加える。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout) | :: | accumulator | |||
| real(kind=dp), | intent(in) | :: | increment | |||
| character(len=*), | intent(in) | :: | context |
subroutine checked_accumulate_charge(accumulator, increment, context) real(dp), intent(inout) :: accumulator real(dp), intent(in) :: increment character(len=*), intent(in) :: context if (.not. ieee_is_finite(accumulator) .or. .not. ieee_is_finite(increment)) then error stop trim(context)//' contains a non-finite charge.' end if if (increment > 0.0_dp .and. accumulator > huge(accumulator) - increment) then error stop trim(context)//' charge accumulation overflowed.' end if if (increment < 0.0_dp .and. accumulator < -huge(accumulator) - increment) then error stop trim(context)//' charge accumulation overflowed.' end if accumulator = accumulator + increment if (.not. ieee_is_finite(accumulator)) error stop trim(context)//' charge accumulation is not finite.' end subroutine checked_accumulate_charge