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

btest , what's wrong...

lparedi
Beginner
840 Views
do k=1,10
ibip=0
do j=0,15
if(btest(k,j))ibip=ibip+1
enddo
write(6,*)k,ibip
enddo

stop
end



Version 12.0.X give wrong results...version 11 is ok.

0 Kudos
5 Replies
forcpp
New Contributor I
840 Views
The maximum bit positions for maximum integer, k=10, will be 4 that is j=0,3. This is the possible reason because of which you are getting wrong answer. I checked your code by ifort 12.0.3.167and it is giving wrong result because of wrong declaration. But, the gfortran compiler behaves differently and gives right answer with the present form of the code.
0 Kudos
Steven_L_Intel1
Employee
840 Views
Same program as here - where is this coming from?
0 Kudos
mecej4
Honored Contributor III
840 Views
> it is giving wrong result because of wrong declaration

What "wrong declaration"? The second argument to the intrinsic function btest(i, pos) is required to satisfy 0 pos < bit_size(i). Do you think there is a violation of this requirement in the test program?
0 Kudos
forcpp
New Contributor I
840 Views
This may be bug as I see some older posts. But this can be circumvented if we declare j = 0, 3. Moreover, I also noticed that the results are coming right up to j=0, 10. If we give j=0, 11 results go wrong.
0 Kudos
Steven_L_Intel1
Employee
840 Views
I don't see anything wrong with the source as posted. This is pretty much the exact same program as in the other thread. Clearly both of you read this somewhere - where?
0 Kudos
Reply