followup #18318: simplify dollarImpl and add a test (#18330)

This commit is contained in:
Timothee Cour
2021-06-22 21:42:39 -07:00
committed by GitHub
parent 9a81e91fa5
commit 5badeea170
2 changed files with 23 additions and 7 deletions

View File

@@ -0,0 +1,23 @@
import std/private/digitsutils
template main =
block: # digits10
doAssert digits10(0'u64) == 1
# checks correctness on all powers of 10 + [0,-1,1]
var x = 1'u64
var num = 1
while true:
# echo (x, num)
doAssert digits10(x) == num
doAssert digits10(x+1) == num
if x > 1:
doAssert digits10(x-1) == num - 1
num += 1
let xOld = x
x *= 10
if x < xOld:
# wrap-around
break
static: main()
main()