Minor rewrites.

This commit is contained in:
Rhinemann 2023-06-27 16:43:18 +03:00
parent 9fedc98310
commit 0f94f6d37a
1 changed files with 10 additions and 13 deletions

View File

@ -97,7 +97,8 @@ def binary_sum(first_term: BasicRegister, second_term: BasicRegister, return_rem
return result
def binary_subtraction_1_complement(first_term: BasicRegister, second_term: BasicRegister) -> BasicRegister:
def binary_subtraction(first_term: BasicRegister, second_term: BasicRegister) -> BasicRegister:
second_term.reverse()
result: BasicRegister
@ -105,7 +106,7 @@ def binary_subtraction_1_complement(first_term: BasicRegister, second_term: Basi
result, final_carry = binary_sum(first_term, second_term, True)
if final_carry:
return binary_sum(result, BasicRegister([True]))
return binary_sum(result, BasicRegister([True] * len(result)))
else:
result.reverse()
return result
@ -113,16 +114,12 @@ def binary_subtraction_1_complement(first_term: BasicRegister, second_term: Basi
def align_registers(first_register: BasicRegister, second_register: BasicRegister) \
-> tuple[BasicRegister, BasicRegister]:
size_a = len(first_register)
size_b = len(second_register)
first_size = len(first_register)
second_size = len(second_register)
required_size = max(size_a, size_b)
required_size = max(first_size, second_size)
a = first_register
b = second_register
if size_a != size_b:
a = a.adjusted_by_size(required_size)
b = b.adjusted_by_size(required_size)
return a, b
if first_size != second_size:
return first_register.adjusted_by_size(required_size), second_register.adjusted_by_size(required_size)
else:
return first_register, second_register