microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/language/BigInt.qs
34lines · modecode
| 1 | /// # Sample |
| 2 | /// BigInt |
| 3 | /// |
| 4 | /// # Description |
| 5 | /// Value literals for the `BigInt` type are always postfixed with L and |
| 6 | /// can be expressed in binary, octal, decimal, or hexadecimal representation. |
| 7 | /// `BigInt`s can be arbitrarily large, as opposed to `Int`s which have a size limit. |
| 8 | namespace MyQuantumApp { |
| 9 | |
| 10 | @EntryPoint() |
| 11 | function Main() : BigInt { |
| 12 | // Numbers can be declared in hex, octal, decimal, or binary. |
| 13 | let foo = 0x42L; |
| 14 | Message($"Hexadecimal BigInt: {foo}"); |
| 15 | let foo = 0o42L; |
| 16 | Message($"Octal BigInt: {foo}"); |
| 17 | let foo = 42L; |
| 18 | Message($"Decimal BigInt: {foo}"); |
| 19 | let foo = 0b101010L; |
| 20 | Message($"Binary BigInt: {foo}"); |
| 21 | |
| 22 | // Numbers can be operated upon in the usual ways, with addition (+), subtraction (-), |
| 23 | // multiplication (*), division (/), modulo (%), and exponentiation (^). |
| 24 | let foo = foo + 1L; |
| 25 | Message($"Addition result: {foo}"); |
| 26 | let foo = foo % 2L; |
| 27 | Message($"Modulo result: {foo}"); |
| 28 | // `BigInt`s being raised to an exponent take an `Int` as the exponent. |
| 29 | let foo = foo^2; |
| 30 | Message($"Exponentiation result: {foo}"); |
| 31 | |
| 32 | return foo; |
| 33 | } |
| 34 | } |
| 35 | |