Skip to content

Commit 2443555

Browse files
committed
Fix incorrect multiplication
1 parent f1cf748 commit 2443555

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/algebraic_numbers.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn sign_changes_at(
202202
let degree = polynomial.degree().unwrap_or(0);
203203
let s = Sign::new(&polynomial.highest_power_coefficient());
204204
if degree.is_odd() {
205-
s.map(|| -s)
205+
s.map(|s| -s)
206206
} else {
207207
s
208208
}
@@ -1000,23 +1000,20 @@ trait RootSelector: Sized {
10001000
&factor.primitive_sturm_sequence,
10011001
ValueOrInfinity::Value(&lower_bound),
10021002
);
1003-
if lower_bound_sign_changes.is_root {
1004-
return lower_bound.into();
1005-
}
10061003
let upper_bound_sign_changes = sign_changes_at(
10071004
&factor.primitive_sturm_sequence,
10081005
ValueOrInfinity::Value(&upper_bound),
10091006
);
1010-
if upper_bound_sign_changes.is_root {
1011-
return upper_bound.into();
1012-
}
1013-
if lower_bound_sign_changes.sign_change_count
1014-
!= upper_bound_sign_changes.sign_change_count
1015-
{
1016-
let num_roots = distance(
1017-
lower_bound_sign_changes.sign_change_count,
1018-
upper_bound_sign_changes.sign_change_count,
1019-
);
1007+
let num_roots = if lower_bound_sign_changes.is_root {
1008+
1
1009+
} else {
1010+
0
1011+
} + distance(
1012+
lower_bound_sign_changes.sign_change_count,
1013+
upper_bound_sign_changes.sign_change_count,
1014+
);
1015+
1016+
if num_roots > 0 {
10201017
roots_left += num_roots;
10211018
factors.push(factor);
10221019
}
@@ -1885,6 +1882,20 @@ mod tests {
18851882
make_sqrt(3, DyadicFractionInterval::from_int_range(bi(1), bi(2), 0)),
18861883
make_sqrt(6, DyadicFractionInterval::from_int_range(bi(1), bi(10), 0)),
18871884
);
1885+
test_case(
1886+
RealAlgebraicNumber::new_unchecked(
1887+
p(&[-1, 2, 4]),
1888+
DyadicFractionInterval::new(bi(-1), bi(3), 1),
1889+
),
1890+
RealAlgebraicNumber::new_unchecked(
1891+
p(&[-1, 2, 4]),
1892+
DyadicFractionInterval::new(bi(-1), bi(3), 1),
1893+
),
1894+
RealAlgebraicNumber::new_unchecked(
1895+
p(&[1, -12, 16]),
1896+
DyadicFractionInterval::new(bi(0), bi(2), 3),
1897+
),
1898+
);
18881899
}
18891900

18901901
#[test]

0 commit comments

Comments
 (0)