mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-24 10:09:01 -06:00
Fix trailing dot in All Metadata rational formatter
Found while testing crates/meta/src/tags.rs:148 (rational) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
d999e382ba
commit
af0146c5e8
+18
-1
@@ -145,7 +145,14 @@ fn rational(n: f64, d: f64) -> String {
|
||||
return "—".into();
|
||||
}
|
||||
let v = n / d;
|
||||
if (v - v.round()).abs() < 1e-9 { format!("{}", v.round()) } else { format!("{:.4}", v).trim_end_matches('0').to_string() }
|
||||
if (v - v.round()).abs() < 1e-9 {
|
||||
let r = v.round();
|
||||
if r == 0.0 { "0".to_string() } else { format!("{}", r) }
|
||||
} else {
|
||||
let s = format!("{:.4}", v);
|
||||
let s = s.trim_end_matches('0').trim_end_matches('.');
|
||||
if s == "-0" { "0".to_string() } else { s.to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
fn list<T: ToString>(v: &[T]) -> String {
|
||||
@@ -370,6 +377,16 @@ pub fn file_tag_rows(bytes: &[u8]) -> Vec<TagRow> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn rational_has_no_trailing_dot() {
|
||||
assert_eq!(rational(1.0, 100000.0), "0");
|
||||
assert_eq!(rational(-1.0, 100000.0), "0");
|
||||
assert_eq!(rational(-1.0, 1e10), "0");
|
||||
assert_eq!(rational(1000001.0, 100000.0), "10");
|
||||
assert_eq!(rational(1.0, 3.0), "0.3333");
|
||||
assert_eq!(rational(5.0, 2.0), "2.5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_from_written_exif() {
|
||||
let m = crate::Metadata {
|
||||
|
||||
Reference in New Issue
Block a user