mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-03 04:24:45 +00:00
js: improve tests + some docs (#16727)
* js: improve tests * _ * _ * _ * fixup
This commit is contained in:
@@ -92,8 +92,18 @@ func `==`*(x, y: JsBigInt): bool {.importjs: "(# == #)".} =
|
||||
doAssert big"42" == big"42"
|
||||
|
||||
func `**`*(x, y: JsBigInt): JsBigInt {.importjs: "((#) $1 #)".} =
|
||||
# (#) needed, refs https://github.com/nim-lang/Nim/pull/16409#issuecomment-760550812
|
||||
runnableExamples:
|
||||
doAssert (big"9" ** big"5") == big"59049"
|
||||
doAssert big"2" ** big"64" == big"18446744073709551616"
|
||||
doAssert big"-2" ** big"3" == big"-8"
|
||||
doAssert -big"2" ** big"2" == big"4" # parsed as: (-2n) ** 2n
|
||||
doAssert big"0" ** big"0" == big"1" # edge case
|
||||
var ok = false
|
||||
try: discard big"2" ** big"-1" # raises foreign `RangeError`
|
||||
except: ok = true
|
||||
doAssert ok
|
||||
# pending https://github.com/nim-lang/Nim/pull/15940, simplify to:
|
||||
# doAssertRaises: discard big"2" ** big"-1" # raises foreign `RangeError`
|
||||
|
||||
func `xor`*(x, y: JsBigInt): JsBigInt {.importjs: "(# ^ #)".} =
|
||||
runnableExamples:
|
||||
|
||||
Reference in New Issue
Block a user