Skip to content

Commit

Permalink
Add real constructors from Complex and Acb, mainly for ambiguities re…
Browse files Browse the repository at this point in the history
…asons
  • Loading branch information
Joel-Dahne committed Apr 22, 2024
1 parent 91b49d6 commit b944755
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Mag(x) = set!(Mag(), x)
Mag(x::Union{MagRef,ArfRef}) = Mag(cstruct(x))
Mag(x, y) = set!(Mag(), x, y)
# disambiguation
Mag(z::Complex) = isreal(z) ? Mag(real(z)) : throw(InexactError(:Mag, Mag, z))
Mag(x::AbstractChar) = set!(Mag(), x)
Mag(x::Base.TwicePrecision) = set!(Mag(), x)

Expand All @@ -15,14 +16,17 @@ Arf(x; prec::Integer = _precision(x)) = set!(Arf(; prec), x)
# disambiguation
Arf(x::Arf; prec::Integer = precision(x)) = set!(Arf(; prec), x)
Arf(x::Rational; prec::Integer = _precision(x)) = set!(Arf(; prec), x)
Arf(z::Complex) = isreal(z) ? Arf(real(z)) : throw(InexactError(:Arf, Arf, z))
Arf(x::AbstractChar; prec::Integer = _precision(x)) = set!(Arf(; prec), x)
Arf(x::Base.TwicePrecision; prec::Integer = _precision(x)) = set!(Arf(; prec), x)

#Arb
Arb(x; prec::Integer = _precision(x)) = set!(Arb(; prec), x)
Arb(z::Acb) = isreal(z) ? Arb(Arblib.realref(z)) : throw(InexactError(:Arb, Arb, z))
# disambiguation
Arb(x::Arb; prec::Integer = precision(x)) = set!(Arb(; prec), x)
Arb(x::Rational; prec::Integer = _precision(x)) = set!(Arb(; prec), x)
Arb(z::Complex) = isreal(z) ? Arb(real(z)) : throw(InexactError(:Arb, Arb, z))
Arb(x::AbstractChar; prec::Integer = _precision(x)) = set!(Arb(; prec), x)
Arb(x::Base.TwicePrecision; prec::Integer = _precision(x)) = set!(Arb(; prec), x)

Expand Down
10 changes: 10 additions & 0 deletions test/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@test Mag(3, 4) == Mag(3 * 2^4)

# Check for ambiguities
@test Mag(1 + 0im) == Mag(1)
@test_throws InexactError Mag(1 + im)
@test Mag('a') == Mag(Int('a'))
@test Float64(Mag(Base.TwicePrecision(1.0, 0.5))) 1.5
end
Expand All @@ -29,6 +31,8 @@
@test precision(one(Arf(prec = 80))) == 80

# Check for ambiguities
@test Arf(1 + 0im) == 1
@test_throws InexactError Arf(1 + im)
@test Arf('a') == Int('a')
@test Arf(Base.TwicePrecision(1.0, 0.5)) == 1.5
end
Expand Down Expand Up @@ -66,6 +70,10 @@
@test precision(Arb(MathConstants.catalan, prec = 80)) == 80
@test precision(Arb(MathConstants.φ, prec = 80)) == 80

@test Arb(Acb(1)) == 1
@test precision(Arb(Acb(1, prec = 80))) == 80
@test_throws InexactError Arb(Acb(1, 1))

# setball
@test isone(Arblib.setball(Arb, Arf(1), Mag(0)))
@test isone(Arblib.setball(Arb, 1, 0))
Expand All @@ -81,6 +89,8 @@
@test precision(Arblib.setball(Arb, Arf(prec = 90), 0, prec = 80)) == 80

# Check for ambiguities
@test Arb(1 + 0im) == 1
@test_throws InexactError Arb(1 + im)
@test Arb('a') == Int('a')
@test Arb(Base.TwicePrecision(1.0, 0.5)) == 1.5
@test Arblib.overlaps(
Expand Down

0 comments on commit b944755

Please sign in to comment.