- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The above documentation notes that the first parameter "Must be in the range 0 (least significant bit) to 31 (most significant bit)", but also notes that the second parameter can be an INTEGER(4) or an INTEGER(8). Does the function support testing bits 32-63, or does it only support examining the first 32 bytes of a 64-bit operand?
A quick test of an example program shows that it does indeed correctly support examining the upper bits of 64-bit operands, so it appears the documentation is incorrect for the "bitnum" parameter.
It is also unclear as to what happens if you attempt to examine higher-order bits of 32-bit operands:
INTEGER*4 A
A = 32768
IF ( BIT(41, A) ) WRITE(*,*) 'TEST PASSED'
The above compiles and executes successfully (and no output is generated), but is it legal, and/or is it addressing beyond the scope of 'A'?
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The documentation on the related subroutines BIC/BIS seems clear enough:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
program Console31
use IFPORT
implicit none
INTEGER*2 A,B
Integer*4 pos
pos = 41
A = 32767
B = A + 1
if(B < 0) then
write(*,*)" Wrong Integer type"
else IF ( BTEST(41, A) .eq. 1) then
WRITE(*,*) 'TEST PASSED'
else
write(*,*) "Something bad happened"
end if
end program Console31
Should BTEST not test for the integer length? Just a thought.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would be reasonable to do so, but I doubt it happens.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No I checked it does not, so I added a simple test. Of course to test for all integers the else if would get a lot longer.
Should it not be checked at compile time? Is this not a bug?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's not a bug - such checking is not required. You could have a variable with the position and the compiler can't check. The function could check and raise some sort of error.
NAG Fortran does check at compile time:
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7108
Error: t.f90, line 2: POS argument (41) to intrinsic BTEST out of range (0:31)
[NAG Fortran Compiler error termination, 1 error]
I'll note that the test case above gets the arguments in the wrong order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Apart from the other issues that have been discussed, please note that the line of code
else IF ( BTEST(41, A) .eq. 1) then
is in error since BTEST is of type logical, and its returned value is being compared to the integer constant 1.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page