diff --git a/base/rational.jl b/base/rational.jl index 3cf51283f5b3f0..18d104a434923e 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -262,7 +262,7 @@ typemin(::Type{Rational{T}}) where {T<:Integer} = unsafe_rational(T, zero(T), on typemax(::Type{Rational{T}}) where {T<:Integer} = unsafe_rational(T, one(T), zero(T)) isinteger(x::Rational) = x.den == 1 -ispow2(x::Rational) = (x.den == 1 && ispow2(x.num)) || (x.num == 1 && ispow2(x.den)) +ispow2(x::Rational) = ispow2(x.num)) & ispow2(x.den) +(x::Rational) = unsafe_rational(+x.num, x.den) -(x::Rational) = unsafe_rational(-x.num, x.den) diff --git a/test/rational.jl b/test/rational.jl index 166df8afc47af4..76ff20acbf938e 100644 --- a/test/rational.jl +++ b/test/rational.jl @@ -595,7 +595,6 @@ end @test -2//3 * 0x1 == 0x1 * -2//3 == -2//3 end - @testset "ispow2" begin @test ispow2(4//1) @test ispow2(1//8)