From d2521fe36033fc328d2f52a3802750ff87e319ec Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Sun, 10 Mar 2024 23:44:16 -0400 Subject: [PATCH] Simplify the construction of `x / 1` and `x / -1` --- src/types.jl | 2 +- test/basics.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types.jl b/src/types.jl index 840f8a6e1..2202a8df1 100644 --- a/src/types.jl +++ b/src/types.jl @@ -1143,7 +1143,7 @@ end \(a::Number, b::SN) = b / a -/(a::SN, b::Number) = (b isa Integer ? 1//b : inv(b)) * a +/(a::SN, b::Number) = (isone(abs(b)) ? b : (b isa Integer ? 1//b : inv(b))) * a //(a::Union{SN, Number}, b::SN) = a / b diff --git a/test/basics.jl b/test/basics.jl index 6dbeb9384..cc3464eab 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -301,6 +301,8 @@ end @test (2.5x/3x).num == 2.5 @test (2.5x/3x).den == 3 @test (x/3x) == 1//3 + @test isequal(x / 1, x) + @test isequal(x / -1, -x) end @testset "LiteralReal" begin