Closed AhmedCode99 closed 12 months ago
Hi Ahmed,
I have no idea how one would encode the fact that the number was negative into qubits from binary (and frankly it scares me), but you could probably get away with making some conditional statement at the beginning that slaps a negative sign on. I.e.
sign = 1
if (multiplicand < 0) != (multiplier < 0):
sign = -1
multiplier = abs(multiplier)
multiplicand = abs(multiplicand)
Where since the rest of the code is unfriendly to binary representations of negative numbers (because I think that gets weird), once we've tracked the sign we repeat the normal code with the absolute value of the two numbers.
We just make sure to return at the end
return sign*int(list(result.get_counts())[0],2)
Which on my end returns the correct value for negative numbers multiplied by positive and vice versa. I think this should be acceptable since like I said I don't know how one would encode a negative number into qubits, though that would be interesting to look into...
The code does not work when multiplying a positive and a negative number. Any ideas on how to fix it?