Specifications
These are some basic specifications.
apa::bint : Bitwise Not (~)
-
The bitwise not (~) of
\[y = -(x+1)\]bintis the same as Python’s not operator, or in general it performs a 2’s complement conversion.In
bintThis will be equivalent to adding 1 for thenumbermember, then flipping thesignmember to negative.
apa::bint’s bitwise logical &, |, ^ operators
-
The other bitwise logical operators of
bint(&, |, ^) applies a special 2’s complement conversion to negativebintparameters before applying the operators.If the output is negative we then again applies a special 2’s complement conversion.
This special 2’s complement conversion is different from the
bint::operator~, it involves padding the operands and thesigndoes not flip here.In general the output of these operators should be the same as python3’s bitwise logical operators.
apa::bint : Division
-
The division operator of
bintis more similar to C/C++ than in python.bintdon’t apply a floor function to the quotient, instead it stops calculating the value after the decimal.To show the difference here is an example:
-
C/C++ & bint division output:
\[-9/4 = -2\] -
Python3 floor division output:
\[-9//4 = -3\]
-
apa::bint : Modulo
-
Since the division of bint is more similar to C/C++ the modulo output of
bintin some cases for negative numbers will be different to the output of python’s modulo.-
C/C++ &
\[-9 \ mod \ 4 = -1\]bintmodulo output: -
Python3 modulo output:
\[-9 \ mod \ 4 = 3\]
This is because python uses the floor division to get the mod:
\[remainder = a - b \lfloor a/b\rfloor\]To achieve a python similar modulo result in C++ we can use this operation instead:
template<typename T> constexpr T mod(T num, T mod) { return ((num % mod) + mod) % mod; }
-