2e2e15cec2
For these 3 bitwise operations there are now fast functions for positive-only arguments, and general functions for arbitrary sign arguments (the fast functions are the existing implementation). By default the fast functions are not used (to save space) and instead the general functions are used for all operations. Enable MICROPY_OPT_MPZ_BITWISE to use the fast functions for positive arguments.
146 lines
5.2 KiB
Python
146 lines
5.2 KiB
Python
print(0 & (1 << 80))
|
|
print(0 & (1 << 80) == 0)
|
|
print(bool(0 & (1 << 80)))
|
|
|
|
a = 0xfffffffffffffffffffffffffffff
|
|
print(a & (1 << 80))
|
|
print((a & (1 << 80)) >> 80)
|
|
print((a & (1 << 80)) >> 80 == 1)
|
|
|
|
# test negative on rhs
|
|
a = 123456789012345678901234567890
|
|
print(a & -1)
|
|
print(a & -2)
|
|
print(a & -2345678901234567890123456789)
|
|
print(a & (-a))
|
|
print(a & (-a - 1))
|
|
print(a & (-a + 1))
|
|
|
|
# test negative on lhs
|
|
a = 123456789012345678901234567890
|
|
print(-1 & a)
|
|
print(-2 & a)
|
|
print(-2345678901234567890123456789 & a)
|
|
print((-a) & a)
|
|
print((-a) & 0xffffffff)
|
|
print((-a) & 0xffffffffffffffffffffffffffffffff)
|
|
print((-a) & 2)
|
|
print((-(1 << 70)) & 2)
|
|
|
|
# test negative on lhs and rhs
|
|
mpz = 1 << 70
|
|
a = 123456789012345678901234567890
|
|
print(-1 & (-a))
|
|
print(-2 & (-a))
|
|
print(-2345678901234567890123456789 & (-a))
|
|
print((-a) & (-a))
|
|
print((-a) & (-0xffffffff))
|
|
print((-a) & (-0xffffffffffffffffffffffffffffffff))
|
|
print((-1) & (-0xffffffffffffffffffffffffffffffff))
|
|
print((-a) & (-2))
|
|
print((-mpz) & (-2))
|
|
|
|
# test + +
|
|
|
|
print( 97989513389222316022151446562729620153292831887555425160965597396
|
|
& 23716683549865351578586448630079789776107310103486834795830390982)
|
|
|
|
print( 53817081128841898634258263553430908085326601592682411889506742059
|
|
& 37042558948907407488299113387826240429667200950043601129661240876)
|
|
|
|
print( 26167512042587370698808974207700979337713004510730289760097826496
|
|
& 98456276326770292376138852628141531773120376436197321310863125849)
|
|
|
|
print( 21085380307304977067262070503651827226504797285572981274069266136
|
|
& 15928222825828272388778130358888206480162413547887287646273147570)
|
|
|
|
print( 40827393422334167255488276244226338235131323044408420081160772273
|
|
& 63815443187857978125545555033672525708399848575557475462799643340)
|
|
|
|
print( 5181013159871685724135944379095645225188360725917119022722046448
|
|
& 59734090450462480092384049604830976376887859531148103803093112493)
|
|
|
|
print( 283894311
|
|
& 86526825689187217371383854139783231460931720533100376593106943447)
|
|
|
|
print( 40019818573920230246248826511203818792007462193311949166285967147
|
|
& 9487909752)
|
|
|
|
# test - +
|
|
|
|
print( -97989513389222316022151446562729620153292831887555425160965597396
|
|
& 23716683549865351578586448630079789776107310103486834795830390982)
|
|
|
|
print( -53817081128841898634258263553430908085326601592682411889506742059
|
|
& 37042558948907407488299113387826240429667200950043601129661240876)
|
|
|
|
print( -26167512042587370698808974207700979337713004510730289760097826496
|
|
& 98456276326770292376138852628141531773120376436197321310863125849)
|
|
|
|
print( -21085380307304977067262070503651827226504797285572981274069266136
|
|
& 15928222825828272388778130358888206480162413547887287646273147570)
|
|
|
|
print( -40827393422334167255488276244226338235131323044408420081160772273
|
|
& 63815443187857978125545555033672525708399848575557475462799643340)
|
|
|
|
print( -5181013159871685724135944379095645225188360725917119022722046448
|
|
& 59734090450462480092384049604830976376887859531148103803093112493)
|
|
|
|
print( -283894311
|
|
& 86526825689187217371383854139783231460931720533100376593106943447)
|
|
|
|
print( -40019818573920230246248826511203818792007462193311949166285967147
|
|
& 9487909752)
|
|
|
|
# test + -
|
|
|
|
print( 97989513389222316022151446562729620153292831887555425160965597396
|
|
& -23716683549865351578586448630079789776107310103486834795830390982)
|
|
|
|
print( 53817081128841898634258263553430908085326601592682411889506742059
|
|
& -37042558948907407488299113387826240429667200950043601129661240876)
|
|
|
|
print( 26167512042587370698808974207700979337713004510730289760097826496
|
|
& -98456276326770292376138852628141531773120376436197321310863125849)
|
|
|
|
print( 21085380307304977067262070503651827226504797285572981274069266136
|
|
& -15928222825828272388778130358888206480162413547887287646273147570)
|
|
|
|
print( 40827393422334167255488276244226338235131323044408420081160772273
|
|
& -63815443187857978125545555033672525708399848575557475462799643340)
|
|
|
|
print( 5181013159871685724135944379095645225188360725917119022722046448
|
|
& -59734090450462480092384049604830976376887859531148103803093112493)
|
|
|
|
print( 283894311
|
|
& -86526825689187217371383854139783231460931720533100376593106943447)
|
|
|
|
print( 40019818573920230246248826511203818792007462193311949166285967147
|
|
& -9487909752)
|
|
|
|
# test - -
|
|
|
|
print( -97989513389222316022151446562729620153292831887555425160965597396
|
|
& -23716683549865351578586448630079789776107310103486834795830390982)
|
|
|
|
print( -53817081128841898634258263553430908085326601592682411889506742059
|
|
& -37042558948907407488299113387826240429667200950043601129661240876)
|
|
|
|
print( -26167512042587370698808974207700979337713004510730289760097826496
|
|
& -98456276326770292376138852628141531773120376436197321310863125849)
|
|
|
|
print( -21085380307304977067262070503651827226504797285572981274069266136
|
|
& -15928222825828272388778130358888206480162413547887287646273147570)
|
|
|
|
print( -40827393422334167255488276244226338235131323044408420081160772273
|
|
& -63815443187857978125545555033672525708399848575557475462799643340)
|
|
|
|
print( -5181013159871685724135944379095645225188360725917119022722046448
|
|
& -59734090450462480092384049604830976376887859531148103803093112493)
|
|
|
|
print( -283894311
|
|
& -86526825689187217371383854139783231460931720533100376593106943447)
|
|
|
|
print( -40019818573920230246248826511203818792007462193311949166285967147
|
|
& -9487909752)
|