Skip to content

Commit 79ce74c

Browse files
committed
fix(deep_causality_num): The Display implementation for Quaternion has been refined to correctly handle the signs of its components, producing a more standard and readable mathematical format. All tests pass.
Signed-off-by: Marvin Hansen <[email protected]>
1 parent 098e140 commit 79ce74c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

deep_causality_num/src/quaternion/display.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ use crate::quaternion::Quaternion;
66
// Display
77
impl<F: Float + Display> Display for Quaternion<F> {
88
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9-
write!(f, "{} + {}i + {}j + {}k", self.w, self.x, self.y, self.z)
9+
write!(f, "{}", self.w)?;
10+
write!(
11+
f,
12+
" {} {}i",
13+
if self.x < F::zero() { "-" } else { "+" },
14+
self.x.abs()
15+
)?;
16+
write!(
17+
f,
18+
" {} {}j",
19+
if self.y < F::zero() { "-" } else { "+" },
20+
self.y.abs()
21+
)?;
22+
write!(
23+
f,
24+
" {} {}k",
25+
if self.z < F::zero() { "-" } else { "+" },
26+
self.z.abs()
27+
)
1028
}
1129
}

0 commit comments

Comments
 (0)