1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

strconv: fix strconv.v_printf() (#13716)

This commit is contained in:
yuyi 2022-03-11 23:00:57 +08:00 committed by GitHub
parent 10ab758aa7
commit 795fe5844c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View File

@ -23,7 +23,7 @@ enum Char_parse_state {
}
pub fn v_printf(str string, pt ...voidptr) {
print(v_sprintf(str, pt))
print(v_sprintf(str, ...pt))
}
pub fn v_sprintf(str string, pt ...voidptr) string {

View File

@ -0,0 +1,10 @@
. 2 3 . 5 . 7 . . . 11 . 13 . . . 17 . 19 .iter: 20
. . 23 . . . . . 29 . 31 . . . . . 37 . . .iter: 40
41 . 43 . . . 47 . . . . . 53 . . . . . 59 .iter: 60
61 . . . . . 67 . . . 71 . 73 . . . . . 79 .iter: 80
. . 83 . . . . . 89 . . . . . . . 97 . . .iter: 100
101 .103 . . .107 .109 . . .113 . . . . . . .iter: 120
. . . . . .127 . . .131 . . . . .137 .139 .iter: 140
. . . . . . . .149 .151 . . . . .157 . . .iter: 160
. .163 . . .167 . . . . .173 . . . . .179 .iter: 180
181 . . . . . . . . .191 .193 . . .197 .199 .iter: 200

View File

@ -0,0 +1,40 @@
import strconv
const limit = 201
fn main() {
// sieve
mut c := [limit]bool{}
c[1] = true
mut p := 2
for {
p2 := p * p
if p2 >= limit {
break
}
for i := p2; i < limit; i += p {
c[i] = true
}
for {
p++
if !c[p] {
break
}
}
}
// sieve complete. now print a representation.
for n in 1 .. limit {
if c[n] {
print(' .')
} else {
strconv.v_printf('%3d', n)
}
if n % 20 == 0 {
println('iter: $n')
}
}
}