Convert negative precision to zero in printf (#1127)
and remove redundant check in grisu2_prettify.
diff --git a/include/fmt/format.h b/include/fmt/format.h
index e9f2951..0e8fb2e 100644
--- a/include/fmt/format.h
+++ b/include/fmt/format.h
@@ -1181,8 +1181,7 @@
*it++ = static_cast<Char>(params.upper ? 'E' : 'e');
return write_exponent<Char>(exp, it);
}
- const int exp_threshold = 21;
- if (size <= full_exp && full_exp <= exp_threshold) {
+ if (size <= full_exp) {
// 1234e7 -> 12340000000[.0+]
it = copy_str<Char>(digits, digits + size, it);
it = std::fill_n(it, full_exp - size, static_cast<Char>('0'));
diff --git a/include/fmt/printf.h b/include/fmt/printf.h
index dd55313..f75f10a 100644
--- a/include/fmt/printf.h
+++ b/include/fmt/printf.h
@@ -44,7 +44,7 @@
int operator()(T value) {
if (!int_checker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
FMT_THROW(format_error("number is too big"));
- return static_cast<int>(value);
+ return (std::max)(static_cast<int>(value), 0);
}
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>