Skip to content

Commit

Permalink
Change 'nonnegative' to 'non-negative' (JuliaLang#51380)
Browse files Browse the repository at this point in the history
This is for consistency. I picked the one which was more often used.
  • Loading branch information
fingolfin authored Sep 20, 2023
1 parent 53a00f3 commit 1282a65
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ Bool[]
first(itr, n::Integer) = collect(Iterators.take(itr, n))
# Faster method for vectors
function first(v::AbstractVector, n::Integer)
n < 0 && throw(ArgumentError("Number of elements must be nonnegative"))
n < 0 && throw(ArgumentError("Number of elements must be non-negative"))
v[range(begin, length=min(n, checked_length(v)))]
end

Expand Down Expand Up @@ -549,7 +549,7 @@ Float64[]
last(itr, n::Integer) = reverse!(collect(Iterators.take(Iterators.reverse(itr), n)))
# Faster method for arrays
function last(v::AbstractVector, n::Integer)
n < 0 && throw(ArgumentError("Number of elements must be nonnegative"))
n < 0 && throw(ArgumentError("Number of elements must be non-negative"))
v[range(stop=lastindex(v), length=min(n, checked_length(v)))]
end

Expand Down Expand Up @@ -993,7 +993,7 @@ end
# this method must be separate from the above since src might not have a length
function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer, n::Integer)
n < 0 && throw(ArgumentError(LazyString("tried to copy n=",n,
", elements, but n should be nonnegative")))
", elements, but n should be non-negative")))
n == 0 && return dest
dmax = dstart + n - 1
inds = LinearIndices(dest)
Expand Down Expand Up @@ -1124,7 +1124,7 @@ function copyto!(dest::AbstractArray, dstart::Integer,
n::Integer)
n == 0 && return dest
n < 0 && throw(ArgumentError(LazyString("tried to copy n=",
n," elements, but n should be nonnegative")))
n," elements, but n should be non-negative")))
destinds, srcinds = LinearIndices(dest), LinearIndices(src)
(checkbounds(Bool, destinds, dstart) && checkbounds(Bool, destinds, dstart+n-1)) || throw(BoundsError(dest, dstart:dstart+n-1))
(checkbounds(Bool, srcinds, sstart) && checkbounds(Bool, srcinds, sstart+n-1)) || throw(BoundsError(src, sstart:sstart+n-1))
Expand Down Expand Up @@ -2292,13 +2292,13 @@ _typed_hvncat_0d_only_one() =

function _typed_hvncat(::Type{T}, ::Val{N}) where {T, N}
N < 0 &&
throw(ArgumentError("concatenation dimension must be nonnegative"))
throw(ArgumentError("concatenation dimension must be non-negative"))
return Array{T, N}(undef, ntuple(x -> 0, Val(N)))
end

function _typed_hvncat(T::Type, ::Val{N}, xs::Number...) where N
N < 0 &&
throw(ArgumentError("concatenation dimension must be nonnegative"))
throw(ArgumentError("concatenation dimension must be non-negative"))
A = cat_similar(xs[1], T, (ntuple(x -> 1, Val(N - 1))..., length(xs)))
hvncat_fill!(A, false, xs)
return A
Expand All @@ -2310,7 +2310,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
length(as) > 0 ||
throw(ArgumentError("must have at least one element"))
N < 0 &&
throw(ArgumentError("concatenation dimension must be nonnegative"))
throw(ArgumentError("concatenation dimension must be non-negative"))
for a as
ndims(a) <= N || all(x -> size(a, x) == 1, (N + 1):ndims(a)) ||
return _typed_hvncat(T, (ntuple(x -> 1, Val(N - 1))..., length(as), 1), false, as...)
Expand Down Expand Up @@ -2343,7 +2343,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
length(as) > 0 ||
throw(ArgumentError("must have at least one element"))
N < 0 &&
throw(ArgumentError("concatenation dimension must be nonnegative"))
throw(ArgumentError("concatenation dimension must be non-negative"))
nd = N
Ndim = 0
for i eachindex(as)
Expand Down
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ end

function _copyto_impl!(dest::Array, doffs::Integer, src::Array, soffs::Integer, n::Integer)
n == 0 && return dest
n > 0 || _throw_argerror("Number of elements to copy must be nonnegative.")
n > 0 || _throw_argerror("Number of elements to copy must be non-negative.")
@boundscheck checkbounds(dest, doffs:doffs+n-1)
@boundscheck checkbounds(src, soffs:soffs+n-1)
unsafe_copyto!(dest, doffs, src, soffs, n)
Expand Down
2 changes: 1 addition & 1 deletion base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray,Array}, soffs::Integ
_copyto_int!(dest, Int(doffs), src, Int(soffs), Int(n))
function _copyto_int!(dest::BitArray, doffs::Int, src::Union{BitArray,Array}, soffs::Int, n::Int)
n == 0 && return dest
n < 0 && throw(ArgumentError("Number of elements to copy must be nonnegative."))
n < 0 && throw(ArgumentError("Number of elements to copy must be non-negative."))
soffs < 1 && throw(BoundsError(src, soffs))
doffs < 1 && throw(BoundsError(dest, doffs))
soffs+n-1 > length(src) && throw(BoundsError(src, length(src)+1))
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ end

