BigInt runnableExamples: octal, binary, hex constructor (#16868)
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
This commit is contained in:
parent
2c70734913
commit
b8e8eaae66
1 changed files with 19 additions and 11 deletions
|
|
@ -10,11 +10,18 @@ func big*(integer: SomeInteger): JsBigInt {.importjs: "BigInt(#)".} =
|
||||||
## Constructor for `JsBigInt`.
|
## Constructor for `JsBigInt`.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
doAssert big(1234567890) == big"1234567890"
|
doAssert big(1234567890) == big"1234567890"
|
||||||
|
doAssert 0b1111100111.big == 0o1747.big and 0o1747.big == 999.big
|
||||||
|
|
||||||
func big*(integer: cstring): JsBigInt {.importjs: "BigInt(#)".} =
|
func big*(integer: cstring): JsBigInt {.importjs: "BigInt(#)".} =
|
||||||
## Constructor for `JsBigInt`.
|
## Constructor for `JsBigInt`.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
doAssert big"-1" == big"1" - big"2"
|
doAssert big"-1" == big"1" - big"2"
|
||||||
|
# supports decimal, binary, octal, hex:
|
||||||
|
doAssert big"12" == 12.big
|
||||||
|
doAssert big"0b101" == 0b101.big
|
||||||
|
doAssert big"0o701" == 0o701.big
|
||||||
|
doAssert big"0xdeadbeaf" == 0xdeadbeaf.big
|
||||||
|
doAssert big"0xffffffffffffffff" == (1.big shl 64.big) - 1.big
|
||||||
|
|
||||||
func toCstring*(this: JsBigInt; radix: 2..36): cstring {.importjs: "#.toString(#)".} =
|
func toCstring*(this: JsBigInt; radix: 2..36): cstring {.importjs: "#.toString(#)".} =
|
||||||
## Converts from `JsBigInt` to `cstring` representation.
|
## Converts from `JsBigInt` to `cstring` representation.
|
||||||
|
|
@ -190,17 +197,18 @@ proc high*(_: typedesc[JsBigInt]): JsBigInt {.error:
|
||||||
|
|
||||||
|
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let big1: JsBigInt = big"2147483647"
|
block:
|
||||||
let big2: JsBigInt = big"666"
|
let big1: JsBigInt = big"2147483647"
|
||||||
doAssert JsBigInt isnot int
|
let big2: JsBigInt = big"666"
|
||||||
doAssert big1 != big2
|
doAssert JsBigInt isnot int
|
||||||
doAssert big1 > big2
|
doAssert big1 != big2
|
||||||
doAssert big1 >= big2
|
doAssert big1 > big2
|
||||||
doAssert big2 < big1
|
doAssert big1 >= big2
|
||||||
doAssert big2 <= big1
|
doAssert big2 < big1
|
||||||
doAssert not(big1 == big2)
|
doAssert big2 <= big1
|
||||||
let z = JsBigInt.default
|
doAssert not(big1 == big2)
|
||||||
doAssert $z == "0n"
|
let z = JsBigInt.default
|
||||||
|
doAssert $z == "0n"
|
||||||
block:
|
block:
|
||||||
var a: seq[JsBigInt]
|
var a: seq[JsBigInt]
|
||||||
a.setLen 2
|
a.setLen 2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue