Skip to content

Commit 00b8fba

Browse files
LeszekSwirskiV8 LUCI CQ
authored andcommitted
[conversions] Check for denormal flushing in DoubleToRadixString
Explicitly check the denormal flushing flag in DoubleToRadixString, to avoid the compiler optimizing away checks against zero. Bug: 382005099 Fixed: 397731718 Change-Id: If9298e68827bf2e5a1fd987b04b2536bf937a19f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6286167 Commit-Queue: Leszek Swirski <[email protected]> Auto-Submit: Leszek Swirski <[email protected]> Reviewed-by: Jakob Kummerow <[email protected]> Cr-Commit-Position: refs/heads/main@{#98833}
1 parent 788343c commit 00b8fba

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/numbers/conversions.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,11 +1251,19 @@ std::string_view DoubleToRadixStringView(double value, int radix,
12511251
double fraction = value - integer;
12521252
// We only compute fractional digits up to the input double's precision.
12531253
double delta = 0.5 * (base::Double(value).NextDouble() - value);
1254-
delta = std::max(base::Double(0.0).NextDouble(), delta);
1255-
// Delta should always be greater than zero, so long as we're not flushing
1256-
// denormals to zero.
1257-
DCHECK_IMPLIES(!(delta > 0.0), base::FPU::GetFlushDenormals());
1258-
if (delta > 0.0 && fraction >= delta) {
1254+
bool delta_is_positive = true;
1255+
// If the delta rounded down to zero, use the minimum (denormal) delta
1256+
// value. Be careful around denormal flushing when doing so.
1257+
if (delta <= 0) {
1258+
if (base::FPU::GetFlushDenormals()) {
1259+
// We're flushing the delta value to zero, so the loop below won't
1260+
// make progress. Skip it instead.
1261+
delta_is_positive = false;
1262+
} else {
1263+
delta = base::Double(0.0).NextDouble();
1264+
}
1265+
}
1266+
if (delta_is_positive && fraction >= delta) {
12591267
// Insert decimal point.
12601268
buffer[fraction_cursor++] = '.';
12611269
do {

0 commit comments

Comments
 (0)