diff options
author | romankoshelev <romankoshelev@yandex-team.com> | 2023-08-14 19:51:50 +0300 |
---|---|---|
committer | romankoshelev <romankoshelev@yandex-team.com> | 2023-08-15 01:24:11 +0300 |
commit | cfcd865e05c0d0525ea27d1e153a043b32a85138 (patch) | |
tree | 68d3b3b25271e8a4998505897a269ff7ce119b76 /contrib/libs/icu/i18n/units_complexconverter.cpp | |
parent | ccb790c507bd5e8ffe2ef9886ce5ee0a7ce22a15 (diff) | |
download | ydb-cfcd865e05c0d0525ea27d1e153a043b32a85138.tar.gz |
Update ICU to 73.2
Diffstat (limited to 'contrib/libs/icu/i18n/units_complexconverter.cpp')
-rw-r--r-- | contrib/libs/icu/i18n/units_complexconverter.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/contrib/libs/icu/i18n/units_complexconverter.cpp b/contrib/libs/icu/i18n/units_complexconverter.cpp index 78cefbf7eb..edbb6573ff 100644 --- a/contrib/libs/icu/i18n/units_complexconverter.cpp +++ b/contrib/libs/icu/i18n/units_complexconverter.cpp @@ -143,7 +143,7 @@ MaybeStackVector<Measure> ComplexUnitsConverter::convert(double quantity, // TODO: return an error for "foot-and-foot"? MaybeStackVector<Measure> result; int sign = 1; - if (quantity < 0) { + if (quantity < 0 && unitsConverters_.length() > 1) { quantity *= -1; sign = -1; } @@ -164,12 +164,14 @@ MaybeStackVector<Measure> ComplexUnitsConverter::convert(double quantity, if (i < n - 1) { // If quantity is at the limits of double's precision from an // integer value, we take that integer value. - int64_t flooredQuantity = static_cast<int64_t>(floor(quantity * (1 + DBL_EPSILON))); + int64_t flooredQuantity; if (uprv_isNaN(quantity)) { // With clang on Linux: floor does not support NaN, resulting in // a giant negative number. For now, we produce "0 feet, NaN // inches". TODO(icu-units#131): revisit desired output. flooredQuantity = 0; + } else { + flooredQuantity = static_cast<int64_t>(floor(quantity * (1 + DBL_EPSILON))); } intValues[i] = flooredQuantity; @@ -183,7 +185,7 @@ MaybeStackVector<Measure> ComplexUnitsConverter::convert(double quantity, } else { quantity = remainder; } - } + } } applyRounder(intValues, quantity, rounder, status); @@ -210,7 +212,6 @@ MaybeStackVector<Measure> ComplexUnitsConverter::convert(double quantity, } } - // Transfer values into result and return: for(int32_t i = 0, n = unitsConverters_.length(); i < n; ++i) { U_ASSERT(tmpResult[i] != nullptr); @@ -224,6 +225,12 @@ MaybeStackVector<Measure> ComplexUnitsConverter::convert(double quantity, void ComplexUnitsConverter::applyRounder(MaybeStackArray<int64_t, 5> &intValues, double &quantity, icu::number::impl::RoundingImpl *rounder, UErrorCode &status) const { + if (uprv_isInfinite(quantity) || uprv_isNaN(quantity)) { + // Inf and NaN can't be rounded, and calculating `carry` below is known + // to fail on Gentoo on HPPA and OpenSUSE on riscv64. Nothing to do. + return; + } + if (rounder == nullptr) { // Nothing to do for the quantity. return; |