* Implements #555. * Apply suggestions from code review Co-authored-by: Mariia Mykhailova <mamykhai@microsoft.com> * Change order of arguments. Co-authored-by: Mariia Mykhailova <mamykhai@microsoft.com>
This commit is contained in:
Родитель
ad3a6f19aa
Коммит
7b5cfc4e4c
|
@ -43,4 +43,46 @@ namespace Microsoft.Quantum.Arithmetic {
|
|||
|
||||
AddI(LittleEndian(fp1::Register), LittleEndian(fp2::Register));
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
/// Computes the additive inverse of `fp`.
|
||||
///
|
||||
/// # Input
|
||||
/// ## fp
|
||||
/// Fixed-point number to invert.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Numerical inaccuracies may occur depending on the
|
||||
/// bit-precision of the fixed-point number.
|
||||
///
|
||||
/// # See also
|
||||
/// - Microsoft.Quantum.Arithmetic.SubtractFxP
|
||||
operation InvertFxP(fp: FixedPoint) : Unit is Adj + Ctl {
|
||||
let (_, reg) = fp!;
|
||||
Invert2sSI(SignedLittleEndian(LittleEndian(reg)));
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
/// Computes `minuend - subtrahend` and stores the difference in `minuend`.
|
||||
///
|
||||
/// # Input
|
||||
/// ## subtrahend
|
||||
/// The subtrahend of the subtraction - the number to be subtracted.
|
||||
/// ## minuend
|
||||
/// The minuend of the subtraction - the number from which the other is subtracted.
|
||||
///
|
||||
/// # Remarks
|
||||
/// Computes the difference by inverting `subtrahend` before and after adding
|
||||
/// it to `minuend`. Notice that `minuend`, the first argument is updated.
|
||||
///
|
||||
/// # See also
|
||||
/// - Microsoft.Quantum.Arithmetic.AddFxP
|
||||
/// - Microsoft.Quantum.Arithmetic.InvertFxP
|
||||
operation SubtractFxP(minuend : FixedPoint, subtrahend : FixedPoint) : Unit is Adj + Ctl {
|
||||
within {
|
||||
InvertFxP(subtrahend);
|
||||
} apply {
|
||||
AddFxP(subtrahend, minuend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче