Commit e7409329 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/{test-bignum-dtoa, test-dtoa

... ,test-fast-dtoa, test-fixed-dtoa} to unittests/base/
{bignum-dtoa-unittest, dtoa-unittest, fast-dtoa-unittest,
fixed-dtoa-unittest}.

This CL also moves cctest/{gay-fixed, gay-precision,
gay-shortest} to unittest/{gay-fixed, gay-precision,
gay-shortest}.

Bug: v8:12781
Change-Id: Id6072f92908ad3abfe683c69dac041227de2553f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3607114
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80572}
parent 5c416ad2
...@@ -128,12 +128,6 @@ v8_source_set("cctest_sources") { ...@@ -128,12 +128,6 @@ v8_source_set("cctest_sources") {
"compiler/value-helper.cc", "compiler/value-helper.cc",
"compiler/value-helper.h", "compiler/value-helper.h",
"expression-type-collector-macros.h", "expression-type-collector-macros.h",
"gay-fixed.cc",
"gay-fixed.h",
"gay-precision.cc",
"gay-precision.h",
"gay-shortest.cc",
"gay-shortest.h",
"heap/heap-tester.h", "heap/heap-tester.h",
"heap/heap-utils.cc", "heap/heap-utils.cc",
"heap/heap-utils.h", "heap/heap-utils.h",
...@@ -193,7 +187,6 @@ v8_source_set("cctest_sources") { ...@@ -193,7 +187,6 @@ v8_source_set("cctest_sources") {
"test-api.cc", "test-api.cc",
"test-api.h", "test-api.h",
"test-atomicops.cc", "test-atomicops.cc",
"test-bignum-dtoa.cc",
"test-code-stub-assembler.cc", "test-code-stub-assembler.cc",
"test-constantpool.cc", "test-constantpool.cc",
"test-cpu-profiler.cc", "test-cpu-profiler.cc",
...@@ -206,13 +199,10 @@ v8_source_set("cctest_sources") { ...@@ -206,13 +199,10 @@ v8_source_set("cctest_sources") {
"test-disasm-regex-helper.cc", "test-disasm-regex-helper.cc",
"test-disasm-regex-helper.h", "test-disasm-regex-helper.h",
"test-diy-fp.cc", "test-diy-fp.cc",
"test-dtoa.cc",
"test-factory.cc", "test-factory.cc",
"test-fast-dtoa.cc",
"test-feedback-vector.cc", "test-feedback-vector.cc",
"test-feedback-vector.h", "test-feedback-vector.h",
"test-field-type-tracking.cc", "test-field-type-tracking.cc",
"test-fixed-dtoa.cc",
"test-flags.cc", "test-flags.cc",
"test-func-name-inference.cc", "test-func-name-inference.cc",
"test-global-handles.cc", "test-global-handles.cc",
......
...@@ -221,11 +221,15 @@ v8_source_set("unittests_sources") { ...@@ -221,11 +221,15 @@ v8_source_set("unittests_sources") {
"api/v8-script-unittest.cc", "api/v8-script-unittest.cc",
"base/address-region-unittest.cc", "base/address-region-unittest.cc",
"base/atomic-utils-unittest.cc", "base/atomic-utils-unittest.cc",
"base/bignum-dtoa-unittest.cc",
"base/bignum-unittest.cc", "base/bignum-unittest.cc",
"base/bits-unittest.cc", "base/bits-unittest.cc",
"base/cpu-unittest.cc", "base/cpu-unittest.cc",
"base/division-by-constant-unittest.cc", "base/division-by-constant-unittest.cc",
"base/double-unittest.cc", "base/double-unittest.cc",
"base/dtoa-unittest.cc",
"base/fast-dtoa-unittest.cc",
"base/fixed-dtoa-unittest.cc",
"base/flags-unittest.cc", "base/flags-unittest.cc",
"base/functional-unittest.cc", "base/functional-unittest.cc",
"base/ieee754-unittest.cc", "base/ieee754-unittest.cc",
...@@ -325,6 +329,12 @@ v8_source_set("unittests_sources") { ...@@ -325,6 +329,12 @@ v8_source_set("unittests_sources") {
"diagnostics/eh-frame-writer-unittest.cc", "diagnostics/eh-frame-writer-unittest.cc",
"diagnostics/gdb-jit-unittest.cc", "diagnostics/gdb-jit-unittest.cc",
"execution/microtask-queue-unittest.cc", "execution/microtask-queue-unittest.cc",
"gay-fixed.cc",
"gay-fixed.h",
"gay-precision.cc",
"gay-precision.h",
"gay-shortest.cc",
"gay-shortest.h",
"heap/allocation-observer-unittest.cc", "heap/allocation-observer-unittest.cc",
"heap/bitmap-test-utils.h", "heap/bitmap-test-utils.h",
"heap/bitmap-unittest.cc", "heap/bitmap-unittest.cc",
......
...@@ -25,18 +25,22 @@ ...@@ -25,18 +25,22 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "src/base/numbers/bignum-dtoa.h"
#include <stdlib.h> #include <stdlib.h>
#include "src/base/numbers/bignum-dtoa.h"
#include "src/base/numbers/double.h" #include "src/base/numbers/double.h"
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/cctest.h" #include "test/unittests/gay-fixed.h"
#include "test/cctest/gay-fixed.h" #include "test/unittests/gay-precision.h"
#include "test/cctest/gay-precision.h" #include "test/unittests/gay-shortest.h"
#include "test/cctest/gay-shortest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
using BignumDtoaTest = ::testing::Test;
namespace base { namespace base {
namespace test_bignum_dtoa { namespace test_bignum_dtoa {
...@@ -50,8 +54,7 @@ static void TrimRepresentation(char* representation) { ...@@ -50,8 +54,7 @@ static void TrimRepresentation(char* representation) {
static const int kBufferSize = 100; static const int kBufferSize = 100;
TEST_F(BignumDtoaTest, BignumDtoaVariousDoubles) {
TEST(BignumDtoaVariousDoubles) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
int length; int length;
...@@ -124,64 +127,59 @@ TEST(BignumDtoaVariousDoubles) { ...@@ -124,64 +127,59 @@ TEST(BignumDtoaVariousDoubles) {
CHECK_EQ(0, strcmp("429496727200000", buffer.begin())); CHECK_EQ(0, strcmp("429496727200000", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
BignumDtoa(4294967272.0, BIGNUM_DTOA_PRECISION, 14, buffer, &length, &point); BignumDtoa(4294967272.0, BIGNUM_DTOA_PRECISION, 14, buffer, &length, &point);
CHECK_GE(14, length); CHECK_GE(14, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("4294967272", buffer.begin())); CHECK_EQ(0, strcmp("4294967272", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
BignumDtoa(4.1855804968213567e298, BIGNUM_DTOA_SHORTEST, 0, BignumDtoa(4.1855804968213567e298, BIGNUM_DTOA_SHORTEST, 0, buffer, &length,
buffer, &length, &point); &point);
CHECK_EQ(0, strcmp("4185580496821357", buffer.begin())); CHECK_EQ(0, strcmp("4185580496821357", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
BignumDtoa(4.1855804968213567e298, BIGNUM_DTOA_PRECISION, 20, BignumDtoa(4.1855804968213567e298, BIGNUM_DTOA_PRECISION, 20, buffer, &length,
buffer, &length, &point); &point);
CHECK_GE(20, length); CHECK_GE(20, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("41855804968213567225", buffer.begin())); CHECK_EQ(0, strcmp("41855804968213567225", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
BignumDtoa(5.5626846462680035e-309, BIGNUM_DTOA_SHORTEST, 0, BignumDtoa(5.5626846462680035e-309, BIGNUM_DTOA_SHORTEST, 0, buffer, &length,
buffer, &length, &point); &point);
CHECK_EQ(0, strcmp("5562684646268003", buffer.begin())); CHECK_EQ(0, strcmp("5562684646268003", buffer.begin()));
CHECK_EQ(-308, point); CHECK_EQ(-308, point);
BignumDtoa(5.5626846462680035e-309, BIGNUM_DTOA_PRECISION, 1, BignumDtoa(5.5626846462680035e-309, BIGNUM_DTOA_PRECISION, 1, buffer, &length,
buffer, &length, &point); &point);
CHECK_GE(1, length); CHECK_GE(1, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("6", buffer.begin())); CHECK_EQ(0, strcmp("6", buffer.begin()));
CHECK_EQ(-308, point); CHECK_EQ(-308, point);
BignumDtoa(2147483648.0, BIGNUM_DTOA_SHORTEST, 0, BignumDtoa(2147483648.0, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
buffer, &length, &point);
CHECK_EQ(0, strcmp("2147483648", buffer.begin())); CHECK_EQ(0, strcmp("2147483648", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
BignumDtoa(2147483648.0, BIGNUM_DTOA_FIXED, 2, buffer, &length, &point);
BignumDtoa(2147483648.0, BIGNUM_DTOA_FIXED, 2,
buffer, &length, &point);
CHECK_GE(2, length - point); CHECK_GE(2, length - point);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("2147483648", buffer.begin())); CHECK_EQ(0, strcmp("2147483648", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
BignumDtoa(2147483648.0, BIGNUM_DTOA_PRECISION, 5, BignumDtoa(2147483648.0, BIGNUM_DTOA_PRECISION, 5, buffer, &length, &point);
buffer, &length, &point);
CHECK_GE(5, length); CHECK_GE(5, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("21475", buffer.begin())); CHECK_EQ(0, strcmp("21475", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
BignumDtoa(3.5844466002796428e+298, BIGNUM_DTOA_SHORTEST, 0, BignumDtoa(3.5844466002796428e+298, BIGNUM_DTOA_SHORTEST, 0, buffer, &length,
buffer, &length, &point); &point);
CHECK_EQ(0, strcmp("35844466002796428", buffer.begin())); CHECK_EQ(0, strcmp("35844466002796428", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
BignumDtoa(3.5844466002796428e+298, BIGNUM_DTOA_PRECISION, 10, BignumDtoa(3.5844466002796428e+298, BIGNUM_DTOA_PRECISION, 10, buffer,
buffer, &length, &point); &length, &point);
CHECK_GE(10, length); CHECK_GE(10, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("35844466", buffer.begin())); CHECK_EQ(0, strcmp("35844466", buffer.begin()));
...@@ -211,8 +209,8 @@ TEST(BignumDtoaVariousDoubles) { ...@@ -211,8 +209,8 @@ TEST(BignumDtoaVariousDoubles) {
CHECK_EQ(0, strcmp("2225073858507200889", buffer.begin())); CHECK_EQ(0, strcmp("2225073858507200889", buffer.begin()));
CHECK_EQ(-307, point); CHECK_EQ(-307, point);
BignumDtoa(4128420500802942e-24, BIGNUM_DTOA_SHORTEST, 0, BignumDtoa(4128420500802942e-24, BIGNUM_DTOA_SHORTEST, 0, buffer, &length,
buffer, &length, &point); &point);
CHECK_EQ(0, strcmp("4128420500802942", buffer.begin())); CHECK_EQ(0, strcmp("4128420500802942", buffer.begin()));
CHECK_EQ(-8, point); CHECK_EQ(-8, point);
...@@ -248,8 +246,7 @@ TEST(BignumDtoaVariousDoubles) { ...@@ -248,8 +246,7 @@ TEST(BignumDtoaVariousDoubles) {
CHECK_EQ(18, point); CHECK_EQ(18, point);
} }
TEST_F(BignumDtoaTest, BignumDtoaGayShortest) {
TEST(BignumDtoaGayShortest) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
int length; int length;
...@@ -266,8 +263,7 @@ TEST(BignumDtoaGayShortest) { ...@@ -266,8 +263,7 @@ TEST(BignumDtoaGayShortest) {
} }
} }
TEST_F(BignumDtoaTest, BignumDtoaGayFixed) {
TEST(BignumDtoaGayFixed) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
int length; int length;
...@@ -287,8 +283,7 @@ TEST(BignumDtoaGayFixed) { ...@@ -287,8 +283,7 @@ TEST(BignumDtoaGayFixed) {
} }
} }
TEST_F(BignumDtoaTest, BignumDtoaGayPrecision) {
TEST(BignumDtoaGayPrecision) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
int length; int length;
...@@ -300,8 +295,8 @@ TEST(BignumDtoaGayPrecision) { ...@@ -300,8 +295,8 @@ TEST(BignumDtoaGayPrecision) {
const PrecomputedPrecision current_test = precomputed[i]; const PrecomputedPrecision current_test = precomputed[i];
double v = current_test.v; double v = current_test.v;
int number_digits = current_test.number_digits; int number_digits = current_test.number_digits;
BignumDtoa(v, BIGNUM_DTOA_PRECISION, number_digits, BignumDtoa(v, BIGNUM_DTOA_PRECISION, number_digits, buffer, &length,
buffer, &length, &point); &point);
CHECK_EQ(current_test.decimal_point, point); CHECK_EQ(current_test.decimal_point, point);
CHECK_GE(number_digits, length); CHECK_GE(number_digits, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
......
...@@ -25,18 +25,22 @@ ...@@ -25,18 +25,22 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "src/base/numbers/dtoa.h"
#include <stdlib.h> #include <stdlib.h>
#include "src/base/numbers/double.h" #include "src/base/numbers/double.h"
#include "src/base/numbers/dtoa.h"
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/cctest.h" #include "test/unittests/gay-fixed.h"
#include "test/cctest/gay-fixed.h" #include "test/unittests/gay-precision.h"
#include "test/cctest/gay-precision.h" #include "test/unittests/gay-shortest.h"
#include "test/cctest/gay-shortest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
using DtoaTest = ::testing::Test;
namespace base { namespace base {
namespace test_dtoa { namespace test_dtoa {
...@@ -50,8 +54,7 @@ static void TrimRepresentation(char* representation) { ...@@ -50,8 +54,7 @@ static void TrimRepresentation(char* representation) {
static const int kBufferSize = 100; static const int kBufferSize = 100;
TEST_F(DtoaTest, DtoaVariousDoubles) {
TEST(DtoaVariousDoubles) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
base::Vector<char> buffer(buffer_container, kBufferSize); base::Vector<char> buffer(buffer_container, kBufferSize);
int length; int length;
...@@ -142,45 +145,43 @@ TEST(DtoaVariousDoubles) { ...@@ -142,45 +145,43 @@ TEST(DtoaVariousDoubles) {
CHECK_EQ(0, strcmp("4294967272", buffer.begin())); CHECK_EQ(0, strcmp("4294967272", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
DoubleToAscii(4294967272.0, DTOA_PRECISION, 14, buffer, &sign, &length,
DoubleToAscii(4294967272.0, DTOA_PRECISION, 14, &point);
buffer, &sign, &length, &point);
CHECK_GE(14, length); CHECK_GE(14, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("4294967272", buffer.begin())); CHECK_EQ(0, strcmp("4294967272", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
DoubleToAscii(4.1855804968213567e298, DTOA_SHORTEST, 0, DoubleToAscii(4.1855804968213567e298, DTOA_SHORTEST, 0, buffer, &sign,
buffer, &sign, &length, &point); &length, &point);
CHECK_EQ(0, strcmp("4185580496821357", buffer.begin())); CHECK_EQ(0, strcmp("4185580496821357", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
DoubleToAscii(4.1855804968213567e298, DTOA_PRECISION, 20, DoubleToAscii(4.1855804968213567e298, DTOA_PRECISION, 20, buffer, &sign,
buffer, &sign, &length, &point); &length, &point);
CHECK_GE(20, length); CHECK_GE(20, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("41855804968213567225", buffer.begin())); CHECK_EQ(0, strcmp("41855804968213567225", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
DoubleToAscii(5.5626846462680035e-309, DTOA_SHORTEST, 0, DoubleToAscii(5.5626846462680035e-309, DTOA_SHORTEST, 0, buffer, &sign,
buffer, &sign, &length, &point); &length, &point);
CHECK_EQ(0, strcmp("5562684646268003", buffer.begin())); CHECK_EQ(0, strcmp("5562684646268003", buffer.begin()));
CHECK_EQ(-308, point); CHECK_EQ(-308, point);
DoubleToAscii(5.5626846462680035e-309, DTOA_PRECISION, 1, DoubleToAscii(5.5626846462680035e-309, DTOA_PRECISION, 1, buffer, &sign,
buffer, &sign, &length, &point); &length, &point);
CHECK_GE(1, length); CHECK_GE(1, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(0, strcmp("6", buffer.begin())); CHECK_EQ(0, strcmp("6", buffer.begin()));
CHECK_EQ(-308, point); CHECK_EQ(-308, point);
DoubleToAscii(-2147483648.0, DTOA_SHORTEST, 0, DoubleToAscii(-2147483648.0, DTOA_SHORTEST, 0, buffer, &sign, &length,
buffer, &sign, &length, &point); &point);
CHECK_EQ(1, sign); CHECK_EQ(1, sign);
CHECK_EQ(0, strcmp("2147483648", buffer.begin())); CHECK_EQ(0, strcmp("2147483648", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
DoubleToAscii(-2147483648.0, DTOA_FIXED, 2, buffer, &sign, &length, &point); DoubleToAscii(-2147483648.0, DTOA_FIXED, 2, buffer, &sign, &length, &point);
CHECK_GE(2, length - point); CHECK_GE(2, length - point);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
...@@ -188,22 +189,22 @@ TEST(DtoaVariousDoubles) { ...@@ -188,22 +189,22 @@ TEST(DtoaVariousDoubles) {
CHECK_EQ(0, strcmp("2147483648", buffer.begin())); CHECK_EQ(0, strcmp("2147483648", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
DoubleToAscii(-2147483648.0, DTOA_PRECISION, 5, DoubleToAscii(-2147483648.0, DTOA_PRECISION, 5, buffer, &sign, &length,
buffer, &sign, &length, &point); &point);
CHECK_GE(5, length); CHECK_GE(5, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
CHECK_EQ(1, sign); CHECK_EQ(1, sign);
CHECK_EQ(0, strcmp("21475", buffer.begin())); CHECK_EQ(0, strcmp("21475", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
DoubleToAscii(-3.5844466002796428e+298, DTOA_SHORTEST, 0, DoubleToAscii(-3.5844466002796428e+298, DTOA_SHORTEST, 0, buffer, &sign,
buffer, &sign, &length, &point); &length, &point);
CHECK_EQ(1, sign); CHECK_EQ(1, sign);
CHECK_EQ(0, strcmp("35844466002796428", buffer.begin())); CHECK_EQ(0, strcmp("35844466002796428", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
DoubleToAscii(-3.5844466002796428e+298, DTOA_PRECISION, 10, DoubleToAscii(-3.5844466002796428e+298, DTOA_PRECISION, 10, buffer, &sign,
buffer, &sign, &length, &point); &length, &point);
CHECK_EQ(1, sign); CHECK_EQ(1, sign);
CHECK_GE(10, length); CHECK_GE(10, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
...@@ -234,8 +235,8 @@ TEST(DtoaVariousDoubles) { ...@@ -234,8 +235,8 @@ TEST(DtoaVariousDoubles) {
CHECK_EQ(0, strcmp("2225073858507200889", buffer.begin())); CHECK_EQ(0, strcmp("2225073858507200889", buffer.begin()));
CHECK_EQ(-307, point); CHECK_EQ(-307, point);
DoubleToAscii(4128420500802942e-24, DTOA_SHORTEST, 0, DoubleToAscii(4128420500802942e-24, DTOA_SHORTEST, 0, buffer, &sign, &length,
buffer, &sign, &length, &point); &point);
CHECK_EQ(0, sign); CHECK_EQ(0, sign);
CHECK_EQ(0, strcmp("4128420500802942", buffer.begin())); CHECK_EQ(0, strcmp("4128420500802942", buffer.begin()));
CHECK_EQ(-8, point); CHECK_EQ(-8, point);
...@@ -258,8 +259,7 @@ TEST(DtoaVariousDoubles) { ...@@ -258,8 +259,7 @@ TEST(DtoaVariousDoubles) {
CHECK_EQ(-236, point); CHECK_EQ(-236, point);
} }
TEST_F(DtoaTest, DtoaGayShortest) {
TEST(DtoaGayShortest) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
base::Vector<char> buffer(buffer_container, kBufferSize); base::Vector<char> buffer(buffer_container, kBufferSize);
int sign; int sign;
...@@ -278,8 +278,7 @@ TEST(DtoaGayShortest) { ...@@ -278,8 +278,7 @@ TEST(DtoaGayShortest) {
} }
} }
TEST_F(DtoaTest, DtoaGayFixed) {
TEST(DtoaGayFixed) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
base::Vector<char> buffer(buffer_container, kBufferSize); base::Vector<char> buffer(buffer_container, kBufferSize);
int sign; int sign;
...@@ -301,8 +300,7 @@ TEST(DtoaGayFixed) { ...@@ -301,8 +300,7 @@ TEST(DtoaGayFixed) {
} }
} }
TEST_F(DtoaTest, DtoaGayPrecision) {
TEST(DtoaGayPrecision) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
base::Vector<char> buffer(buffer_container, kBufferSize); base::Vector<char> buffer(buffer_container, kBufferSize);
int sign; int sign;
...@@ -315,8 +313,8 @@ TEST(DtoaGayPrecision) { ...@@ -315,8 +313,8 @@ TEST(DtoaGayPrecision) {
const PrecomputedPrecision current_test = precomputed[i]; const PrecomputedPrecision current_test = precomputed[i];
double v = current_test.v; double v = current_test.v;
int number_digits = current_test.number_digits; int number_digits = current_test.number_digits;
DoubleToAscii(v, DTOA_PRECISION, number_digits, DoubleToAscii(v, DTOA_PRECISION, number_digits, buffer, &sign, &length,
buffer, &sign, &length, &point); &point);
CHECK_EQ(0, sign); // All precomputed numbers are positive. CHECK_EQ(0, sign); // All precomputed numbers are positive.
CHECK_EQ(current_test.decimal_point, point); CHECK_EQ(current_test.decimal_point, point);
CHECK_GE(number_digits, length); CHECK_GE(number_digits, length);
......
...@@ -25,18 +25,22 @@ ...@@ -25,18 +25,22 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "src/base/numbers/fast-dtoa.h"
#include <stdlib.h> #include <stdlib.h>
#include "src/base/numbers/diy-fp.h" #include "src/base/numbers/diy-fp.h"
#include "src/base/numbers/double.h" #include "src/base/numbers/double.h"
#include "src/base/numbers/fast-dtoa.h"
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/cctest.h" #include "test/unittests/gay-precision.h"
#include "test/cctest/gay-precision.h" #include "test/unittests/gay-shortest.h"
#include "test/cctest/gay-shortest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
using FastDtoaTest = ::testing::Test;
namespace base { namespace base {
namespace test_fast_dtoa { namespace test_fast_dtoa {
...@@ -50,7 +54,7 @@ static void TrimRepresentation(char* representation) { ...@@ -50,7 +54,7 @@ static void TrimRepresentation(char* representation) {
representation[len] = '\0'; representation[len] = '\0';
} }
TEST(FastDtoaShortestVariousDoubles) { TEST_F(FastDtoaTest, FastDtoaShortestVariousDoubles) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
int length; int length;
...@@ -58,45 +62,43 @@ TEST(FastDtoaShortestVariousDoubles) { ...@@ -58,45 +62,43 @@ TEST(FastDtoaShortestVariousDoubles) {
int status; int status;
double min_double = 5e-324; double min_double = 5e-324;
status = FastDtoa(min_double, FAST_DTOA_SHORTEST, 0, status = FastDtoa(min_double, FAST_DTOA_SHORTEST, 0, buffer, &length, &point);
buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("5", buffer.begin())); CHECK_EQ(0, strcmp("5", buffer.begin()));
CHECK_EQ(-323, point); CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308; double max_double = 1.7976931348623157e308;
status = FastDtoa(max_double, FAST_DTOA_SHORTEST, 0, status = FastDtoa(max_double, FAST_DTOA_SHORTEST, 0, buffer, &length, &point);
buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("17976931348623157", buffer.begin())); CHECK_EQ(0, strcmp("17976931348623157", buffer.begin()));
CHECK_EQ(309, point); CHECK_EQ(309, point);
status = FastDtoa(4294967272.0, FAST_DTOA_SHORTEST, 0, status =
buffer, &length, &point); FastDtoa(4294967272.0, FAST_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("4294967272", buffer.begin())); CHECK_EQ(0, strcmp("4294967272", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
status = FastDtoa(4.1855804968213567e298, FAST_DTOA_SHORTEST, 0, status = FastDtoa(4.1855804968213567e298, FAST_DTOA_SHORTEST, 0, buffer,
buffer, &length, &point); &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("4185580496821357", buffer.begin())); CHECK_EQ(0, strcmp("4185580496821357", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
status = FastDtoa(5.5626846462680035e-309, FAST_DTOA_SHORTEST, 0, status = FastDtoa(5.5626846462680035e-309, FAST_DTOA_SHORTEST, 0, buffer,
buffer, &length, &point); &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("5562684646268003", buffer.begin())); CHECK_EQ(0, strcmp("5562684646268003", buffer.begin()));
CHECK_EQ(-308, point); CHECK_EQ(-308, point);
status = FastDtoa(2147483648.0, FAST_DTOA_SHORTEST, 0, status =
buffer, &length, &point); FastDtoa(2147483648.0, FAST_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("2147483648", buffer.begin())); CHECK_EQ(0, strcmp("2147483648", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
status = FastDtoa(3.5844466002796428e+298, FAST_DTOA_SHORTEST, 0, status = FastDtoa(3.5844466002796428e+298, FAST_DTOA_SHORTEST, 0, buffer,
buffer, &length, &point); &length, &point);
if (status) { // Not all FastDtoa variants manage to compute this number. if (status) { // Not all FastDtoa variants manage to compute this number.
CHECK_EQ(0, strcmp("35844466002796428", buffer.begin())); CHECK_EQ(0, strcmp("35844466002796428", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
...@@ -119,8 +121,7 @@ TEST(FastDtoaShortestVariousDoubles) { ...@@ -119,8 +121,7 @@ TEST(FastDtoaShortestVariousDoubles) {
} }
} }
TEST_F(FastDtoaTest, FastDtoaPrecisionVariousDoubles) {
TEST(FastDtoaPrecisionVariousDoubles) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
int length; int length;
...@@ -143,21 +144,21 @@ TEST(FastDtoaPrecisionVariousDoubles) { ...@@ -143,21 +144,21 @@ TEST(FastDtoaPrecisionVariousDoubles) {
} }
double min_double = 5e-324; double min_double = 5e-324;
status = FastDtoa(min_double, FAST_DTOA_PRECISION, 5, status =
buffer, &length, &point); FastDtoa(min_double, FAST_DTOA_PRECISION, 5, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("49407", buffer.begin())); CHECK_EQ(0, strcmp("49407", buffer.begin()));
CHECK_EQ(-323, point); CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308; double max_double = 1.7976931348623157e308;
status = FastDtoa(max_double, FAST_DTOA_PRECISION, 7, status =
buffer, &length, &point); FastDtoa(max_double, FAST_DTOA_PRECISION, 7, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("1797693", buffer.begin())); CHECK_EQ(0, strcmp("1797693", buffer.begin()));
CHECK_EQ(309, point); CHECK_EQ(309, point);
status = FastDtoa(4294967272.0, FAST_DTOA_PRECISION, 14, status =
buffer, &length, &point); FastDtoa(4294967272.0, FAST_DTOA_PRECISION, 14, buffer, &length, &point);
if (status) { if (status) {
CHECK_GE(14, length); CHECK_GE(14, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
...@@ -165,26 +166,26 @@ TEST(FastDtoaPrecisionVariousDoubles) { ...@@ -165,26 +166,26 @@ TEST(FastDtoaPrecisionVariousDoubles) {
CHECK_EQ(10, point); CHECK_EQ(10, point);
} }
status = FastDtoa(4.1855804968213567e298, FAST_DTOA_PRECISION, 17, status = FastDtoa(4.1855804968213567e298, FAST_DTOA_PRECISION, 17, buffer,
buffer, &length, &point); &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("41855804968213567", buffer.begin())); CHECK_EQ(0, strcmp("41855804968213567", buffer.begin()));
CHECK_EQ(299, point); CHECK_EQ(299, point);
status = FastDtoa(5.5626846462680035e-309, FAST_DTOA_PRECISION, 1, status = FastDtoa(5.5626846462680035e-309, FAST_DTOA_PRECISION, 1, buffer,
buffer, &length, &point); &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("6", buffer.begin())); CHECK_EQ(0, strcmp("6", buffer.begin()));
CHECK_EQ(-308, point); CHECK_EQ(-308, point);
status = FastDtoa(2147483648.0, FAST_DTOA_PRECISION, 5, status =
buffer, &length, &point); FastDtoa(2147483648.0, FAST_DTOA_PRECISION, 5, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, strcmp("21475", buffer.begin())); CHECK_EQ(0, strcmp("21475", buffer.begin()));
CHECK_EQ(10, point); CHECK_EQ(10, point);
status = FastDtoa(3.5844466002796428e+298, FAST_DTOA_PRECISION, 10, status = FastDtoa(3.5844466002796428e+298, FAST_DTOA_PRECISION, 10, buffer,
buffer, &length, &point); &length, &point);
CHECK(status); CHECK(status);
CHECK_GE(10, length); CHECK_GE(10, length);
TrimRepresentation(buffer.begin()); TrimRepresentation(buffer.begin());
...@@ -220,8 +221,7 @@ TEST(FastDtoaPrecisionVariousDoubles) { ...@@ -220,8 +221,7 @@ TEST(FastDtoaPrecisionVariousDoubles) {
CHECK_EQ(192, point); CHECK_EQ(192, point);
} }
TEST_F(FastDtoaTest, FastDtoaGayShortest) {
TEST(FastDtoaGayShortest) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
bool status; bool status;
...@@ -245,12 +245,11 @@ TEST(FastDtoaGayShortest) { ...@@ -245,12 +245,11 @@ TEST(FastDtoaGayShortest) {
CHECK_EQ(current_test.decimal_point, point); CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(0, strcmp(current_test.representation, buffer.begin())); CHECK_EQ(0, strcmp(current_test.representation, buffer.begin()));
} }
CHECK_GT(succeeded*1.0/total, 0.99); CHECK_GT(succeeded * 1.0 / total, 0.99);
CHECK(needed_max_length); CHECK(needed_max_length);
} }
TEST_F(FastDtoaTest, FastDtoaGayPrecision) {
TEST(FastDtoaGayPrecision) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
bool status; bool status;
...@@ -270,8 +269,8 @@ TEST(FastDtoaGayPrecision) { ...@@ -270,8 +269,8 @@ TEST(FastDtoaGayPrecision) {
int number_digits = current_test.number_digits; int number_digits = current_test.number_digits;
total++; total++;
if (number_digits <= 15) total_15++; if (number_digits <= 15) total_15++;
status = FastDtoa(v, FAST_DTOA_PRECISION, number_digits, status = FastDtoa(v, FAST_DTOA_PRECISION, number_digits, buffer, &length,
buffer, &length, &point); &point);
CHECK_GE(number_digits, length); CHECK_GE(number_digits, length);
if (!status) continue; if (!status) continue;
succeeded++; succeeded++;
...@@ -283,10 +282,10 @@ TEST(FastDtoaGayPrecision) { ...@@ -283,10 +282,10 @@ TEST(FastDtoaGayPrecision) {
// The precomputed numbers contain many entries with many requested // The precomputed numbers contain many entries with many requested
// digits. These have a high failure rate and we therefore expect a lower // digits. These have a high failure rate and we therefore expect a lower
// success rate than for the shortest representation. // success rate than for the shortest representation.
CHECK_GT(succeeded*1.0/total, 0.85); CHECK_GT(succeeded * 1.0 / total, 0.85);
// However with less than 15 digits almost the algorithm should almost always // However with less than 15 digits almost the algorithm should almost always
// succeed. // succeed.
CHECK_GT(succeeded_15*1.0/total_15, 0.9999); CHECK_GT(succeeded_15 * 1.0 / total_15, 0.9999);
} }
} // namespace test_fast_dtoa } // namespace test_fast_dtoa
......
...@@ -25,21 +25,24 @@ ...@@ -25,21 +25,24 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "src/base/numbers/fixed-dtoa.h"
#include <stdlib.h> #include <stdlib.h>
#include "src/base/numbers/double.h" #include "src/base/numbers/double.h"
#include "src/base/numbers/fixed-dtoa.h"
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/cctest.h" #include "test/unittests/gay-fixed.h"
#include "test/cctest/gay-fixed.h" #include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
using FixedDtoaTest = ::testing::Test;
namespace base { namespace base {
static const int kBufferSize = 500; static const int kBufferSize = 500;
TEST(FastFixedVariousDoubles) { TEST_F(FixedDtoaTest, FastFixedVariousDoubles) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
int length; int length;
...@@ -74,8 +77,8 @@ TEST(FastFixedVariousDoubles) { ...@@ -74,8 +77,8 @@ TEST(FastFixedVariousDoubles) {
CHECK_EQ(0, strcmp("999999999999999868928", buffer.begin())); CHECK_EQ(0, strcmp("999999999999999868928", buffer.begin()));
CHECK_EQ(21, point); CHECK_EQ(21, point);
CHECK(FastFixedDtoa(6.9999999999999989514240000e+21, 5, buffer, CHECK(FastFixedDtoa(6.9999999999999989514240000e+21, 5, buffer, &length,
&length, &point)); &point));
CHECK_EQ(0, strcmp("6999999999999998951424", buffer.begin())); CHECK_EQ(0, strcmp("6999999999999998951424", buffer.begin()));
CHECK_EQ(22, point); CHECK_EQ(22, point);
...@@ -467,29 +470,27 @@ TEST(FastFixedVariousDoubles) { ...@@ -467,29 +470,27 @@ TEST(FastFixedVariousDoubles) {
CHECK_EQ(0, strcmp("1", buffer.begin())); CHECK_EQ(0, strcmp("1", buffer.begin()));
CHECK_EQ(-19, point); CHECK_EQ(-19, point);
CHECK(FastFixedDtoa(9.1193616301674545152000000e+19, 0, CHECK(FastFixedDtoa(9.1193616301674545152000000e+19, 0, buffer, &length,
buffer, &length, &point)); &point));
CHECK_EQ(0, strcmp("91193616301674545152", buffer.begin())); CHECK_EQ(0, strcmp("91193616301674545152", buffer.begin()));
CHECK_EQ(20, point); CHECK_EQ(20, point);
CHECK(FastFixedDtoa(4.8184662102767651659096515e-04, 19, CHECK(FastFixedDtoa(4.8184662102767651659096515e-04, 19, buffer, &length,
buffer, &length, &point)); &point));
CHECK_EQ(0, strcmp("4818466210276765", buffer.begin())); CHECK_EQ(0, strcmp("4818466210276765", buffer.begin()));
CHECK_EQ(-3, point); CHECK_EQ(-3, point);
CHECK(FastFixedDtoa(1.9023164229540652612705182e-23, 8, CHECK(FastFixedDtoa(1.9023164229540652612705182e-23, 8, buffer, &length,
buffer, &length, &point)); &point));
CHECK_EQ(0, strcmp("", buffer.begin())); CHECK_EQ(0, strcmp("", buffer.begin()));
CHECK_EQ(-8, point); CHECK_EQ(-8, point);
CHECK(FastFixedDtoa(1000000000000000128.0, 0, CHECK(FastFixedDtoa(1000000000000000128.0, 0, buffer, &length, &point));
buffer, &length, &point));
CHECK_EQ(0, strcmp("1000000000000000128", buffer.begin())); CHECK_EQ(0, strcmp("1000000000000000128", buffer.begin()));
CHECK_EQ(19, point); CHECK_EQ(19, point);
} }
TEST_F(FixedDtoaTest, FastFixedDtoaGayFixed) {
TEST(FastFixedDtoaGayFixed) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
bool status; bool status;
...@@ -502,8 +503,7 @@ TEST(FastFixedDtoaGayFixed) { ...@@ -502,8 +503,7 @@ TEST(FastFixedDtoaGayFixed) {
const PrecomputedFixed current_test = precomputed[i]; const PrecomputedFixed current_test = precomputed[i];
double v = current_test.v; double v = current_test.v;
int number_digits = current_test.number_digits; int number_digits = current_test.number_digits;
status = FastFixedDtoa(v, number_digits, status = FastFixedDtoa(v, number_digits, buffer, &length, &point);
buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(current_test.decimal_point, point); CHECK_EQ(current_test.decimal_point, point);
CHECK_GE(number_digits, length - point); CHECK_GE(number_digits, length - point);
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/gay-fixed.h" #include "test/unittests/gay-fixed.h"
namespace v8 { namespace v8 {
namespace base { namespace base {
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/gay-precision.h" #include "test/unittests/gay-precision.h"
namespace v8 { namespace v8 {
namespace base { namespace base {
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/gay-shortest.h" #include "test/unittests/gay-shortest.h"
namespace v8 { namespace v8 {
namespace base { namespace base {
...@@ -223,6 +223,8 @@ ...@@ -223,6 +223,8 @@
'LogMapsTest.*': [SKIP], 'LogMapsTest.*': [SKIP],
'LogMapsCodeTest.LogMapsDetailsCode': [SKIP], 'LogMapsCodeTest.LogMapsDetailsCode': [SKIP],
'LogFunctionEventsTest.LogFunctionEvents': [SKIP], 'LogFunctionEventsTest.LogFunctionEvents': [SKIP],
'BignumDtoaTest.*': [SKIP],
'DtoaTest.*': [SKIP],
}], # variant == no_wasm_traps }], # variant == no_wasm_traps
############################################################################## ##############################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment