Skip to content

Commit cd3c808

Browse files
committed
fix tau display
1 parent ce82a63 commit cd3c808

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/grid_fmt.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,24 @@ impl GridFmt for f64 {
7373
return vec![vec!['W']];
7474
} else if positive.fract() == 0.0 || positive.is_nan() {
7575
format!("{minus}{positive}")
76-
} else if let Some((num, denom)) =
76+
} else if let Some((num, denom, approx)) =
7777
[1u8, 2, 3, 4, 5, 6, 8, 9, 12].iter().find_map(|&denom| {
7878
let num = (positive * denom as f64) / TAU;
79-
if (num - num.round()).abs() <= f64::EPSILON {
80-
Some((num.round() as u8, denom))
79+
let rounded = num.round();
80+
if (num - rounded).abs() <= f64::EPSILON && rounded != 0.0 {
81+
Some((num.round() as u8, denom, num != rounded))
8182
} else {
8283
None
8384
}
8485
})
8586
{
87+
let prefix = if approx { "~" } else { "" };
8688
if denom == 1 {
87-
format!("{minus}{num}τ")
89+
format!("{prefix}{minus}{num}τ")
8890
} else if num == 1 {
89-
format!("{minus}τ/{denom}")
91+
format!("{prefix}{minus}τ/{denom}")
9092
} else {
91-
format!("{minus}{num}τ/{denom}")
93+
format!("{prefix}{minus}{num}τ/{denom}")
9294
}
9395
} else {
9496
let mut pos_formatted = positive.to_string();

0 commit comments

Comments
 (0)