diff options
author | Araq <rumpf_a@web.de> | 2015-09-16 11:36:49 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-09-16 11:36:49 +0200 |
commit | c9a2fa54c7055c16892e9664dd64d8fc68918c07 (patch) | |
tree | b67fca3d93765f677de696f4f8b1ed50b031b164 /lib/system | |
parent | 1251fc76c32bdd50a3b9540e0cd80b0c435051ce (diff) | |
parent | d24eaf084b4be17e43f262d4127a91993ae6f7cd (diff) | |
download | Nim-c9a2fa54c7055c16892e9664dd64d8fc68918c07.tar.gz |
Merge branch 'devel' into fix_bracket_expr
Diffstat (limited to 'lib/system')
-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) - |