Closed nthalpy closed 6 years ago
Was reading this item and my first reaction was; "but if they reduce it to a int, would that semantically be incorrect. Since its only 32 bits where one expects 64 bits in the specification of the language." But; int.MaxValue = 2,147,483,647 bits = 256 MB datatype... So if we really want to shift based on a Int64, our datatypes need to be at least 256 MB to have any value where the current Int64 is just 64 bits. Think to generate a cast to int would be good enough here.
foreach (var x in new Range(0L, (2L << (int) bitCount))) { // do some translated stuffs... }
This is indeed a code generation bug; I've entered it into our internal tracking system. It will be fixed in a coming release. Sorry about that!!
This is now fixed with the most recent update (0.2.1809.701).
According to https://docs.microsoft.com/en-us/quantum/quantum-qr-expressions?view=qsharp-preview, Q# provides arithmetic shift operator
<<<
and>>>
.And since Q# uses
Int64
type to express integer, following codetranslates to
and since both left hand and right hand is
Int64
, C# compiler throws following error:I think Q# compiler should translate arithmetic shift to something else, such as function does arithmetic shift with 2
Int64
values.