u32_to_int32 Function

private pure function u32_to_int32(u) result(r)

Reinterpret an unsigned 32-bit value held in [0, 2**32) as the signed int32 with the same bit pattern. Done arithmetically rather than with transfer, and without ever passing an out-of-range value to int.

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: u

Return Value integer(kind=int32)


Called by

proc~~u32_to_int32~~CalledByGraph proc~u32_to_int32 u32_to_int32 proc~pcg32_next pcg32_t%pcg32_next proc~pcg32_next->proc~u32_to_int32

Source Code

   pure function u32_to_int32(u) result(r)
      !! Reinterpret an unsigned 32-bit value held in [0, 2**32) as the signed
      !! `int32` with the same bit pattern. Done arithmetically rather than with
      !! `transfer`, and without ever passing an out-of-range value to `int`.
      integer(int64), intent(in) :: u
      integer(int32) :: r

      if (u >= TWO_TO_31) then
         r = int(u - TWO_TO_32, int32)
      else
         r = int(u, int32)
      end if
   end function u32_to_int32