Skip to content

Commit

Permalink
Specialize isapprox for ULogarithmic input arguments (#16)
Browse files Browse the repository at this point in the history
* specialize isapprox for ULogarithmic

* test isapprox

* better test
  • Loading branch information
stecrotti authored Aug 19, 2023
1 parent 272529a commit 84151f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/LogarithmicNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ function Base.isequal(x::Logarithmic, y::Logarithmic)
isequal(x.abs, y.abs) && isequal(x.signbit, y.signbit)
end

function Base.isapprox(x::ULogarithmic, y::ULogarithmic; kwargs...)
isapprox(Logarithmic(x), Logarithmic(y); kwargs...)
end

function Base.:(<)(x::ULogarithmic, y::ULogarithmic)
x.log < y.log
end
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ atypes2 = (ULogarithmic, ULogFloat32, Logarithmic, LogFloat32)
end
end

@testset "isapprox" begin
for A in atypes, x1 in vals
A <: ULogarithmic && x1 < 0 && continue
x2 = x1 + 1e-12
y1 = A(x1)
y2 = A(x2)
@test @inferred(isapprox(y1, y2; atol=1e-11)) == isapprox(x1,x2; atol=1e-11)
end
end

@testset "<" begin
for A in atypes, x1 in vals, x2 in vals
A <: ULogarithmic && (x1 < 0 || x2 < 0) && continue
Expand Down

0 comments on commit 84151f5

Please sign in to comment.