Skip to content

Commit

Permalink
Missing "Examples" headings and a few more actual examples (#27340)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt authored and fredrikekre committed Jun 1, 2018
1 parent 8b3849e commit d555a9a
Show file tree
Hide file tree
Showing 27 changed files with 176 additions and 15 deletions.
1 change: 1 addition & 0 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Return the type that represents the real part of a value of type `T`.
e.g: for `T == Complex{R}`, returns `R`.
Equivalent to `typeof(real(zero(T)))`.
# Examples
```jldoctest
julia> real(Complex{Int})
Int64
Expand Down
6 changes: 5 additions & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Keys are compared with [`isequal`](@ref) and hashed with [`hash`](@ref).
Given a single iterable argument, constructs a [`Dict`](@ref) whose key-value pairs
are taken from 2-tuples `(key,value)` generated by the argument.
# Examples
```jldoctest
julia> Dict([("A", 1), ("B", 2)])
Dict{String,Int64} with 2 entries:
Expand Down Expand Up @@ -256,6 +257,7 @@ end
Remove all elements from a `collection`.
# Examples
```jldoctest
julia> A = Dict("a" => 1, "b" => 2)
Dict{String,Int64} with 2 entries:
Expand Down Expand Up @@ -534,8 +536,9 @@ end
"""
haskey(collection, key) -> Bool
Determine whether a collection has a mapping for a given key.
Determine whether a collection has a mapping for a given `key`.
# Examples
```jldoctest
julia> D = Dict('a'=>2, 'b'=>3)
Dict{Char,Int64} with 2 entries:
Expand All @@ -557,6 +560,7 @@ in(key, v::KeySet{<:Any, <:Dict}) = (ht_keyindex(v.dict, key) >= 0)
Return the key matching argument `key` if one exists in `collection`, otherwise return `default`.
# Examples
```jldoctest
julia> D = Dict('a'=>2, 'b'=>3)
Dict{Char,Int64} with 2 entries:
Expand Down
1 change: 1 addition & 0 deletions base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ If a second argument `val` is provided, it will be passed to the task (via the r
[`yieldto`](@ref)) when it runs again. If `error` is `true`, the value is raised as an exception in
the woken task.
# Examples
```jldoctest
julia> a5() = sum(i for i in 1:1000);
Expand Down
4 changes: 4 additions & 0 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ float(x) = AbstractFloat(x)
Return an appropriate type to represent a value of type `T` as a floating point value.
Equivalent to `typeof(float(zero(T)))`.
# Examples
```jldoctest
julia> float(Complex{Int})
Complex{Float64}
Expand Down Expand Up @@ -531,6 +532,7 @@ isnan(x::Real) = false
Test whether a number is finite.
# Examples
```jldoctest
julia> isfinite(5)
true
Expand Down Expand Up @@ -765,6 +767,7 @@ default). This is defined as the gap between 1 and the next largest value repres
`typeof(one(T))`, and is equivalent to `eps(one(T))`. (Since `eps(T)` is a
bound on the *relative error* of `T`, it is a "dimensionless" quantity like [`one`](@ref).)
# Examples
```jldoctest
julia> eps()
2.220446049250313e-16
Expand Down Expand Up @@ -802,6 +805,7 @@ is the nearest floating point number to ``y``, then
|y-x| \\leq \\operatorname{eps}(x)/2.
```
# Examples
```jldoctest
julia> eps(1.0)
2.220446049250313e-16
Expand Down
1 change: 1 addition & 0 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ results are promoted to a [`BigInt`](@ref).
Instances can be constructed from strings via [`parse`](@ref), or using the `big`
string literal.
# Examples
```jldoctest
julia> parse(BigInt, "42")
42
Expand Down
1 change: 1 addition & 0 deletions base/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ end
Check two array shapes for compatibility, allowing trailing singleton dimensions, and return
whichever shape has more dimensions.
# Examples
```jldoctest
julia> a = fill(1, (3,4,1,1,1));
Expand Down
19 changes: 19 additions & 0 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ inv(x::Integer) = float(one(x)) / float(x)
Return `true` if `x` is odd (that is, not divisible by 2), and `false` otherwise.
# Examples
```jldoctest
julia> isodd(9)
true
Expand All @@ -78,6 +79,7 @@ isodd(n::Integer) = rem(n, 2) != 0
Return `true` is `x` is even (that is, divisible by 2), and `false` otherwise.
# Examples
```jldoctest
julia> iseven(9)
false
Expand Down Expand Up @@ -116,6 +118,7 @@ when `abs` is applied to the minimum representable value of a signed
integer. That is, when `x == typemin(typeof(x))`, `abs(x) == x < 0`,
not `-x` as might be expected.
# Examples
```jldoctest
julia> abs(-3)
3
Expand Down Expand Up @@ -346,6 +349,7 @@ bswap(x::Union{Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128}) =
Number of ones in the binary representation of `x`.
# Examples
```jldoctest
julia> count_ones(7)
3
Expand All @@ -358,6 +362,7 @@ count_ones(x::BitInteger) = Int(ctpop_int(x))
Number of zeros leading the binary representation of `x`.
# Examples
```jldoctest
julia> leading_zeros(Int32(1))
31
Expand All @@ -370,6 +375,7 @@ leading_zeros(x::BitInteger) = Int(ctlz_int(x))
Number of zeros trailing the binary representation of `x`.
# Examples
```jldoctest
julia> trailing_zeros(2)
1
Expand All @@ -382,6 +388,7 @@ trailing_zeros(x::BitInteger) = Int(cttz_int(x))
Number of zeros in the binary representation of `x`.
# Examples
```jldoctest
julia> count_zeros(Int32(2 ^ 16 - 1))
16
Expand All @@ -394,6 +401,7 @@ count_zeros(x::Integer) = count_ones(~x)
Number of ones leading the binary representation of `x`.
# Examples
```jldoctest
julia> leading_ones(UInt32(2 ^ 32 - 2))
31
Expand All @@ -406,6 +414,7 @@ leading_ones(x::Integer) = leading_zeros(~x)
Number of ones trailing the binary representation of `x`.
# Examples
```jldoctest
julia> trailing_ones(3)
2
Expand Down Expand Up @@ -476,6 +485,7 @@ if nameof(@__MODULE__) === :Base
If `T` can represent any integer (e.g. `T == BigInt`), then this operation corresponds to
a conversion to `T`.
# Examples
```jldoctest
julia> 129 % Int8
-127
Expand Down Expand Up @@ -616,6 +626,15 @@ function typemin end
typemax(T)
The highest value representable by the given (real) numeric `DataType`.
# Examples
```jldoctest
julia> typemax(Int8)
127
julia> typemax(UInt32)
0xffffffff
```
"""
function typemax end

Expand Down
4 changes: 2 additions & 2 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ rest(itr) = itr
Returns the first element and an iterator over the remaining elements.
# Example
# Examples
```jldoctest
julia> (a, rest) = Iterators.peel("abc");
Expand Down Expand Up @@ -992,7 +992,7 @@ iteration can be resumed from the same spot by continuing to iterate over the
same iterator object (in contrast, an immutable iterator would restart from the
beginning).
# Example:
# Examples
```jldoctest
julia> a = Iterators.Stateful("abcdef");
Expand Down
Loading

0 comments on commit d555a9a

Please sign in to comment.