mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-12 01:51:34 +11:00
Add comment explaining how the fiddle works
This commit is contained in:
parent
89f89803dd
commit
e1e4318c38
|
@ -459,6 +459,11 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> Display for Num<I, N> {
|
||||||
|
|
||||||
let mut fractional = self.0 & mask;
|
let mut fractional = self.0 & mask;
|
||||||
|
|
||||||
|
// Negative fix nums are awkward to print if they have non zero fractional part.
|
||||||
|
// This is because you can think of them as `number + non negative fraction`.
|
||||||
|
//
|
||||||
|
// But if you think of a negative number, you'd like it to be `negative number - non negative fraction`
|
||||||
|
// So we have to add 1 to the integral bit, and take 1 - fractional bit
|
||||||
if fractional != I::zero() && integral < I::zero() {
|
if fractional != I::zero() && integral < I::zero() {
|
||||||
integral = integral + I::one();
|
integral = integral + I::one();
|
||||||
fractional = (I::one() << N) - fractional;
|
fractional = (I::one() << N) - fractional;
|
||||||
|
|
Loading…
Reference in a new issue