Skip to content

Commit 5241779

Browse files
authored
Use Base.real instead of defining real in the package (#400)
* Use Base.real * real for unsetnumber
1 parent e3f9926 commit 5241779

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

src/ApproxFunBase.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !,
2929
getproperty, findfirst, unsafe_getindex, fld, div,
3030
eachindex, firstindex, lastindex, isreal,
3131
OneTo, Array, Vector, Matrix, view, ones, @propagate_inbounds,
32-
print_array, split, iszero, permutedims, rad2deg, deg2rad, checkbounds
32+
print_array, split, iszero, permutedims, rad2deg, deg2rad, checkbounds,
33+
real, float
3334

3435
import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle,
3536
broadcastable, DefaultArrayStyle, broadcasted

src/LinearAlgebra/helper.jl

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,13 @@ isapproxinteger(::Integer) = true
5555
isapproxinteger(x) = isinteger(x) || isapprox(x,round(Int,x)) || isapprox(x+1,round(Int,x+1))
5656

5757

58-
# This creates ApproxFunBase.real, ApproxFunBase.eps and ApproxFunBase.dou
59-
# which we override for default julia types
60-
real(x...) = Base.real(x...)
58+
real(x::UnsetNumber) = x
6159
real(::Type{UnsetNumber}) = UnsetNumber
62-
real(::Type{Array{T,n}}) where {T<:Real,n} = Array{T,n}
63-
real(::Type{Array{T,n}}) where {T<:Complex,n} = Array{real(T),n}
64-
real(::Type{SVector{N,T}}) where {N,T<:Real} = SVector{N,T}
65-
real(::Type{SVector{N,T}}) where {N,T<:Complex} = SVector{N,real(T)}
66-
67-
float(x) = Base.float(x)
68-
Base.float(::UnsetNumber) = UnsetNumber()
69-
Base.float(::Type{UnsetNumber}) = UnsetNumber
70-
float(::Type{Array{T,N}}) where {T,N} = Array{float(T),N}
71-
float(::Type{SVector{N,T}}) where {T,N} = SVector{N,float(T)}
72-
7360

61+
float(x::UnsetNumber) = x
62+
float(::Type{UnsetNumber}) = UnsetNumber
7463

64+
# This creates ApproxFunBase.eps, which we override for default julia types
7565
eps(x...) = Base.eps(x...)
7666
eps(x) = Base.eps(x)
7767

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ end
4040
end
4141

4242
@testset "issue #94" begin
43-
@test ApproxFunBase.real !== Base.real
4443
@test_throws MethodError ApproxFunBase.real(1,2)
44+
@test float(ApproxFunBase.UnsetNumber()) == ApproxFunBase.UnsetNumber()
45+
@test float(ApproxFunBase.UnsetNumber) == ApproxFunBase.UnsetNumber
46+
@test real(ApproxFunBase.UnsetNumber()) == ApproxFunBase.UnsetNumber()
47+
@test real(ApproxFunBase.UnsetNumber) == ApproxFunBase.UnsetNumber
4548
end
4649

4750
@testset "hasnumargs" begin

0 commit comments

Comments
 (0)