On Monday, September 19, 2022 at 2:10:00 PM UTC+12, Robin Vowels wrote:
> On Monday, September 19, 2022 at 2:24:21 AM UTC+10, Ron Shepard wrote:
> > On 9/18/22 4:28 AM, Robin Vowels wrote: am
> > > On Sunday, September 18, 2022 at 2:05:48 PM UTC+10, jfh wrote:
> > >
> > >> Someone trying one of my programs with Silverfrost told me years ago that it wouldn't compile because i had tried to declare an integer variable with the smallest number of bits with selected-int-kind(0) .
> > > You mean, selected_int_kind(0).
> > > .
> > > You wanted an integer variable capable of storing values between -1 and +1 ?
> > > In other words, you wanted an integer variable capable of storing the value 0 [i.e., zero].
> > > You have to be joking.
> .
> > If there were ever a 1-bit integer kind introduced into the language,
> > then how would it be specified?
> .
> Well, selected_int_kind(0) won't do it, because the only value that
> could be stored is '0'. And maybe -1 if 2 bits are allocated.
> .
> Might need a BIT type for that.
> .
> > selected_int_kind(1) would require at
> > least 5 bits, rounded up to 8-bits on most modern compute
s. So unless
> > the selected_int_kind() function is changed somehow (e.g. to specify
> > directly the minimum number of bits), asking for 0 decimal digits might
> > be the only way -- you ask for 0-bits and it would get rounded up to 1-bit.
Robin Vowels seems to assume that selected_int_kind(0) is asking for an integer kind that can only provide integers n such that -1 < n < 1. It is not. It is asking for the integer kind with the least decimal exponent range that includes 0. I have now found that ifort agrees with gfortran and g95 by giving 8-bit integers with huge = 127. If Robin were right then selected_int_kind(1) would give an integer type that allows -10 < n < 10 but not one that allows -100 < n < 100. I was not surprised that all three of those compilers print 127 four times with this program, and they are standard-conforming in that respect because none of those compilers has a 4-bit integer type. My revised 4-line program:
integer, parameter:: ineg = selected_int_kind(-1), i0 = selected_int_kind(0),&
i1 = selected_int_kind(1), i2 = selected_int_kind(2)
print *, huge(0_ineg),huge(0_i0),huge(0_i1),huge(0_i2)
end program