Skip to content

Commit 5ff2e53

Browse files
committed
Linting
1 parent c47a8b6 commit 5ff2e53

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

src/ops/circular.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::bounded::{NonNegative, UnitInterval};
44
use crate::error::{Error, Result};
55
use crate::kernel::circular_vectoring;
66
use crate::ops::algebraic::sqrt_nonneg;
7-
use crate::tables::chebyshev::{horner, COS_Q_HI, COS_Q_LO, SIN_P_HI, SIN_P_LO};
7+
use crate::tables::chebyshev::{COS_Q_HI, COS_Q_LO, SIN_P_HI, SIN_P_LO, horner};
88
use crate::traits::CordicNumber;
99

1010
/// Sine and cosine. More efficient than separate calls. Accepts any angle.
@@ -68,17 +68,13 @@ pub fn sin_cos<T: CordicNumber>(angle: T) -> (T, T) {
6868
let (sp_val, cp_val) = if T::frac_bits() >= 24 {
6969
// High precision: degree 15 sin, degree 14 cos
7070
let sp = horner(&SIN_P_HI, u);
71-
let sin_approx = poly_arg.saturating_add(
72-
poly_arg.saturating_mul(u).saturating_mul(sp),
73-
);
71+
let sin_approx = poly_arg.saturating_add(poly_arg.saturating_mul(u).saturating_mul(sp));
7472
let cp = horner(&COS_Q_HI, u);
7573
(sin_approx, one.saturating_add(u.saturating_mul(cp)))
7674
} else {
7775
// Low precision: degree 9 sin, degree 8 cos
7876
let sp = horner(&SIN_P_LO, u);
79-
let sin_approx = poly_arg.saturating_add(
80-
poly_arg.saturating_mul(u).saturating_mul(sp),
81-
);
77+
let sin_approx = poly_arg.saturating_add(poly_arg.saturating_mul(u).saturating_mul(sp));
8278
let cp = horner(&COS_Q_LO, u);
8379
(sin_approx, one.saturating_add(u.saturating_mul(cp)))
8480
};

src/tables/chebyshev.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,3 @@ pub const COS_Q_HI: [i64; 7] = [
8484
0x0555_5555_5555_5435, // +4.167e-02
8585
-0x3FFF_FFFF_FFFF_FFFE, // -5.000e-01
8686
];
87-

tests/unit/tables/chebyshev.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ mod tests {
6060
] {
6161
for (i, &bits) in table.iter().enumerate() {
6262
let val = i1f63_to_f64(bits).abs();
63-
assert!(
64-
val < 1.0,
65-
"{name}[{i}] = {val}, exceeds I1F63 range"
66-
);
63+
assert!(val < 1.0, "{name}[{i}] = {val}, exceeds I1F63 range");
6764
}
6865
}
6966
}

tests/unit/traits.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ mod tests {
8282
assert_eq!(I48F16::frac_bits(), 16);
8383
}
8484

85+
#[test]
86+
fn div_overflow_saturates_to_min() {
87+
// Dividing a negative number by zero should saturate to MIN
88+
// (signs disagree: negative / "positive zero").
89+
let neg = I16F16::from_num(-1);
90+
let zero = I16F16::ZERO;
91+
assert_eq!(neg.div(zero), I16F16::MIN);
92+
}
93+
94+
#[test]
95+
fn div_by_zero_positive_saturates_to_max() {
96+
let pos = I16F16::from_num(1);
97+
let zero = I16F16::ZERO;
98+
assert_eq!(pos.div(zero), I16F16::MAX);
99+
}
100+
85101
#[test]
86102
fn frac_pi_4_values() {
87103
// Test the frac_pi_4() default implementation

0 commit comments

Comments
 (0)