## Computing the cost of a function body

# saturating sum (inputs are nonnegative), prevents overflow with typemax(Int) below
# saturating sum (inputs are non-negative), prevents overflow with typemax(Int) below
plus_saturate(x::Int, y::Int) = max(x, y, x+y)

# known return type
Expand Down
2 changes: 1 addition & 1 deletion base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ julia> factorial(big(21))
* [Factorial](https://en.wikipedia.org/wiki/Factorial) on Wikipedia.
"""
function factorial(n::Integer)
n < 0 && throw(DomainError(n, "`n` must be nonnegative."))
n < 0 && throw(DomainError(n, "`n` must be non-negative."))
f::typeof(n*n) = 1
for i::typeof(n*n) = 2:n
f *= i
Expand Down
4 changes: 2 additions & 2 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ struct Take{I}
xs::I
n::Int
function Take(xs::I, n::Integer) where {I}
n < 0 && throw(ArgumentError("Take length must be nonnegative"))
n < 0 && throw(ArgumentError("Take length must be non-negative"))
return new{I}(xs, n)
end
end
Expand Down Expand Up @@ -773,7 +773,7 @@ struct Drop{I}
xs::I
n::Int
function Drop(xs::I, n::Integer) where {I}
n < 0 && throw(ArgumentError("Drop length must be nonnegative"))
n < 0 && throw(ArgumentError("Drop length must be non-negative"))
return new{I}(xs, n)
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/multinverses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract type MultiplicativeInverse{T} <: Number end
# Division of Int32 by 3:
# floor((2^32+2)/3 * n/2^32) = floor(n/3 + 2n/(3*2^32))
# The correction term, 2n/(3*2^32), is strictly less than 1/3 for any
# nonnegative n::Int32, so this divides any nonnegative Int32 by 3.
# non-negative n::Int32, so this divides any non-negative Int32 by 3.
# (When n < 0, we add 1, and one can show that this computes
# ceil(n/d) = -floor(abs(n)/d).)
#
Expand Down
2 changes: 1 addition & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function steprange_last(start, step, stop)::typeof(stop)
# (to simplify handling both signed and unsigned T and checking for signed overflow):
absdiff, absstep = stop > start ? (stop - start, step) : (start - stop, -step)

# Compute remainder as a nonnegative number:
# Compute remainder as a non-negative number:
if absdiff isa Signed && absdiff < zero(absdiff)
# unlikely, but handle the signed overflow case with unsigned rem
overflow_case(absdiff, absstep) = (@noinline; convert(typeof(absdiff), unsigned(absdiff) % absstep))
Expand Down
2 changes: 1 addition & 1 deletion base/rawbigints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ split_bit_index(x::RawBigInt, i::Int) = divrem(i, word_length(x), RoundToZero)
the less significant words.
"""
function get_elem(x::RawBigInt{T}, i::Int, ::Val{:words}, ::Val{:ascending}) where {T}
# `i` must be nonnegative and less than `x.word_count`
# `i` must be non-negative and less than `x.word_count`
d = x.d
(GC.@preserve d unsafe_load(Ptr{T}(pointer(d)), i + 1))::T
end
Expand Down
6 changes: 3 additions & 3 deletions doc/src/manual/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,19 +637,19 @@ julia> struct MyCustomException <: Exception end
### The [`throw`](@ref) function

Exceptions can be created explicitly with [`throw`](@ref). For example, a function defined only
for nonnegative numbers could be written to [`throw`](@ref) a [`DomainError`](@ref) if the argument
for non-negative numbers could be written to [`throw`](@ref) a [`DomainError`](@ref) if the argument
is negative:

```jldoctest; filter = r"Stacktrace:(\n \[[0-9]+\].*)*"
julia> f(x) = x>=0 ? exp(-x) : throw(DomainError(x, "argument must be nonnegative"))
julia> f(x) = x>=0 ? exp(-x) : throw(DomainError(x, "argument must be non-negative"))
f (generic function with 1 method)
julia> f(1)
0.36787944117144233
julia> f(-1)
ERROR: DomainError with -1:
argument must be nonnegative
argument must be non-negative
Stacktrace:
[1] f(::Int64) at ./none:1
```
Expand Down
2 changes: 1 addition & 1 deletion test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ end
# line meta
if d < 0
# line meta
error(\"dimension size must be nonnegative (got \$d)\")
error(\"dimension size must be non-negative (got \$d)\")
end
# line meta
n *= d
Expand Down

0 comments on commit 1282a65

Please sign in to comment.