Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 5be21f5

Browse files
authored
Clarify BoolArrayAsBigInt behavior for negative numbers (#965)
Fix microsoft/QuantumLibraries#390.
1 parent ebaad05 commit 5be21f5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Simulation/QSharpFoundation/Convert/Convert.qs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,19 @@ namespace Microsoft.Quantum.Convert {
8585
/// The 0 element of the array is the least significant bit of the big integer.
8686
/// # Remarks
8787
/// 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.
88+
/// Note that the Boolean array is padded of the right with `false` values to a length that is a multiple of 8,
89+
/// and then treated as a little-endian notation of a positive or negative number following two's complement semantics.
90+
///
91+
/// # Example
92+
/// ```qsharp
93+
/// let bi1 = BoolArrayAsBigInt([true, false, true]); // Padded to 10100000 -> 5
94+
/// let bi2 = BoolArrayAsBigInt([false, false, false, false, false, false, false, true]); // Not padded -> -128
95+
/// ```
8896
function BoolArrayAsBigInt(a : Bool[]) : BigInt {
8997
body intrinsic;
9098
}
9199

100+
92101
/// # Summary
93102
/// Converts a given boolean value to an equivalent string representation.
94103
///

0 commit comments

Comments
 (0)