fix: a time label's mantissa cannot reach its own radix
`format_time()` picked its sub-second rung from the raw value, so three significant figures of a value just under a rung's top rounded to 1000 and `%.3g` wrote that as an exponent: a one-second tick computed as 0.9999999 s read `1e+03ms`. The rung is now chosen by the rounded mantissa, which is the same 999.5 check `format_si()` already made for the SI prefixes, and a value that rounds to a whole second leaves the sub-second branch entirely.
This commit is contained in:
1 parent
c2c8c596f3
commit
58473db384
2 files changed
+21
-2
No files matched your search
@@ -263,6 +263,18 @@ PLOT_TEST(format_time_never_lets_a_field_reach_its_radix) {
|
||||
plot::format_time(86399.5, b, sizeof b); PLOT_CHECK(std::string(b) == "1d");
|
||||
plot::format_time(86400.0, b, sizeof b); PLOT_CHECK(std::string(b) == "1d");
|
||||
|
||||
// A mantissa may not reach its own radix either: three significant figures of a value a
|
||||
// hair under a rung's top round up to 1000, and `%.3g` writes that `1e+03`. A one-second
|
||||
// tick computed as 0.9999999 s read `1e+03ms` on a live axis, which is where this was seen.
|
||||
plot::format_time(0.9999999, b, sizeof b); PLOT_CHECK(std::string(b) == "1s");
|
||||
plot::format_time(0.9995, b, sizeof b); PLOT_CHECK(std::string(b) == "1s");
|
||||
plot::format_time(0.9994, b, sizeof b); PLOT_CHECK(std::string(b) == "999ms");
|
||||
plot::format_time(0.9999999e-3, b, sizeof b); PLOT_CHECK(std::string(b) == "1ms");
|
||||
plot::format_time(0.9994e-3, b, sizeof b); PLOT_CHECK(std::string(b) == "999\u00b5s");
|
||||
plot::format_time(0.9999999e-6, b, sizeof b); PLOT_CHECK(std::string(b) == "1\u00b5s");
|
||||
plot::format_time(0.9999999e-9, b, sizeof b); PLOT_CHECK(std::string(b) == "1ns");
|
||||
plot::format_time(-0.9999999, b, sizeof b); PLOT_CHECK(std::string(b) == "-1s");
|
||||
|
||||
// Sweep the boundary neighbourhoods and check every emitted field.
|
||||
const double values[] = {0.4, 0.9995, 1.0, 59.4, 59.4999, 59.5, 59.9, 60.0, 90.0, 119.5, 3599.4,
|
||||
3599.5, 3599.9, 86399.4, 86399.5, 86399.9, 86400.0, 172800.0, -119.5,
|
||||
|
||||
Reference in new issue
Block a user