Last active
December 16, 2015 11:18
-
-
Save andreasvc/5426158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cdef extern from "macros.h": | |
# test whether the b'th bit of array a is set: | |
unsigned long TESTBIT(unsigned long a[], int b) | |
cdef unsigned long foo[2] | |
foo[0] = 281474976710656UL | |
foo[1] = 0 | |
# what the macro does: | |
print foo[0] & (1UL << 48) | |
if (foo[0] & (1UL << 48)): | |
print 'bit 48 is set' | |
# macro works fine on its own: | |
print TESTBIT(foo, 48) | |
if TESTBIT(foo, 48) != 0: | |
print 'bit 48 is really set' | |
if TESTBIT(foo, 48): | |
print 'bit 48 is set' | |
print TESTBIT(foo, 48) | |
if True and TESTBIT(foo, 48) != 0: | |
print 'bit 48 is really set' | |
# bug occurs when combined with other condition: | |
if True and TESTBIT(foo, 48): | |
print 'bit 48 is set' | |
else: | |
print 'bit 48 is NOT set?' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BITSIZE (8*sizeof(long)) | |
#define BITMASK(b) (1UL << ((b) % BITSIZE)) | |
#define BITSLOT(b) ((b) / BITSIZE) | |
#define TESTBIT(a, b) ((a)[BITSLOT(b)] & BITMASK(b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment