From 9b058185d47127db0f0c9fa22ce3011f2c9e1f0e Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Wed, 9 Mar 2022 13:14:56 -0800 Subject: [PATCH] Clarify BoolArrayAsBigInt behavior for negative numbers Fix https://github.com/microsoft/QuantumLibraries/issues/390. --- src/Simulation/QSharpFoundation/Convert/Convert.qs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Simulation/QSharpFoundation/Convert/Convert.qs b/src/Simulation/QSharpFoundation/Convert/Convert.qs index fb501496b73..ac3ad6dd85f 100644 --- a/src/Simulation/QSharpFoundation/Convert/Convert.qs +++ b/src/Simulation/QSharpFoundation/Convert/Convert.qs @@ -85,10 +85,19 @@ namespace Microsoft.Quantum.Convert { /// The 0 element of the array is the least significant bit of the big integer. /// # Remarks /// See [C# BigInteger constructor](https://docs.microsoft.com/dotnet/api/system.numerics.biginteger.-ctor?view=netframework-4.7.2#System_Numerics_BigInteger__ctor_System_Int64_) for more details. + /// Note that the Boolean array is padded of the right with `false` values to a length that is a multiple of 8, + /// and then treated as a little-endian notation of a positive or negative number following two's complement semantics. + /// + /// # Example + /// ```qsharp + /// let bi1 = BoolArrayAsBigInt([true, false, true]); // Padded to 10100000 -> 5 + /// let bi2 = BoolArrayAsBigInt([false, false, false, false, false, false, false, true]); // Not padded -> -128 + /// ``` function BoolArrayAsBigInt(a : Bool[]) : BigInt { body intrinsic; } + /// # Summary /// Converts a given boolean value to an equivalent string representation. ///