Skip to content

Commit 88c673c

Browse files
authored
Fix a check broken by wrong operator precedence (#2249)
In Julia, `a && b || c` is the same as `(a && b) || c` but the code clearly assumes that it is `a && (b || c)`. But also this code can be simplified, so let's do that. This also fixes a JET warning about `d2` possibly not being defined.
1 parent 31ea1cd commit 88c673c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/generic/MPoly.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,10 +1629,9 @@ function sqrt_classical_char2(a::MPoly{T}; check::Bool=true) where {T <: RingEle
16291629
for i = 1:m
16301630
d1 = monomial_halves!(Qe, i, a.exps, i, mask, N)
16311631
if check
1632+
d1 || return false, par()
16321633
d2 = is_square(a.coeffs[i])
1633-
end
1634-
if check && !d1 || !d2
1635-
return false, par()
1634+
d2 || return false, par()
16361635
end
16371636
Qc[i] = sqrt(a.coeffs[i]; check=check)
16381637
end
@@ -1688,9 +1687,10 @@ function sqrt_heap(a::MPoly{T}, bits::Int; check::Bool=true) where {T <: RingEle
16881687
reuse = zeros(Int, 0)
16891688
# get leading coeff of sqrt
16901689
d1 = monomial_halves!(Qe, 1, a.exps, 1, mask, N)
1691-
d2 = check ? is_square(a.coeffs[1]) : true
1692-
if check && !d1 || !d2
1693-
return false, par()
1690+
if check
1691+
d1 || return false, par()
1692+
d2 = is_square(a.coeffs[1])
1693+
d2 || return false, par()
16941694
end
16951695
Qc[1] = sqrt(a.coeffs[1]; check=check)
16961696
mb = -2*Qc[1]
@@ -1799,12 +1799,12 @@ function sqrt_heap(a::MPoly{T}, bits::Int; check::Bool=true) where {T <: RingEle
17991799
else
18001800
# if not, check the accumulation is divisible by leading coeff
18011801
if check
1802+
# if accumulation term is not divisible, return false
1803+
d1 || return false, par()
18021804
d2, Qc[k] = divides(qc, mb)
1805+
d2 || return false, par()
18031806
else
1804-
d2, Qc[k] = true, divexact(qc, mb; check=check)
1805-
end
1806-
if check && !d1 || !d2 # if accumulation term is not divisible, return false
1807-
return false, par()
1807+
Qc[k] = divexact(qc, mb; check=check)
18081808
end
18091809
viewalloc += 1
18101810
push!(Viewn, viewalloc)

0 commit comments

Comments
 (0)