mirror of
https://github.com/status-im/nim-stint.git
synced 2025-02-16 08:57:18 +00:00
add $
alias for toString
This commit is contained in:
parent
1283d582a1
commit
7c11f7da07
11
stint/io.nim
11
stint/io.nim
@ -247,7 +247,16 @@ func toString*[bits: static[int]](num: Stint[bits] or StUint[bits]): string {.in
|
||||
#
|
||||
# TODO: Have a default static argument in the previous proc. Currently we get
|
||||
# "Error: type mismatch: got <int, type StInt[128]>, required type static[int]"
|
||||
toString(num, 10)
|
||||
when num.data is SomeInteger:
|
||||
$num.data
|
||||
else:
|
||||
toString(num, 10)
|
||||
|
||||
func `$`*(num: Stint or StUint): string {.inline.}=
|
||||
when num.data is SomeInteger:
|
||||
$num.data
|
||||
else:
|
||||
toString(num, 10)
|
||||
|
||||
func toHex*[bits: static[int]](num: Stint[bits] or StUint[bits]): string {.inline.}=
|
||||
## Convert to a hex string.
|
||||
|
@ -61,14 +61,17 @@ suite "Testing input and output procedures":
|
||||
block:
|
||||
let a = 1234567891234567890.stint(128)
|
||||
check: a.toString == "1234567891234567890"
|
||||
check: $a == "1234567891234567890"
|
||||
|
||||
block:
|
||||
let a = 1234567891234567890.stuint(128)
|
||||
check: a.toString == "1234567891234567890"
|
||||
check: $a == "1234567891234567890"
|
||||
|
||||
block:
|
||||
let a = (-1234567891234567890).stint(128)
|
||||
check: a.toString == "-1234567891234567890"
|
||||
check: $a == "-1234567891234567890"
|
||||
|
||||
test "Conversion to hex strings":
|
||||
block:
|
||||
@ -95,11 +98,13 @@ suite "Testing input and output procedures":
|
||||
let s = "1234567890123456789012345678901234567890123456789"
|
||||
let a = parse(s, StInt[512])
|
||||
check: a.toString == s
|
||||
check: $a == s
|
||||
|
||||
block:
|
||||
let s = "1234567890123456789012345678901234567890123456789"
|
||||
let a = parse(s, StUInt[512])
|
||||
check: a.toString == s
|
||||
check: $a == s
|
||||
|
||||
suite "Testing conversion functions: Hex, Bytes, Endianness using secp256k1 curve":
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user