This commit is contained in:
Andreas Rumpf
2019-06-02 14:24:38 +02:00
committed by GitHub
parent c02320e230
commit 5eb47f8ed9
2 changed files with 17 additions and 10 deletions

View File

@@ -892,14 +892,14 @@ proc toBin*(x: BiggestInt, len: Positive): string {.noSideEffect,
doAssert b.toBin(8) == "00000001"
doAssert b.toBin(9) == "100000001"
var
mask: BiggestInt = 1
shift: BiggestInt = 0
mask = BiggestUInt 1
shift = BiggestUInt 0
assert(len > 0)
result = newString(len)
for j in countdown(len-1, 0):
result[j] = chr(int((x and mask) shr shift) + ord('0'))
shift = shift + 1
mask = mask shl 1
result[j] = chr(int((BiggestUInt(x) and mask) shr shift) + ord('0'))
inc shift
mask = mask shl BiggestUInt(1)
proc toOct*(x: BiggestInt, len: Positive): string {.noSideEffect,
rtl, extern: "nsuToOct".} =
@@ -917,14 +917,14 @@ proc toOct*(x: BiggestInt, len: Positive): string {.noSideEffect,
doAssert b.toOct(3) == "001"
doAssert b.toOct(5) == "01001"
var
mask: BiggestInt = 7
shift: BiggestInt = 0
mask = BiggestUInt 7
shift = BiggestUInt 0
assert(len > 0)
result = newString(len)
for j in countdown(len-1, 0):
result[j] = chr(int((x and mask) shr shift) + ord('0'))
shift = shift + 3
mask = mask shl 3
result[j] = chr(int((BiggestUInt(x) and mask) shr shift) + ord('0'))
inc shift, 3
mask = mask shl BiggestUInt(3)
proc toHex*(x: BiggestInt, len: Positive): string {.noSideEffect,
rtl, extern: "nsuToHex".} =

View File

@@ -308,6 +308,13 @@ assert(' '.repeat(0) == "")
assert(" ".repeat(0) == "")
assert(spaces(0) == "")
# bug #11369
var num: int64 = -1
assert num.toBin(64) == "1111111111111111111111111111111111111111111111111111111111111111"
assert num.toOct(24) == "001777777777777777777777"
# bug #8911
when true:
static: