You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
There was something wrong when I tried to print the result of DoubleAsFixedPoint. After debugging, I found two errors in its source code.
When integerBits or fractionalBits is negative, it undergoes no validation, and logically, it will execute successfully if the sum of integerBits and fractionalBitsis greater than 0. However, negative numbers are meaningless here. For example, the official documentation's description of integerBits states: "Assumed number of integer bits (including the sign bit)."
Another error is running the following program will lead to an overflow. The content of the error is in this line the related line
, the value of rescaledConstant is too big to calculate.
To Reproduce
namespaceTest{openMicrosoft.Quantum.Logical;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Oracles;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
@EntryPoint()
operation main(): Unit {
mutable integerBits=4;mutablefractionalBits=64;mutablevalue=9.1;mutableAPIResult=DoubleAsFixedPoint(integerBits,fractionalBits,value);Message($"{APIResult}");}}
Expected behavior
Add fact statements to the FixedPointAsBoolArray function to prompt integerBits and fractionalBits should be positive.
The overflow problem with the Floor is traced to the Truncate function.
Actual behavior
System.OverflowException: “Arithmetic operation resulted in an overflow.”
Describe the bug
There was something wrong when I tried to print the result of
DoubleAsFixedPoint.After debugging, I found two errors in its source code.integerBitsorfractionalBitsis negative, it undergoes no validation, and logically, it will execute successfully if the sum ofintegerBitsandfractionalBitsis greater than0. However, negative numbers are meaningless here. For example, the official documentation's description of integerBits states: "Assumed number of integer bits (including the sign bit)."QuantumLibraries/Numerics/src/FixedPoint/Convert.qs
Line 35 in 025a812
rescaledConstantis too big to calculate.To Reproduce
Expected behavior
Add fact statements to the
FixedPointAsBoolArrayfunction to promptintegerBitsandfractionalBitsshould be positive.The overflow problem with the
Flooris traced to theTruncatefunction.Actual behavior
System.OverflowException: “Arithmetic operation resulted in an overflow.”System information
Additional context
We can submit a PR to fix this bug QuantumLibraries.