Skip to content

Commit

Permalink
julia/Rational: x == 0 -> iszero(x) (#1872)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsajko authored Oct 18, 2024
1 parent 983f6ec commit dedf056
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/julia/Rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ divexact(a::Integer, b::Rational; check::Bool=true) = a//b
divexact(a::Rational, b::Rational; check::Bool=true) = a//b

function divides(a::T, b::T) where T <: Rational
if b == 0
if iszero(b)
return false, T(0)
else
return true, divexact(a, b; check=false)
Expand Down Expand Up @@ -206,7 +206,7 @@ function rand(rng::AbstractRNG,
) where {T}
R, n = sp[][1:end]
d = T(0)
while d == 0
while iszero(d)
d = T(rand(rng, n))
end
n = T(rand(rng, n))
Expand All @@ -231,14 +231,14 @@ rand(R::Rationals, n) = rand(Random.GLOBAL_RNG, R, n)
#
# TODO: what happens to z = 0???
function remove(z::Rational{T}, p::T) where {T<:Integer}
z == 0 && return (0, z)
iszero(z) && return (0, z)
v, d = remove(denominator(z), p)
w, n = remove(numerator(z), p)
return w - v, n // d
end

function valuation(z::Rational{T}, p::T) where {T<:Integer}
z == 0 && error("Not yet implemented")
iszero(z) && error("Not yet implemented")
v = valuation(denominator(z), p)
w = valuation(numerator(z), p)
return w - v
Expand Down

0 comments on commit dedf056

Please sign in to comment.