diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-09-14 20:43:50 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-09-14 20:43:50 +0200 |
commit | be43467037c68b2d932a642e81b7fb4868dae9e5 (patch) | |
tree | cb19711283560489477ecbfaf87002ef9e952d68 /lib | |
parent | fa177076842d5a5e7900469d6b5ec0e2e432d17c (diff) | |
parent | 6ac2ba122366bdd320b1ab6ce7a6ca3cbb362800 (diff) | |
download | Nim-be43467037c68b2d932a642e81b7fb4868dae9e5.tar.gz |
Merge pull request #3322 from yglukhov/fix-uint64-str-vm
Uint64 to string in pure nim. array[char] to string fixed in vm.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/repr.nim | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/system/repr.nim b/lib/system/repr.nim index b4188527f..1f81a0813 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -21,9 +21,22 @@ proc reprPointer(x: pointer): string {.compilerproc.} = return $buf proc `$`(x: uint64): string = - var buf: array [0..59, char] - discard c_sprintf(buf, "%llu", x) - return $buf + if x == 0: + result = "0" + else: + var buf: array [60, char] + var i = 0 + var n = x + while n != 0: + let nn = n div 10'u64 + buf[i] = char(n - 10'u64 * nn + ord('0')) + inc i + n = nn + + let half = i div 2 + # Reverse + for t in 0 .. < half: swap(buf[t], buf[i-t-1]) + result = $buf proc reprStrAux(result: var string, s: string) = if cast[pointer](s) == nil: @@ -294,4 +307,3 @@ when not defined(useNimRtl): reprAux(result, addr(p), typ, cl) add result, "\n" deinitReprClosure(cl) - |