shiftr Function

private pure function shiftr(val, shift) result(res_value)

Arguments

Type IntentOptional Attributes Name
integer(kind=i8), intent(in) :: val
integer, intent(in) :: shift

Return Value integer(kind=i8)


Source Code

  pure function shiftr(val, shift) result(res_value)
    integer(i8), intent(in) :: val
    integer, intent(in)     :: shift
    integer(i8)             :: res_value
    integer(i8)             :: bit_mask1

    bit_mask1 = huge(val)
    if (shift == 0) then
      res_value = val
    else if (val < 0_i8) then
      res_value = ior(&
        rshift(iand(val, bit_mask1), shift),&
        lshift(1_i8, 63-shift))
    else
      res_value = rshift(val, shift)
    end if
  end function shiftr