-
Notifications
You must be signed in to change notification settings - Fork 4
Faster twos_comp #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster twos_comp #16
Conversation
@Ajstros I tried the new
I would expect -16384 The previous function may have been poorly named. This function took unsigned register values represented in twos-complement and converted to signed integers. |
@lucask07 Right, I remember now. It seems like there are two possible things we might want to do that involve two's complement:
I think it would clear things up if we created separate functions for these. Something like >>>int_to_custom_signed([-5, 5], 16) # Same as binary_twos_comp([-5, 5], 16)
array([65531, 5])
>>>custom_signed_to_int([65531, 5], 16) # Same as twos_comp([65531, 5], 16)
array([-5, 5]) |
@Ajstros sounds like a plan -- go for it. I can't think of places where we are using an operation like |
@lucask07 I agree, although I am using |
@Ajstros The docstring for The comments of
|
As far as I can tell
The Numpy documentation for
so it seems the CPython two's complement form of the |
Recently, we added
binary_twos_comp
in thepyripherals.utils
module. We already hadtwos_comp
, but this was meant to be a bit clearer and perform the complete binary two's complement usable going to or from twos_complement form. It also takes advantage of numpy arrays rather than the for loops found intwos_comp
. This makesbinary_twos_comp
clearer, faster, and more generally applicable thantwos_comp
. For that reason, we are replacingtwos_comp
withbinary_twos_comp
, now renamed totwos_comp
.