mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Fix signed integer overflow on x = 0, detected by GCC sanitizer
This commit is contained in:
parent
8793c2eed9
commit
fdefff1108
@ -1446,8 +1446,8 @@ std::string formatFPNumber(double x)
|
||||
os << std::fixed;
|
||||
// Prevent outputs of 23.4200000000000017 but output small numbers
|
||||
// with at least 6 significant digits.
|
||||
double const logarithm = log10(fabs(x));
|
||||
os << std::setprecision(max(6 - iround(logarithm), 0)) << x;
|
||||
int const precision = (x == 0.0) ? 0 : max(6 - iround(log10(fabs(x))), 0);
|
||||
os << std::setprecision(precision) << x;
|
||||
string result = os.str();
|
||||
if (result.find('.') != string::npos) {
|
||||
result = rtrim(result, "0");
|
||||
|
Loading…
Reference in New Issue
Block a user