bit.print_dec_uintΒΆ
prints x[:n] as an unsigned decimal number (without leading zeros).
The number 28/93 is the ratio of the number of decimal digits and the number of binary digits.
Itβs bigger than log(2)/log(10) by 0.015%, which is just enough.
SignatureΒΆ
def print_dec_uint n, x @ start_printing, xor, end_xor, dst, src, print_buffer, print_buffer_flag, div10, zero_flag, ret_reg, end { ... }
Defined in bit/output.fj β lines 150β189 (view on GitHub).
ComplexityΒΆ
Time:
n^2(2@+4) // actually: nd(7@+12) (for d number of decimal digits)Space:
n(14@+16)
See the complexity glossary for what @, w, dw, dbit, n mean.
SourceΒΆ
Click to view the macro body
def print_dec_uint n, x @ start_printing, xor, end_xor, dst, src, print_buffer, print_buffer_flag, \
div10, zero_flag, ret_reg, end {
.mov n, src, x
.zero zero_flag
// the next three takes ~ (28/93n)*(n(7@+12)) = n^2(2.11@+3.61) ~= n^2(2@+4) time
// the next three takes ~ (28/93n)*(@-1 + 11@-3 + 5@+12) = n(5.12@+2.41) ~= n(5@+2.5) space
.zero n*28/93+1, print_buffer_flag // all chars are off
// fill the print buffer with the decimal digits of src
rep(n*28/93+1, i) .print_dec_uint.div10_step div10, xor, ret_reg, src, \
print_buffer+i*4*dw, print_buffer_flag+i*dw, zero_flag, start_printing
start_printing:
rep(n*28/93+1, i) .print_dec_uint.print_char \
print_buffer+(n*28/93-i)*4*dw, \
print_buffer_flag+(n*28/93-i)*dw
;end
div10:
.div10 n, dst, src
stl.fret ret_reg
xor:
.xor n, src, dst // can double_exact_xor and zero dst too - so to save the "zero n dst" inside the next div10
.if1 n, dst, end_xor
.not zero_flag
end_xor:
stl.fret ret_reg
// takes n(2+28/93*5) = 3.5n space
// dst,src are padded to >=4 bits: the digit-extraction (double_exact_xor over 4 bits)
// and div10 both read 4 bits of src, so for n<4 they must not spill into print_buffer.
dst: .vec (n < 4 ? 4 : n)
src: .vec (n < 4 ? 4 : n)
print_buffer: .vec (n*28/93+1)*4
print_buffer_flag: .vec n*28/93+1
zero_flag: .bit
ret_reg: 0;0
end:
}
Depends onΒΆ
Used byΒΆ
Example usesΒΆ
bit.print_dec_intinbit/output.fjhex.print_dec_uintinhex/output.fj
β Previous: bit.print_hex_int
Next: bit.print_dec_uint.div10_step β