diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index 110da07c7..8eabf2e40 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -414,6 +414,9 @@ static int test_truncd(void) tr_snprintf(buf, sizeof(buf), "%.0f", tr_truncd(3.3333, 0)); check_str(buf, ==, "3"); + tr_snprintf(buf, sizeof(buf), "%.0f", tr_truncd(3.9999, 0)); + check_str(buf, ==, "3"); + #if !(defined(_MSC_VER) || (defined(__MINGW32__) && defined(__MSVCRT__))) /* FIXME: MSCVRT behaves differently in case of nan */ tr_snprintf(buf, sizeof(buf), "%.2f", tr_truncd(nan, 2)); diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 42f4996ce..04b4372f7 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -17,9 +17,9 @@ #include /* isdigit(), tolower() */ #include -#include /* DBL_EPSILON */ +#include /* DBL_DIG */ #include /* localeconv() */ -#include /* pow(), fabs(), floor() */ +#include /* fabs(), floor() */ #include #include /* getenv() */ #include /* strerror(), memset(), memmem() */ @@ -1625,8 +1625,7 @@ double tr_truncd(double x, int precision) { char* pt; char buf[128]; - int const max_precision = (int)log10(1.0 / DBL_EPSILON) - 1; - tr_snprintf(buf, sizeof(buf), "%.*f", max_precision, x); + tr_snprintf(buf, sizeof(buf), "%.*f", DBL_DIG, x); if ((pt = strstr(buf, localeconv()->decimal_point)) != NULL) {