diff --git a/base/printf.jl b/base/printf.jl index 1cf58d34102184..f1d89bddf8bc4e 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -541,29 +541,6 @@ function format(f::Format, args...) # => String return unsafe_string(pointer(buf), pos-1) end -""" - @printf([io::IOStream], "%Fmt", args...) - -Print `args` using C `printf` style format specification string, with some caveats: -`Inf` and `NaN` are printed consistently as `Inf` and `NaN` for flags `%a`, `%A`, -`%e`, `%E`, `%f`, `%F`, `%g`, and `%G`. Furthermore, if a floating point number is -equally close to the numeric values of two possible output strings, the output -string further away from zero is chosen. - -Optionally, an [`IOStream`](@ref) -may be passed as the first argument to redirect output. - -See also: [`@sprintf`](@ref) - -# Examples -```jldoctest -julia> @printf("%f %F %f %F\\n", Inf, Inf, NaN, NaN) -Inf Inf NaN NaN\n - -julia> @printf "%.0f %.1f %f\\n" 0.5 0.025 -0.0078125 -1 0.0 -0.007813 -``` -""" macro printf(io_or_fmt, args...) if io_or_fmt isa String io = stdout @@ -577,19 +554,6 @@ macro printf(io_or_fmt, args...) end end -""" - @sprintf("%Fmt", args...) - -Return `@printf` formatted output as string. - -# Examples -```jldoctest -julia> s = @sprintf "this is a %s %15.1f" "test" 34.567; - -julia> println(s) -this is a test 34.6 -``` -""" macro sprintf(fmt, args...) f = Format(fmt) return esc(:(Base.Printf.format($f, $(args...)))) diff --git a/contrib/generate_precompile.jl b/contrib/generate_precompile.jl index aa00de46981d8d..81d262ca605763 100644 --- a/contrib/generate_precompile.jl +++ b/contrib/generate_precompile.jl @@ -137,7 +137,9 @@ function generate_precompile_statements() # Extract the precompile statements from stderr statements = Set{String}() for statement in eachline(precompile_file_h) - occursin("Main.", statement) && continue + (occursin("Main.", statement) || + occursin("Printf.", statement) || + occursin("Base.io_has_tvar_name", statement)) && continue # check for `#x##s66` style variable names not in quotes occursin(r"#\w", statement) && count(r"(?:#+\w+)+", statement) != diff --git a/stdlib/Printf/src/Printf.jl b/stdlib/Printf/src/Printf.jl index e2d57ccf853761..be29fee0b7ae3d 100644 --- a/stdlib/Printf/src/Printf.jl +++ b/stdlib/Printf/src/Printf.jl @@ -7,4 +7,44 @@ module Printf export @printf, @sprintf using Base.Printf +""" + @printf([io::IOStream], "%Fmt", args...) + +Print `args` using C `printf` style format specification string, with some caveats: +`Inf` and `NaN` are printed consistently as `Inf` and `NaN` for flags `%a`, `%A`, +`%e`, `%E`, `%f`, `%F`, `%g`, and `%G`. Furthermore, if a floating point number is +equally close to the numeric values of two possible output strings, the output +string further away from zero is chosen. + +Optionally, an [`IOStream`](@ref) +may be passed as the first argument to redirect output. + +See also: [`@sprintf`](@ref) + +# Examples +```jldoctest +julia> @printf("%f %F %f %F\\n", Inf, Inf, NaN, NaN) +Inf Inf NaN NaN\n + +julia> @printf "%.0f %.1f %f\\n" 0.5 0.025 -0.0078125 +1 0.0 -0.007813 +``` +""" +:(@printf) + +""" + @sprintf("%Fmt", args...) + +Return `@printf` formatted output as string. + +# Examples +```jldoctest +julia> s = @sprintf "this is a %s %15.1f" "test" 34.567; + +julia> println(s) +this is a test 34.6 +``` +""" +:(@sprintf) + end # module