double-conversion / test / cctest / test-bignum-dtoa.cc

Diff from to

test/cctest/test-bignum-dtoa.cc

 #include "bignum-dtoa.h"
 
 #include "cctest.h"
-#include "double.h"
 #include "gay-fixed.h"
 #include "gay-precision.h"
 #include "gay-shortest.h"
+#include "gay-shortest-single.h"
+#include "ieee.h"
 #include "utils.h"
 
 using namespace double_conversion;
 }
 
 
+TEST(BignumDtoaShortestVariousFloats) {
+  char buffer_container[kBufferSize];
+  Vector<char> buffer(buffer_container, kBufferSize);
+  int length;
+  int point;
+  int status;
+
+  float min_float = 1e-45f;
+  BignumDtoa(min_float, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
+             buffer, &length, &point);
+  CHECK_EQ("1", buffer.start());
+  CHECK_EQ(-44, point);
+
+
+  float max_float = 3.4028234e38f;
+  BignumDtoa(max_float, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
+             buffer, &length, &point);
+  CHECK_EQ("34028235", buffer.start());
+  CHECK_EQ(39, point);
+
+  BignumDtoa(4294967272.0f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
+             buffer, &length, &point);
+  CHECK_EQ("42949673", buffer.start());
+  CHECK_EQ(10, point);
+
+  BignumDtoa(3.32306998946228968226e+35f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
+             buffer, &length, &point);
+  CHECK_EQ("332307", buffer.start());
+  CHECK_EQ(36, point);
+
+  BignumDtoa(1.23405349260765015351e-41f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
+             buffer, &length, &point);
+  CHECK_EQ("12341", buffer.start());
+  CHECK_EQ(-40, point);
+
+  BignumDtoa(3.3554432e7, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
+             buffer, &length, &point);
+  CHECK_EQ("33554432", buffer.start());
+  CHECK_EQ(8, point);
+
+  BignumDtoa(3.26494756798464e14f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
+             buffer, &length, &point);
+  CHECK_EQ("32649476", buffer.start());
+  CHECK_EQ(15, point);
+
+  BignumDtoa(3.91132223637771935344e37f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
+             buffer, &length, &point);
+  CHECK_EQ("39113222", buffer.start());
+  CHECK_EQ(38, point);
+
+  uint32_t smallest_normal32 = 0x00800000;
+  double v = Single(smallest_normal32).value();
+  BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
+  CHECK_EQ("11754944", buffer.start());
+  CHECK_EQ(-37, point);
+
+  uint32_t largest_denormal32 = 0x007FFFFF;
+  v = Single(largest_denormal32).value();
+  BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
+  CHECK_EQ("11754942", buffer.start());
+  CHECK_EQ(-37, point);
+}
+
+
 TEST(BignumDtoaGayShortest) {
   char buffer_container[kBufferSize];
   Vector<char> buffer(buffer_container, kBufferSize);
 }
 
 
+TEST(BignumDtoaGayShortestSingle) {
+  char buffer_container[kBufferSize];
+  Vector<char> buffer(buffer_container, kBufferSize);
+  int length;
+  int point;
+
+  Vector<const PrecomputedShortestSingle> precomputed =
+      PrecomputedShortestSingleRepresentations();
+  for (int i = 0; i < precomputed.length(); ++i) {
+    const PrecomputedShortestSingle current_test = precomputed[i];
+    float v = current_test.v;
+    BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
+    CHECK_EQ(current_test.decimal_point, point);
+    CHECK_EQ(current_test.representation, buffer.start());
+  }
+}
+
+
 TEST(BignumDtoaGayFixed) {
   char buffer_container[kBufferSize];
   Vector<char> buffer(buffer_container, kBufferSize);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.