Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,10 @@ applications of [`nextfloat`](@ref) if `n < 0`.
"""
prevfloat(x::AbstractFloat, d::Integer) = _nextfloat(x, ispositive(d), uabs(d))

# this method improves backwards compatibility for types only specializing
# nextfloat and relying on an implicit prevfloat
prevfloat(x::AbstractFloat, d::T) where {T<:Signed} = nextfloat(x, -d)

"""
prevfloat(x::AbstractFloat)

Expand Down
6 changes: 6 additions & 0 deletions test/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,9 @@ end
end
end
end

@testset "nextfloat can be defined without prevfloat for signed step sizes" begin
struct MyFloat59661<:AbstractFloat x end
Base.nextfloat(x::MyFloat59661, d::Integer) = nextfloat(x.x, d)
@test prevfloat(MyFloat59661(1.0), 1) == prevfloat(1.0, 1)
end