Skip to content

Commit

Permalink
Fixed broken isreal
Browse files Browse the repository at this point in the history
Must be a change in Julia since this was last tested?

Add tests and change incorrect & to &&

Fix isinteger and UpToPhase

fixes #6
fixes #7
  • Loading branch information
jlapeyre committed Aug 29, 2022
1 parent d53bb3d commit 02bc87b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/base_applications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ isinteger(x::AbstractFloat, approx_test::AbstractApprox=Equal()) = isapprox(appr

# complex.jl
isinteger(z::Complex, approx_test::AbstractApprox=Equal()) =
isreal(z, approx_test) & isinteger(real(z), approx_test)
isreal(z, approx_test) && isinteger(real(z), approx_test)

# TODO: Need to think about difference between real(z) and abs(z) regarding tolerance in all
# methods for complex numbers (not just isingeger)
isinteger(z::Complex, approx_test::UpToPhase) = isinteger(abs(z), approx_test)

isinteger(x::Rational, approx_test::AbstractApprox) = isinteger(float(x), approx_test)

Expand Down
14 changes: 12 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ import LinearAlgebra
@test ! iszero(m, Equal()) # exact
end

@testset "isreal, isinteger" begin
@testset "isreal" begin
@test isreal(1)
@test isreal(1.0)
@test isreal(1.0, Approx())
@test ! isreal(1.0 + 1e-10im)
@test ! isreal(1.0 + 1e-10im, Approx())
@test ! isreal(1.0 + 1e-7im, Approx())
@test isreal(1.0 + 1e-10im, Approx(atol=1e-9))
end

@testset "isinteger" begin
@test isinteger(1)
@test isinteger(1, Approx())
@test isinteger(1 + 1e-8, Approx())
@test ! isinteger(1 + 1e-5, Approx())
@test isinteger(1000 + 1e-5, Approx())
@test isinteger(1 + im * 1e-8, Approx())
@test ! isinteger(1 + im * 1e-5, Approx())
@test isinteger(exp(im*2), UpToPhase())
@test ! isinteger(1.1 * exp(im*2), UpToPhase())
end

@testset "isdiag" begin
Expand Down

0 comments on commit 02bc87b

Please sign in to comment.