char* decimal_rep;
bool used_gay_dtoa = false;
- char fast_dtoa_buffer[kFastDtoaMaximalLength + 1];
+ const int kFastDtoaBufferCapacity = kFastDtoaMaximalLength + 1;
+ char fast_dtoa_buffer[kFastDtoaBufferCapacity];
int length;
- if (FastDtoa(v, fast_dtoa_buffer, &sign, &length, &decimal_point)) {
+ if (FastDtoa(v, Vector<char>(fast_dtoa_buffer, kFastDtoaBufferCapacity),
+ &sign, &length, &decimal_point)) {
decimal_rep = fast_dtoa_buffer;
} else {
decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL);
// Output: returns true if the buffer is guaranteed to contain the closest
// representable number to the input.
// Modifies the generated digits in the buffer to approach (round towards) w.
-bool RoundWeed(char* buffer,
+bool RoundWeed(Vector<char> buffer,
int length,
uint64_t distance_too_high_w,
uint64_t unsafe_interval,
bool DigitGen(DiyFp low,
DiyFp w,
DiyFp high,
- char* buffer,
+ Vector<char> buffer,
int* length,
int* kappa) {
ASSERT(low.e() == w.e() && w.e() == high.e());
// The last digit will be closest to the actual v. That is, even if several
// digits might correctly yield 'v' when read again, the closest will be
// computed.
-bool grisu3(double v, char* buffer, int* length, int* decimal_exponent) {
+bool grisu3(double v, Vector<char> buffer, int* length, int* decimal_exponent) {
DiyFp w = Double(v).AsNormalizedDiyFp();
// boundary_minus and boundary_plus are the boundaries between v and its
// closest floating-point neighbors. Any number strictly between
}
-bool FastDtoa(double v, char* buffer, int* sign, int* length, int* point) {
+bool FastDtoa(double v,
+ Vector<char> buffer,
+ int* sign,
+ int* length,
+ int* point) {
ASSERT(v != 0);
ASSERT(!Double(v).IsSpecial());
static const int kBufferSize = 100;
TEST(FastDtoaVariousDoubles) {
- char buffer[kBufferSize];
+ char buffer_container[kBufferSize];
+ Vector<char> buffer(buffer_container, kBufferSize);
int sign;
int length;
int point;
status = FastDtoa(min_double, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("5", buffer);
+ CHECK_EQ("5", buffer.start());
CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308;
status = FastDtoa(max_double, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("17976931348623157", buffer);
+ CHECK_EQ("17976931348623157", buffer.start());
CHECK_EQ(309, point);
status = FastDtoa(4294967272.0, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("4294967272", buffer);
+ CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
status = FastDtoa(4.1855804968213567e298, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("4185580496821357", buffer);
+ CHECK_EQ("4185580496821357", buffer.start());
CHECK_EQ(299, point);
status = FastDtoa(5.5626846462680035e-309, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("5562684646268003", buffer);
+ CHECK_EQ("5562684646268003", buffer.start());
CHECK_EQ(-308, point);
status = FastDtoa(2147483648.0, buffer, &sign, &length, &point);
CHECK(status);
CHECK_EQ(0, sign);
- CHECK_EQ("2147483648", buffer);
+ CHECK_EQ("2147483648", buffer.start());
CHECK_EQ(10, point);
status = FastDtoa(3.5844466002796428e+298, buffer, &sign, &length, &point);
if (status) { // Not all FastDtoa variants manage to compute this number.
- CHECK_EQ("35844466002796428", buffer);
+ CHECK_EQ("35844466002796428", buffer.start());
CHECK_EQ(0, sign);
CHECK_EQ(299, point);
}
status = FastDtoa(v, buffer, &sign, &length, &point);
if (status) {
CHECK_EQ(0, sign);
- CHECK_EQ("22250738585072014", buffer);
+ CHECK_EQ("22250738585072014", buffer.start());
CHECK_EQ(-307, point);
}
status = FastDtoa(v, buffer, &sign, &length, &point);
if (status) {
CHECK_EQ(0, sign);
- CHECK_EQ("2225073858507201", buffer);
+ CHECK_EQ("2225073858507201", buffer.start());
CHECK_EQ(-307, point);
}
}
TEST(FastDtoaGayShortest) {
- char buffer[kBufferSize];
+ char buffer_container[kBufferSize];
+ Vector<char> buffer(buffer_container, kBufferSize);
bool status;
int sign;
int length;
succeeded++;
CHECK_EQ(0, sign); // All precomputed numbers are positive.
CHECK_EQ(current_test.decimal_point, point);
- CHECK_EQ(current_test.representation, buffer);
+ CHECK_EQ(current_test.representation, buffer.start());
}
CHECK_GT(succeeded*1.0/total, 0.99);
CHECK(needed_max_length);