qrisp.inpl_mult#

inpl_mult(qf, mult_int, treat_overflow=True)[source]#

Performs inplace multiplication of a QuantumFloat with a classical integer. To prevent overflow errors, this function automatically adjusts the mantissa size. If you want to prevent this behavior, set treat_overflow = False.

Parameters:
qfQuantumFloat

The QuantumFloat to inplace-multiply.

mult_intint

The integer to perform the multiplication with.

treat_overflowbool

If set to False, the mantissa will not be extended to prevent overflow errors. The default is True.

Examples

We create a QuantumFloat, bring it to superposition and perform an inplace multiplication.

from qrisp import QuantumFloat, h, inpl_mult
a = QuantumFloat(5, signed = True)
h(a[0])
h(a[-1])
print(a)
# Yields: {0: 0.25, 1: 0.25, -32: 0.25, -31: 0.25}
inpl_mult(a, -5)
print(a)
# Yields: {0: 0.25, 155: 0.25, 160: 0.25, -5: 0.25}