Skip to content

Commit 83017b4

Browse files
Allow two-argument versions of nextfloat and prevfloat (#692)
1 parent bc5dfb2 commit 83017b4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/quantities.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,10 @@ Returns the sign bit of the underlying numeric value of `x`.
436436
"""
437437
signbit(x::AbstractQuantity) = signbit(x.val)
438438

439-
prevfloat(x::AbstractQuantity{T}) where {T <: AbstractFloat} = Quantity(prevfloat(x.val), unit(x))
440-
nextfloat(x::AbstractQuantity{T}) where {T <: AbstractFloat} = Quantity(nextfloat(x.val), unit(x))
439+
prevfloat(x::AbstractQuantity{T}, d::Integer) where {T <: AbstractFloat} = Quantity(prevfloat(x.val, d), unit(x))
440+
prevfloat(x::AbstractQuantity{T}) where {T <: AbstractFloat} = prevfloat(x, 1)
441+
nextfloat(x::AbstractQuantity{T}, d::Integer) where {T <: AbstractFloat} = Quantity(nextfloat(x.val, d), unit(x))
442+
nextfloat(x::AbstractQuantity{T}) where {T <: AbstractFloat} = nextfloat(x, 1)
441443

442444
function frexp(x::AbstractQuantity{T}) where {T <: AbstractFloat}
443445
a,b = frexp(x.val)

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,11 @@ Base.:(<=)(x::Issue399, y::Issue399) = x.num <= y.num
842842
@test !isapprox(1.0u"m",5)
843843
@test frexp(1.5m) == (0.75m, 1.0)
844844
@test unit(nextfloat(0.0m)) == m
845+
@test unit(nextfloat(0.0m, 4)) == m
846+
@test ustrip(nextfloat(0.0m, 4)) == nextfloat(0.0, 4)
845847
@test unit(prevfloat(0.0m)) == m
848+
@test unit(prevfloat(0.0m, 4)) == m
849+
@test ustrip(prevfloat(0.0m, 4)) == prevfloat(0.0, 4)
846850

847851
# NaN behavior
848852
@test NaN*m != NaN*m

0 commit comments

Comments
 (0)