Skip to content

Commit 245b6b0

Browse files
pthierV8 LUCI CQ
authored andcommitted
[conversions] Fix toPrecision buffer length
Fixed: 386487312 Change-Id: I1247cafb0c27d2a1ea80c5c52e32926b07740ab4 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6162974 Auto-Submit: Patrick Thier <[email protected]> Reviewed-by: Leszek Swirski <[email protected]> Commit-Queue: Leszek Swirski <[email protected]> Cr-Commit-Position: refs/heads/main@{#98021}
1 parent 44ea78c commit 245b6b0

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/numbers/conversions.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,10 +1196,6 @@ std::string_view DoubleToPrecisionStringView(double value, int p,
11961196
exponent, negative, p, buffer);
11971197
} else {
11981198
// Use fixed notation.
1199-
//
1200-
// Leave room in the result for appending a minus, a period and in
1201-
// the case where decimal_point is not positive for a zero in
1202-
// front of the period.
12031199
SimpleStringBuilder builder(buffer.begin(), buffer.length());
12041200
if (negative) builder.AddCharacter('-');
12051201
if (decimal_point <= 0) {

src/numbers/conversions.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ constexpr int kDoubleToFixedMaxDigitsBeforePoint = 21;
7272
// Leave room in the result for appending a minus and a period.
7373
constexpr int kDoubleToFixedMaxChars =
7474
kDoubleToFixedMaxDigitsBeforePoint + kMaxFractionDigits + 2;
75-
// Leave room in the result for appending a minus, for a period, the
76-
// letter 'e', a minus or a plus depending on the exponent, and a
77-
// three digit exponent.
78-
constexpr int kDoubleToPrecisionMaxChars = kMaxFractionDigits + 7;
75+
// Leave room in the result for appending a minus, for a period, up to 5 zeros
76+
// padding after the period and a zero in front of the period.
77+
constexpr int kDoubleToPrecisionMaxChars = kMaxFractionDigits + 8;
7978
// Leave room in the result for one digit before the period, a minus, a period,
8079
// the letter 'e', a minus or a plus depending on the exponent, and a three
8180
// digit exponent.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2024 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
assertEquals(
6+
'-0.000001234499999999999996546707660416419827242862083949148654937744140625000000000000000000000000000000000',
7+
(-.0000012345).toPrecision(100));

0 commit comments

Comments
 (0)