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:
parent
10ab758aa7
commit
795fe5844c
@ -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 {
|
||||
|
10
vlib/v/tests/inout/strconv_v_printf.out
Normal file
10
vlib/v/tests/inout/strconv_v_printf.out
Normal 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
|
40
vlib/v/tests/inout/strconv_v_printf.vv
Normal file
40
vlib/v/tests/inout/strconv_v_printf.vv
Normal 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')
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user