Renamed arguments inside binary_sum.
Added carry return (VERY NOT SURE IF IT WORKS CORRECTLY).
This commit is contained in:
parent
132a0b5659
commit
d2df4bbf28
|
@ -67,23 +67,25 @@ def get_memory(variable_name: str) -> list[bool]:
|
|||
print(f"[ERROR] The {variable_name} may contain only 1-s and 0-s!")
|
||||
|
||||
|
||||
def binary_sum(a_original: BasicRegister, b_original: BasicRegister) -> BasicRegister:
|
||||
def binary_sum(first_term: BasicRegister, second_term: BasicRegister, return_remainder: bool = False)\
|
||||
-> BasicRegister | tuple[BasicRegister, int]:
|
||||
"""
|
||||
Sums two registers' values.
|
||||
|
||||
:param BasicRegister a_original: First register.
|
||||
:param BasicRegister b_original: Second register.
|
||||
:param BasicRegister first_term: First register.
|
||||
:param BasicRegister second_term: Second register.
|
||||
:param bool return_remainder: True to return the tuple, False to return just the register.
|
||||
|
||||
:return: Register containing the sum.
|
||||
:rtype: BasicRegister
|
||||
:return: Register containing the sum or the tuple containing the register and carried radix.
|
||||
:rtype: BasicRegister | tuple[BasicRegister, int]
|
||||
"""
|
||||
size_a = len(a_original)
|
||||
size_b = len(b_original)
|
||||
size_a = len(first_term)
|
||||
size_b = len(second_term)
|
||||
|
||||
required_size = max(size_a, size_b)
|
||||
|
||||
a = a_original
|
||||
b = b_original
|
||||
a = first_term
|
||||
b = second_term
|
||||
|
||||
if size_a != size_b:
|
||||
a = a.adjusted_by_size(required_size)
|
||||
|
@ -100,4 +102,7 @@ def binary_sum(a_original: BasicRegister, b_original: BasicRegister) -> BasicReg
|
|||
final_bit_sum = a.memory[0] + b.memory[0] + carry
|
||||
c.memory[0] = bool(final_bit_sum & 1)
|
||||
|
||||
return c
|
||||
if return_remainder:
|
||||
return c, carry
|
||||
else:
|
||||
return c
|
||||
|
|
Loading…
Reference in New Issue