Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: test/cctest/test-strtod.cc

Issue 3584015: Implement fast case for strtod. (Closed)
Patch Set: Address comments Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/SConscript ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-strtod.cc
diff --git a/test/cctest/test-strtod.cc b/test/cctest/test-strtod.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c90bef78e1c94baf1534c0b9d4824358c2471f21
--- /dev/null
+++ b/test/cctest/test-strtod.cc
@@ -0,0 +1,155 @@
+// Copyright 2006-2008 the V8 project authors. All rights reserved.
+
+#include <stdlib.h>
+
+#include "v8.h"
+
+#include "platform.h"
+#include "cctest.h"
+#include "strtod.h"
+
+using namespace v8::internal;
+
+static const int kBufferSize = 100;
+
+
+TEST(Strtod) {
+ char buffer[kBufferSize];
+ Vector<char> vector;
+
+ strncpy(buffer, "0", kBufferSize);
+ vector = Vector<char>(buffer, strlen(buffer));
+
+ CHECK_EQ(0.0, Strtod(vector, 1));
+ CHECK_EQ(0.0, Strtod(vector, 2));
+ CHECK_EQ(0.0, Strtod(vector, -2));
+ CHECK_EQ(0.0, Strtod(vector, -999));
+ CHECK_EQ(0.0, Strtod(vector, +999));
+
+ strncpy(buffer, "1", kBufferSize);
+ vector = Vector<char>(buffer, strlen(buffer));
+ CHECK_EQ(1.0, Strtod(vector, 0));
+ CHECK_EQ(10.0, Strtod(vector, 1));
+ CHECK_EQ(100.0, Strtod(vector, 2));
+ CHECK_EQ(1e20, Strtod(vector, 20));
+ CHECK_EQ(1e22, Strtod(vector, 22));
+ CHECK_EQ(1e23, Strtod(vector, 23));
+ CHECK_EQ(1e35, Strtod(vector, 35));
+ CHECK_EQ(1e36, Strtod(vector, 36));
+ CHECK_EQ(1e37, Strtod(vector, 37));
+ CHECK_EQ(1e-1, Strtod(vector, -1));
+ CHECK_EQ(1e-2, Strtod(vector, -2));
+ CHECK_EQ(1e-5, Strtod(vector, -5));
+ CHECK_EQ(1e-20, Strtod(vector, -20));
+ CHECK_EQ(1e-22, Strtod(vector, -22));
+ CHECK_EQ(1e-23, Strtod(vector, -23));
+ CHECK_EQ(1e-25, Strtod(vector, -25));
+ CHECK_EQ(1e-39, Strtod(vector, -39));
+
+ strncpy(buffer, "2", kBufferSize);
+ vector = Vector<char>(buffer, strlen(buffer));
+ CHECK_EQ(2.0, Strtod(vector, 0));
+ CHECK_EQ(20.0, Strtod(vector, 1));
+ CHECK_EQ(200.0, Strtod(vector, 2));
+ CHECK_EQ(2e20, Strtod(vector, 20));
+ CHECK_EQ(2e22, Strtod(vector, 22));
+ CHECK_EQ(2e23, Strtod(vector, 23));
+ CHECK_EQ(2e35, Strtod(vector, 35));
+ CHECK_EQ(2e36, Strtod(vector, 36));
+ CHECK_EQ(2e37, Strtod(vector, 37));
+ CHECK_EQ(2e-1, Strtod(vector, -1));
+ CHECK_EQ(2e-2, Strtod(vector, -2));
+ CHECK_EQ(2e-5, Strtod(vector, -5));
+ CHECK_EQ(2e-20, Strtod(vector, -20));
+ CHECK_EQ(2e-22, Strtod(vector, -22));
+ CHECK_EQ(2e-23, Strtod(vector, -23));
+ CHECK_EQ(2e-25, Strtod(vector, -25));
+ CHECK_EQ(2e-39, Strtod(vector, -39));
+
+ strncpy(buffer, "9", kBufferSize);
+ vector = Vector<char>(buffer, strlen(buffer));
+ CHECK_EQ(9.0, Strtod(vector, 0));
+ CHECK_EQ(90.0, Strtod(vector, 1));
+ CHECK_EQ(900.0, Strtod(vector, 2));
+ CHECK_EQ(9e20, Strtod(vector, 20));
+ CHECK_EQ(9e22, Strtod(vector, 22));
+ CHECK_EQ(9e23, Strtod(vector, 23));
+ CHECK_EQ(9e35, Strtod(vector, 35));
+ CHECK_EQ(9e36, Strtod(vector, 36));
+ CHECK_EQ(9e37, Strtod(vector, 37));
+ CHECK_EQ(9e-1, Strtod(vector, -1));
+ CHECK_EQ(9e-2, Strtod(vector, -2));
+ CHECK_EQ(9e-5, Strtod(vector, -5));
+ CHECK_EQ(9e-20, Strtod(vector, -20));
+ CHECK_EQ(9e-22, Strtod(vector, -22));
+ CHECK_EQ(9e-23, Strtod(vector, -23));
+ CHECK_EQ(9e-25, Strtod(vector, -25));
+ CHECK_EQ(9e-39, Strtod(vector, -39));
+
+ strncpy(buffer, "12345", kBufferSize);
+ vector = Vector<char>(buffer, strlen(buffer));
+ CHECK_EQ(12345.0, Strtod(vector, 0));
+ CHECK_EQ(123450.0, Strtod(vector, 1));
+ CHECK_EQ(1234500.0, Strtod(vector, 2));
+ CHECK_EQ(12345e20, Strtod(vector, 20));
+ CHECK_EQ(12345e22, Strtod(vector, 22));
+ CHECK_EQ(12345e23, Strtod(vector, 23));
+ CHECK_EQ(12345e30, Strtod(vector, 30));
+ CHECK_EQ(12345e31, Strtod(vector, 31));
+ CHECK_EQ(12345e32, Strtod(vector, 32));
+ CHECK_EQ(12345e35, Strtod(vector, 35));
+ CHECK_EQ(12345e36, Strtod(vector, 36));
+ CHECK_EQ(12345e37, Strtod(vector, 37));
+ CHECK_EQ(12345e-1, Strtod(vector, -1));
+ CHECK_EQ(12345e-2, Strtod(vector, -2));
+ CHECK_EQ(12345e-5, Strtod(vector, -5));
+ CHECK_EQ(12345e-20, Strtod(vector, -20));
+ CHECK_EQ(12345e-22, Strtod(vector, -22));
+ CHECK_EQ(12345e-23, Strtod(vector, -23));
+ CHECK_EQ(12345e-25, Strtod(vector, -25));
+ CHECK_EQ(12345e-39, Strtod(vector, -39));
+
+ strncpy(buffer, "12345678901234", kBufferSize);
+ vector = Vector<char>(buffer, strlen(buffer));
+ CHECK_EQ(12345678901234.0, Strtod(vector, 0));
+ CHECK_EQ(123456789012340.0, Strtod(vector, 1));
+ CHECK_EQ(1234567890123400.0, Strtod(vector, 2));
+ CHECK_EQ(12345678901234e20, Strtod(vector, 20));
+ CHECK_EQ(12345678901234e22, Strtod(vector, 22));
+ CHECK_EQ(12345678901234e23, Strtod(vector, 23));
+ CHECK_EQ(12345678901234e30, Strtod(vector, 30));
+ CHECK_EQ(12345678901234e31, Strtod(vector, 31));
+ CHECK_EQ(12345678901234e32, Strtod(vector, 32));
+ CHECK_EQ(12345678901234e35, Strtod(vector, 35));
+ CHECK_EQ(12345678901234e36, Strtod(vector, 36));
+ CHECK_EQ(12345678901234e37, Strtod(vector, 37));
+ CHECK_EQ(12345678901234e-1, Strtod(vector, -1));
+ CHECK_EQ(12345678901234e-2, Strtod(vector, -2));
+ CHECK_EQ(12345678901234e-5, Strtod(vector, -5));
+ CHECK_EQ(12345678901234e-20, Strtod(vector, -20));
+ CHECK_EQ(12345678901234e-22, Strtod(vector, -22));
+ CHECK_EQ(12345678901234e-23, Strtod(vector, -23));
+ CHECK_EQ(12345678901234e-25, Strtod(vector, -25));
+ CHECK_EQ(12345678901234e-39, Strtod(vector, -39));
+
+ strncpy(buffer, "123456789012345", kBufferSize);
+ vector = Vector<char>(buffer, strlen(buffer));
+ CHECK_EQ(123456789012345.0, Strtod(vector, 0));
+ CHECK_EQ(1234567890123450.0, Strtod(vector, 1));
+ CHECK_EQ(12345678901234500.0, Strtod(vector, 2));
+ CHECK_EQ(123456789012345e20, Strtod(vector, 20));
+ CHECK_EQ(123456789012345e22, Strtod(vector, 22));
+ CHECK_EQ(123456789012345e23, Strtod(vector, 23));
+ CHECK_EQ(123456789012345e35, Strtod(vector, 35));
+ CHECK_EQ(123456789012345e36, Strtod(vector, 36));
+ CHECK_EQ(123456789012345e37, Strtod(vector, 37));
+ CHECK_EQ(123456789012345e39, Strtod(vector, 39));
+ CHECK_EQ(123456789012345e-1, Strtod(vector, -1));
+ CHECK_EQ(123456789012345e-2, Strtod(vector, -2));
+ CHECK_EQ(123456789012345e-5, Strtod(vector, -5));
+ CHECK_EQ(123456789012345e-20, Strtod(vector, -20));
+ CHECK_EQ(123456789012345e-22, Strtod(vector, -22));
+ CHECK_EQ(123456789012345e-23, Strtod(vector, -23));
+ CHECK_EQ(123456789012345e-25, Strtod(vector, -25));
+ CHECK_EQ(123456789012345e-39, Strtod(vector, -39));
+}
« no previous file with comments | « test/cctest/SConscript ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698