Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Interesting little snippet of code

JohnNichols
Valued Contributor III
712 Views
program large_integers
  integer,parameter :: k5 = selected_int_kind(5)
  integer,parameter :: k15 = selected_int_kind(15)
  integer(kind=k5) :: i5
  integer(kind=k15) :: i15

  print *, huge(i5), huge(i15)

  ! The following inequalities are always true
  print *, huge(i5) >= 10_k5**5-1
  print *, huge(i15) >= 10_k15**15-1
end program large_integers

Screenshot 2023-02-16 090625.png

has someone changed the photo insert page, it looks different, more professional.  

 

from 

https://gcc.gnu.org/onlinedocs/gfortran/SELECTED_005fINT_005fKIND.html#SELECTED_005fINT_005fKIND 

0 Kudos
4 Replies
Steve_Lionel
Honored Contributor III
688 Views

Yes, this style is what I recommend to people. What do you find interesting about it? 

0 Kudos
JohnNichols
Valued Contributor III
682 Views

The T / F statements in the print, new one on me.  

0 Kudos
Steve_Lionel
Honored Contributor III
672 Views

Logical expressions are new to you?

0 Kudos
JohnNichols
Valued Contributor III
633 Views

No, but the use of the logical inside the print statement is just an programmer showing off.  This is meant to be a demonstration code, not a look at me how smart I can be with the code.  

Code should read like a novel, not hide like Latin poetry from 200BC. 

0 Kudos
Reply