[UP]


Manual Reference Pages  - trailz (3)

NAME

trailz(3f) - [FORTRAN:INTRINSIC:BIT INQUIRY] Number of trailing zero bits of an integer

SYNTAX

result = trailz(i) integer :: result integer(kind=NNN),intent(in) :: i

DESCRIPTION

TRAILZ returns the number of trailing zero bits of an INTEGER value

ARGUMENTS

I Shall be of type INTEGER.

RETURN VALUE

The type of the return value is the default INTEGER. If all the bits of I are zero, the result value is bit_size(I).

EXAMPLE

Sample program:

    program demo_trailz
    use, intrinsic :: iso_fortran_env, only : integer_kinds, &
    & int8, int16, int32, int64
    implicit none
    integer(kind=int64) :: i, value
      write(*,*)’Default integer:’
      write(*,*)’bit_size=’,bit_size(0)
      write(*,’(1x,i3,1x,i3,1x,b0)’)-1,trailz(1),-1
      write(*,’(1x,i3,1x,i3,1x,b0)’)0,trailz(0),0
      write(*,’(1x,i3,1x,i3,1x,b0)’)1,trailz(1),1
      write(*,’(" huge(0)=",i0,1x,i0,1x,b0)’)huge(0),trailz(huge(0)),huge(0)
      write(*,*)
      write(*,*)’integer(kind=int64):’
      do i=-1,62,5
         value=2**i
         write(*,’(i19,1x,i3,1x,b64.64)’)value,trailz(value),value
      enddo
      value=huge(i)
      write(*,’(i19,1x,i3,1x,b64.64,"(huge(0_int64))")’) &
      & value,trailz(value),value
    end program demo_trailz
Results:

   Default integer:
   bit_size=          32
    -1   0 11111111111111111111111111111111
     0  32 0
     1   0 1
   huge(0)=2147483647 0 1111111111111111111111111111111

integer(kind=int64): 0 64 \ 00000000000000000000000000000000000000000000000000000000000000 16 4 \ 00000000000000000000000000000000000000000000000000000000010000 512 9 \ 00000000000000000000000000000000000000000000000000001000000000 16384 14 \ 00000000000000000000000000000000000000000000000100000000000000 524288 19 \ 00000000000000000000000000000000000000000010000000000000000000 16777216 24 \ 00000000000000000000000000000000000001000000000000000000000000 536870912 29 \ 00000000000000000000000000000000100000000000000000000000000000 17179869184 34 \ 00000000000000000000000000010000000000000000000000000000000000 549755813888 39 \ 00000000000000000000001000000000000000000000000000000000000000 17592186044416 44 \ 00000000000000000100000000000000000000000000000000000000000000 562949953421312 49 \ 00000000000010000000000000000000000000000000000000000000000000 18014398509481984 54 \ 00000001000000000000000000000000000000000000000000000000000000 576460752303423488 59 \ 00100000000000000000000000000000000000000000000000000000000000 9223372036854775807 0 \ 0111111111111111111111111111111111111111111111111111111111111111\ (huge(0_int64))

STANDARD

[[Fortran 2008]] and later

CLASS

[[Elemental function]]

SEE ALSO

bit_size(3), popcnt(3), poppar(3), leadz(3)

    JSU


trailz (3) March 11, 2021
Generated by manServer 1.08 from 1a8d4d5f-6d2c-4918-9b9c-4a37ef4627ba using man macros.