Skip to content

Commit a481116

Browse files
committed
Fix Base.zero and Base.one for RationalPoly
1 parent c00e66a commit a481116

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/rational.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Base.:*(r::RationalPoly, p::APL) = (r.num * p) / r.den
6666
Base.:*(α, r::RationalPoly) =* r.num) / r.den
6767
Base.:*(r::RationalPoly, α) = (r.num * α) / r.den
6868

69-
Base.zero(::RationalPoly{NT}) where {NT} = zero(NT) / one(NT)
69+
Base.zero(r::RationalPoly) = zero(typeof(r))
7070
Base.zero(::Type{RationalPoly{NT, DT}}) where {NT, DT} = zero(NT) / one(DT)
71-
Base.one(::RationalPoly{NT}) where {NT} = one(NT) / one(NT)
71+
Base.one(r::RationalPoly) = one(typeof(r))
7272
Base.one(::Type{RationalPoly{NT, DT}}) where {NT, DT} = one(NT) / one(DT)

test/rational.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
@test x / x^2 == inv(x)
2929
@test isone(((x+1) / (x-1)) / ((x+1) / (x-1)))
3030
@test ((x+1)^2 / (x-1)) / ((x+1) / (x-1)) == x+1
31-
poly = x+1/x
31+
poly = (x+1)/(x+2.0)
3232
RType = typeof(poly)
3333
@test RType(true) == one(RType)
3434
@test RType(false) == zero(RType)
35-
@test one(RType) isa RationalPoly
36-
@test zero(RType) isa RationalPoly
37-
@test one(poly) isa RationalPoly
38-
@test zero(poly) isa RationalPoly
35+
@test one(RType) isa RType
36+
@test zero(RType) isa RType
37+
@test one(poly) isa RType
38+
@test zero(poly) isa RType
3939
end

0 commit comments

Comments
 (0)