microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/language/BigInt.qs
31lines · 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 | |
| 9 | function Main() : BigInt { |
| 10 | // Numbers can be declared in hex, octal, decimal, or binary. |
| 11 | let foo = 0x42L; |
| 12 | Message($"Hexadecimal BigInt: {foo}"); |
| 13 | let foo = 0o42L; |
| 14 | Message($"Octal BigInt: {foo}"); |
| 15 | let foo = 42L; |
| 16 | Message($"Decimal BigInt: {foo}"); |
| 17 | let foo = 0b101010L; |
| 18 | Message($"Binary BigInt: {foo}"); |
| 19 | |
| 20 | // Numbers can be operated upon in the usual ways, with addition (+), subtraction (-), |
| 21 | // multiplication (*), division (/), modulo (%), and exponentiation (^). |
| 22 | let foo = foo + 1L; |
| 23 | Message($"Addition result: {foo}"); |
| 24 | let foo = foo % 2L; |
| 25 | Message($"Modulo result: {foo}"); |
| 26 | // `BigInt`s being raised to an exponent take an `Int` as the exponent. |
| 27 | let foo = foo^2; |
| 28 | Message($"Exponentiation result: {foo}"); |
| 29 | |
| 30 | return foo; |
| 31 | } |
| 32 | |