From 0e8abd4592ecd7e214071cf29a9e5d94c97d6b25 Mon Sep 17 00:00:00 2001 From: lcontento Date: Mon, 8 Oct 2018 16:33:49 +0900 Subject: [PATCH 1/5] Fix abs for Rational{<:Unsigned} --- base/rational.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/base/rational.jl b/base/rational.jl index 6a05b18b7eb3b..eae6e46a21408 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -226,6 +226,8 @@ signbit(x::Rational) = signbit(x.num) copysign(x::Rational, y::Real) = copysign(x.num,y) // x.den copysign(x::Rational, y::Rational) = copysign(x.num,y.num) // x.den +abs(x::Rational{T}) where {T<:Unsigned} = x + typemin(::Type{Rational{T}}) where {T<:Integer} = -one(T)//zero(T) typemax(::Type{Rational{T}}) where {T<:Integer} = one(T)//zero(T) From 3d9ad104aa690b6490379ef5cf872d33f4a367bb Mon Sep 17 00:00:00 2001 From: lcontento Date: Mon, 8 Oct 2018 16:37:26 +0900 Subject: [PATCH 2/5] Add tests for abs(x::Rational) --- test/rational.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/rational.jl b/test/rational.jl index e5296cac2ed17..40ce2356964c5 100644 --- a/test/rational.jl +++ b/test/rational.jl @@ -96,6 +96,10 @@ using Test @test !(1//3 < NaN) @test !(1//3 == NaN) @test !(1//3 > NaN) + + @test abs(one(Rational{UInt})) === one(Rational{UInt}) + @test abs(one(Rational{Int})) === one(Rational{Int}) + @test abs(-one(Rational{Int})) === one(Rational{Int}) end @testset "Rational methods" begin From ffacc1887c52ea5b48f10ddd578c9ee3cbd07b69 Mon Sep 17 00:00:00 2001 From: lcontento Date: Mon, 8 Oct 2018 17:02:28 +0900 Subject: [PATCH 3/5] Remove extra white space in test/rational.jl --- test/rational.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rational.jl b/test/rational.jl index 40ce2356964c5..a7213428ce566 100644 --- a/test/rational.jl +++ b/test/rational.jl @@ -96,7 +96,7 @@ using Test @test !(1//3 < NaN) @test !(1//3 == NaN) @test !(1//3 > NaN) - + @test abs(one(Rational{UInt})) === one(Rational{UInt}) @test abs(one(Rational{Int})) === one(Rational{Int}) @test abs(-one(Rational{Int})) === one(Rational{Int}) From 8d7c863b65f2646dd49f1670db34f07eb8a9c458 Mon Sep 17 00:00:00 2001 From: lcontento Date: Tue, 9 Oct 2018 14:36:49 +0900 Subject: [PATCH 4/5] Add PR reference --- test/rational.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/rational.jl b/test/rational.jl index a7213428ce566..4d45dc62aed77 100644 --- a/test/rational.jl +++ b/test/rational.jl @@ -97,6 +97,7 @@ using Test @test !(1//3 == NaN) @test !(1//3 > NaN) + # PR 29561 @test abs(one(Rational{UInt})) === one(Rational{UInt}) @test abs(one(Rational{Int})) === one(Rational{Int}) @test abs(-one(Rational{Int})) === one(Rational{Int}) From 3e391fa4d2b3b7c4c5f351427a938bfd7d0c2572 Mon Sep 17 00:00:00 2001 From: lcontento Date: Tue, 9 Oct 2018 14:39:41 +0900 Subject: [PATCH 5/5] Update rational.jl --- base/rational.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/rational.jl b/base/rational.jl index eae6e46a21408..107e3f42cd00e 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -226,7 +226,7 @@ signbit(x::Rational) = signbit(x.num) copysign(x::Rational, y::Real) = copysign(x.num,y) // x.den copysign(x::Rational, y::Rational) = copysign(x.num,y.num) // x.den -abs(x::Rational{T}) where {T<:Unsigned} = x +abs(x::Rational) = Rational(abs(x.num), x.den) typemin(::Type{Rational{T}}) where {T<:Integer} = -one(T)//zero(T) typemax(::Type{Rational{T}}) where {T<:Integer} = one(T)//zero(T)