Commit 7fc98eb1 authored by floitschV8@gmail.com's avatar floitschV8@gmail.com

Dtoa for fixed notation.

Review URL: http://codereview.chromium.org/1956005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4596 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f1c5cdbb
...@@ -58,6 +58,7 @@ SOURCES = { ...@@ -58,6 +58,7 @@ SOURCES = {
debug.cc debug.cc
disassembler.cc disassembler.cc
diy-fp.cc diy-fp.cc
dtoa.cc
execution.cc execution.cc
factory.cc factory.cc
flags.cc flags.cc
...@@ -68,6 +69,7 @@ SOURCES = { ...@@ -68,6 +69,7 @@ SOURCES = {
func-name-inferrer.cc func-name-inferrer.cc
global-handles.cc global-handles.cc
fast-dtoa.cc fast-dtoa.cc
fixed-dtoa.cc
handles.cc handles.cc
hashmap.cc hashmap.cc
heap-profiler.cc heap-profiler.cc
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
#include "v8.h" #include "v8.h"
#include "conversions-inl.h" #include "conversions-inl.h"
#include "dtoa.h"
#include "factory.h" #include "factory.h"
#include "fast-dtoa.h"
#include "scanner.h" #include "scanner.h"
namespace v8 { namespace v8 {
...@@ -766,15 +766,16 @@ const char* DoubleToCString(double v, Vector<char> buffer) { ...@@ -766,15 +766,16 @@ const char* DoubleToCString(double v, Vector<char> buffer) {
default: { default: {
int decimal_point; int decimal_point;
int sign; int sign;
char* decimal_rep; char* decimal_rep;
bool used_gay_dtoa = false; bool used_gay_dtoa = false;
const int kFastDtoaBufferCapacity = kFastDtoaMaximalLength + 1; const int kV8DtoaBufferCapacity = kBase10MaximalLength + 1;
char fast_dtoa_buffer[kFastDtoaBufferCapacity]; char v8_dtoa_buffer[kV8DtoaBufferCapacity];
int length; int length;
if (FastDtoa(v, Vector<char>(fast_dtoa_buffer, kFastDtoaBufferCapacity),
&sign, &length, &decimal_point)) { if (DoubleToAscii(v, DTOA_SHORTEST, 0,
decimal_rep = fast_dtoa_buffer; Vector<char>(v8_dtoa_buffer, kV8DtoaBufferCapacity),
&sign, &length, &decimal_point)) {
decimal_rep = v8_dtoa_buffer;
} else { } else {
decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL); decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL);
used_gay_dtoa = true; used_gay_dtoa = true;
...@@ -842,7 +843,11 @@ const char* IntToCString(int n, Vector<char> buffer) { ...@@ -842,7 +843,11 @@ const char* IntToCString(int n, Vector<char> buffer) {
char* DoubleToFixedCString(double value, int f) { char* DoubleToFixedCString(double value, int f) {
const int kMaxDigitsBeforePoint = 20;
const double kFirstNonFixed = 1e21;
const int kMaxDigitsAfterPoint = 20;
ASSERT(f >= 0); ASSERT(f >= 0);
ASSERT(f <= kMaxDigitsAfterPoint);
bool negative = false; bool negative = false;
double abs_value = value; double abs_value = value;
...@@ -851,7 +856,9 @@ char* DoubleToFixedCString(double value, int f) { ...@@ -851,7 +856,9 @@ char* DoubleToFixedCString(double value, int f) {
negative = true; negative = true;
} }
if (abs_value >= 1e21) { // If abs_value has more than kMaxDigitsBeforePoint digits before the point
// use the non-fixed conversion routine.
if (abs_value >= kFirstNonFixed) {
char arr[100]; char arr[100];
Vector<char> buffer(arr, ARRAY_SIZE(arr)); Vector<char> buffer(arr, ARRAY_SIZE(arr));
return StrDup(DoubleToCString(value, buffer)); return StrDup(DoubleToCString(value, buffer));
...@@ -860,8 +867,16 @@ char* DoubleToFixedCString(double value, int f) { ...@@ -860,8 +867,16 @@ char* DoubleToFixedCString(double value, int f) {
// Find a sufficiently precise decimal representation of n. // Find a sufficiently precise decimal representation of n.
int decimal_point; int decimal_point;
int sign; int sign;
char* decimal_rep = dtoa(abs_value, 3, f, &decimal_point, &sign, NULL); // Add space for the '.' and the '\0' byte.
int decimal_rep_length = StrLength(decimal_rep); const int kDecimalRepCapacity =
kMaxDigitsBeforePoint + kMaxDigitsAfterPoint + 2;
char decimal_rep[kDecimalRepCapacity];
int decimal_rep_length;
bool status = DoubleToAscii(value, DTOA_FIXED, f,
Vector<char>(decimal_rep, kDecimalRepCapacity),
&sign, &decimal_rep_length, &decimal_point);
USE(status);
ASSERT(status);
// Create a representation that is padded with zeros if needed. // Create a representation that is padded with zeros if needed.
int zero_prefix_length = 0; int zero_prefix_length = 0;
...@@ -884,7 +899,6 @@ char* DoubleToFixedCString(double value, int f) { ...@@ -884,7 +899,6 @@ char* DoubleToFixedCString(double value, int f) {
rep_builder.AddString(decimal_rep); rep_builder.AddString(decimal_rep);
rep_builder.AddPadding('0', zero_postfix_length); rep_builder.AddPadding('0', zero_postfix_length);
char* rep = rep_builder.Finalize(); char* rep = rep_builder.Finalize();
freedtoa(decimal_rep);
// Create the result string by appending a minus and putting in a // Create the result string by appending a minus and putting in a
// decimal point if needed. // decimal point if needed.
......
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <math.h>
#include "v8.h"
#include "dtoa.h"
#include "double.h"
#include "fast-dtoa.h"
#include "fixed-dtoa.h"
namespace v8 {
namespace internal {
bool DoubleToAscii(double v, DtoaMode mode, int requested_digits,
Vector<char> buffer, int* sign, int* length, int* point) {
ASSERT(!Double(v).IsSpecial());
ASSERT(mode == DTOA_SHORTEST || requested_digits >= 0);
if (Double(v).Sign() < 0) {
*sign = 1;
v = -v;
} else {
*sign = 0;
}
if (v == 0) {
buffer[0] = '0';
buffer[1] = '\0';
*length = 1;
*point = 1;
return true;
}
if (mode == DTOA_PRECISION && requested_digits == 0) {
buffer[0] = '\0';
*length = 0;
return true;
}
switch (mode) {
case DTOA_SHORTEST:
return FastDtoa(v, buffer, length, point);
case DTOA_FIXED:
return FastFixedDtoa(v, requested_digits, buffer, length, point);
default:
break;
}
return false;
}
} } // namespace v8::internal
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_DTOA_H_
#define V8_DTOA_H_
namespace v8 {
namespace internal {
enum DtoaMode {
// 0.9999999999999999 becomes 0.1
DTOA_SHORTEST,
// Fixed number of digits after the decimal point.
// For instance fixed(0.1, 4) becomes 0.1000
// If the input number is big, the output will be big.
DTOA_FIXED,
// Fixed number of digits (independent of the decimal point).
DTOA_PRECISION
};
// The maximal length of digits a double can have in base 10.
// Note that DoubleToAscii null-terminates its input. So the given buffer should
// be at least kBase10MaximalLength + 1 characters long.
static const int kBase10MaximalLength = 17;
// Converts the given double 'v' to ascii.
// The result should be interpreted as buffer * 10^(point-length).
//
// The output depends on the given mode:
// - SHORTEST: produce the least amount of digits for which the internal
// identity requirement is still satisfied. If the digits are printed
// (together with the correct exponent) then reading this number will give
// 'v' again. The buffer will choose the representation that is closest to
// 'v'. If there are two at the same distance, than the one farther away
// from 0 is chosen (halfway cases - ending with 5 - are rounded up).
// In this mode the 'requested_digits' parameter is ignored.
// - FIXED: produces digits necessary to print a given number with
// 'requested_digits' digits after the decimal point. The produced digits
// might be too short in which case the caller has to fill the gaps with '0's.
// Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2.
// Halfway cases are rounded towards +/-Infinity (away from 0). The call
// toFixed(0.15, 2) thus returns buffer="2", point=0.
// The returned buffer may contain digits that would be truncated from the
// shortest representation of the input.
// - PRECISION: produces 'requested_digits' where the first digit is not '0'.
// Even though the length of produced digits usually equals
// 'requested_digits', the function is allowed to return fewer digits, in
// which case the caller has to fill the missing digits with '0's.
// Halfway cases are again rounded away from 0.
// 'DoubleToAscii' expects the given buffer to be big enough to hold all digits
// and a terminating null-character.
bool DoubleToAscii(double v, DtoaMode mode, int requested_digits,
Vector<char> buffer, int* sign, int* length, int* point);
} } // namespace v8::internal
#endif // V8_DTOA_H_
...@@ -314,7 +314,7 @@ static void BiggestPowerTen(uint32_t number, ...@@ -314,7 +314,7 @@ static void BiggestPowerTen(uint32_t number,
// w's fractional part is therefore 0x567890abcdef. // w's fractional part is therefore 0x567890abcdef.
// Printing w's integral part is easy (simply print 0x1234 in decimal). // Printing w's integral part is easy (simply print 0x1234 in decimal).
// In order to print its fraction we repeatedly multiply the fraction by 10 and // In order to print its fraction we repeatedly multiply the fraction by 10 and
// get each digit. Example the first digit after the comma would be computed by // get each digit. Example the first digit after the point would be computed by
// (0x567890abcdef * 10) >> 48. -> 3 // (0x567890abcdef * 10) >> 48. -> 3
// The whole thing becomes slightly more complicated because we want to stop // The whole thing becomes slightly more complicated because we want to stop
// once we have enough digits. That is, once the digits inside the buffer // once we have enough digits. That is, once the digits inside the buffer
...@@ -490,18 +490,11 @@ bool grisu3(double v, Vector<char> buffer, int* length, int* decimal_exponent) { ...@@ -490,18 +490,11 @@ bool grisu3(double v, Vector<char> buffer, int* length, int* decimal_exponent) {
bool FastDtoa(double v, bool FastDtoa(double v,
Vector<char> buffer, Vector<char> buffer,
int* sign,
int* length, int* length,
int* point) { int* point) {
ASSERT(v != 0); ASSERT(v > 0);
ASSERT(!Double(v).IsSpecial()); ASSERT(!Double(v).IsSpecial());
if (v < 0) {
v = -v;
*sign = 1;
} else {
*sign = 0;
}
int decimal_exponent; int decimal_exponent;
bool result = grisu3(v, buffer, length, &decimal_exponent); bool result = grisu3(v, buffer, length, &decimal_exponent);
*point = *length + decimal_exponent; *point = *length + decimal_exponent;
......
...@@ -36,7 +36,7 @@ namespace internal { ...@@ -36,7 +36,7 @@ namespace internal {
static const int kFastDtoaMaximalLength = 17; static const int kFastDtoaMaximalLength = 17;
// Provides a decimal representation of v. // Provides a decimal representation of v.
// v must not be (positive or negative) zero and it must not be Infinity or NaN. // v must be a strictly positive finite double.
// Returns true if it succeeds, otherwise the result can not be trusted. // Returns true if it succeeds, otherwise the result can not be trusted.
// There will be *length digits inside the buffer followed by a null terminator. // There will be *length digits inside the buffer followed by a null terminator.
// If the function returns true then // If the function returns true then
...@@ -50,7 +50,6 @@ static const int kFastDtoaMaximalLength = 17; ...@@ -50,7 +50,6 @@ static const int kFastDtoaMaximalLength = 17;
// otherwise. // otherwise.
bool FastDtoa(double d, bool FastDtoa(double d,
Vector<char> buffer, Vector<char> buffer,
int* sign,
int* length, int* length,
int* point); int* point);
......
This diff is collapsed.
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_FIXED_DTOA_H_
#define V8_FIXED_DTOA_H_
namespace v8 {
namespace internal {
// Produces digits necessary to print a given number with
// 'fractional_count' digits after the decimal point.
// The buffer must be big enough to hold the result plus one terminating null
// character.
//
// The produced digits might be too short in which case the caller has to fill
// the gaps with '0's.
// Example: FastFixedDtoa(0.001, 5, ...) is allowed to return buffer = "1", and
// decimal_point = -2.
// Halfway cases are rounded towards +/-Infinity (away from 0). The call
// FastFixedDtoa(0.15, 2, ...) thus returns buffer = "2", decimal_point = 0.
// The returned buffer may contain digits that would be truncated from the
// shortest representation of the input.
//
// This method only works for some parameters. If it can't handle the input it
// returns false. The output is null-terminated when the function succeeds.
bool FastFixedDtoa(double v, int fractional_count,
Vector<char> buffer, int* length, int* decimal_point);
} } // namespace v8::internal
#endif // V8_FIXED_DTOA_H_
...@@ -34,6 +34,7 @@ Import('context object_files') ...@@ -34,6 +34,7 @@ Import('context object_files')
SOURCES = { SOURCES = {
'all': [ 'all': [
'gay-fixed.cc',
'gay-shortest.cc', 'gay-shortest.cc',
'test-accessors.cc', 'test-accessors.cc',
'test-alloc.cc', 'test-alloc.cc',
...@@ -49,6 +50,7 @@ SOURCES = { ...@@ -49,6 +50,7 @@ SOURCES = {
'test-diy-fp.cc', 'test-diy-fp.cc',
'test-double.cc', 'test-double.cc',
'test-fast-dtoa.cc', 'test-fast-dtoa.cc',
'test-fixed-dtoa.cc',
'test-flags.cc', 'test-flags.cc',
'test-func-name-inference.cc', 'test-func-name-inference.cc',
'test-hashmap.cc', 'test-hashmap.cc',
......
This diff is collapsed.
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GAY_FIXED_H_
#define GAY_FIXED_H_
namespace v8 {
namespace internal {
struct PrecomputedFixed {
double v;
int number_digits;
const char* representation;
int decimal_point;
};
// Returns precomputed values of dtoa. The strings have been generated using
// Gay's dtoa in mode "fixed".
Vector<const PrecomputedFixed> PrecomputedFixedRepresentations();
} } // namespace v8::internal
#endif // GAY_FIXED_H_
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
static const GayShortest kShortestTestNumbers[] = { static const PrecomputedShortest kShortestTestNumbers[] = {
{1.3252057186783201350530603e-106, "13252057186783201", -105}, {1.3252057186783201350530603e-106, "13252057186783201", -105},
{1.6899223998841386493367055e-33, "16899223998841386", -32}, {1.6899223998841386493367055e-33, "16899223998841386", -32},
{1.0077972445720390730768089e+138, "1007797244572039", 139}, {1.0077972445720390730768089e+138, "1007797244572039", 139},
...@@ -100040,9 +100040,11 @@ static const GayShortest kShortestTestNumbers[] = { ...@@ -100040,9 +100040,11 @@ static const GayShortest kShortestTestNumbers[] = {
}; };
Vector<const GayShortest> PrecomputedShortestRepresentations() { Vector<const PrecomputedShortest> PrecomputedShortestRepresentations() {
int number_elements = sizeof(kShortestTestNumbers) / sizeof(GayShortest); int number_elements =
return Vector<const GayShortest>(kShortestTestNumbers, number_elements); sizeof(kShortestTestNumbers) / sizeof(PrecomputedShortest);
return Vector<const PrecomputedShortest>(kShortestTestNumbers,
number_elements);
} }
} } // namespace v8::internal } } // namespace v8::internal
...@@ -31,13 +31,13 @@ ...@@ -31,13 +31,13 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
struct GayShortest { struct PrecomputedShortest {
double v; double v;
const char* representation; const char* representation;
int decimal_point; int decimal_point;
}; };
Vector<const GayShortest> PrecomputedShortestRepresentations(); Vector<const PrecomputedShortest> PrecomputedShortestRepresentations();
} } // namespace v8::internal } } // namespace v8::internal
......
...@@ -18,70 +18,60 @@ static const int kBufferSize = 100; ...@@ -18,70 +18,60 @@ static const int kBufferSize = 100;
TEST(FastDtoaVariousDoubles) { TEST(FastDtoaVariousDoubles) {
char buffer_container[kBufferSize]; char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize); Vector<char> buffer(buffer_container, kBufferSize);
int sign;
int length; int length;
int point; int point;
int status; int status;
double min_double = 5e-324; double min_double = 5e-324;
status = FastDtoa(min_double, buffer, &sign, &length, &point); status = FastDtoa(min_double, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, sign);
CHECK_EQ("5", buffer.start()); CHECK_EQ("5", buffer.start());
CHECK_EQ(-323, point); CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308; double max_double = 1.7976931348623157e308;
status = FastDtoa(max_double, buffer, &sign, &length, &point); status = FastDtoa(max_double, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, sign);
CHECK_EQ("17976931348623157", buffer.start()); CHECK_EQ("17976931348623157", buffer.start());
CHECK_EQ(309, point); CHECK_EQ(309, point);
status = FastDtoa(4294967272.0, buffer, &sign, &length, &point); status = FastDtoa(4294967272.0, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, sign);
CHECK_EQ("4294967272", buffer.start()); CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point); CHECK_EQ(10, point);
status = FastDtoa(4.1855804968213567e298, buffer, &sign, &length, &point); status = FastDtoa(4.1855804968213567e298, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, sign);
CHECK_EQ("4185580496821357", buffer.start()); CHECK_EQ("4185580496821357", buffer.start());
CHECK_EQ(299, point); CHECK_EQ(299, point);
status = FastDtoa(5.5626846462680035e-309, buffer, &sign, &length, &point); status = FastDtoa(5.5626846462680035e-309, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, sign);
CHECK_EQ("5562684646268003", buffer.start()); CHECK_EQ("5562684646268003", buffer.start());
CHECK_EQ(-308, point); CHECK_EQ(-308, point);
status = FastDtoa(2147483648.0, buffer, &sign, &length, &point); status = FastDtoa(2147483648.0, buffer, &length, &point);
CHECK(status); CHECK(status);
CHECK_EQ(0, sign);
CHECK_EQ("2147483648", buffer.start()); CHECK_EQ("2147483648", buffer.start());
CHECK_EQ(10, point); CHECK_EQ(10, point);
status = FastDtoa(3.5844466002796428e+298, buffer, &sign, &length, &point); status = FastDtoa(3.5844466002796428e+298, buffer, &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("35844466002796428", buffer.start()); CHECK_EQ("35844466002796428", buffer.start());
CHECK_EQ(0, sign);
CHECK_EQ(299, point); CHECK_EQ(299, point);
} }
uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000, 00000000); uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000, 00000000);
double v = Double(smallest_normal64).value(); double v = Double(smallest_normal64).value();
status = FastDtoa(v, buffer, &sign, &length, &point); status = FastDtoa(v, buffer, &length, &point);
if (status) { if (status) {
CHECK_EQ(0, sign);
CHECK_EQ("22250738585072014", buffer.start()); CHECK_EQ("22250738585072014", buffer.start());
CHECK_EQ(-307, point); CHECK_EQ(-307, point);
} }
uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF);
v = Double(largest_denormal64).value(); v = Double(largest_denormal64).value();
status = FastDtoa(v, buffer, &sign, &length, &point); status = FastDtoa(v, buffer, &length, &point);
if (status) { if (status) {
CHECK_EQ(0, sign);
CHECK_EQ("2225073858507201", buffer.start()); CHECK_EQ("2225073858507201", buffer.start());
CHECK_EQ(-307, point); CHECK_EQ(-307, point);
} }
...@@ -92,24 +82,23 @@ TEST(FastDtoaGayShortest) { ...@@ -92,24 +82,23 @@ 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;
int sign;
int length; int length;
int point; int point;
int succeeded = 0; int succeeded = 0;
int total = 0; int total = 0;
bool needed_max_length = false; bool needed_max_length = false;
Vector<const GayShortest> precomputed = PrecomputedShortestRepresentations(); Vector<const PrecomputedShortest> precomputed =
PrecomputedShortestRepresentations();
for (int i = 0; i < precomputed.length(); ++i) { for (int i = 0; i < precomputed.length(); ++i) {
const GayShortest current_test = precomputed[i]; const PrecomputedShortest current_test = precomputed[i];
total++; total++;
double v = current_test.v; double v = current_test.v;
status = FastDtoa(v, buffer, &sign, &length, &point); status = FastDtoa(v, buffer, &length, &point);
CHECK_GE(kFastDtoaMaximalLength, length); CHECK_GE(kFastDtoaMaximalLength, length);
if (!status) continue; if (!status) continue;
if (length == kFastDtoaMaximalLength) needed_max_length = true; if (length == kFastDtoaMaximalLength) needed_max_length = true;
succeeded++; succeeded++;
CHECK_EQ(0, sign); // All precomputed numbers are positive.
CHECK_EQ(current_test.decimal_point, point); CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(current_test.representation, buffer.start()); CHECK_EQ(current_test.representation, buffer.start());
} }
......
This diff is collapsed.
...@@ -276,6 +276,8 @@ ...@@ -276,6 +276,8 @@
'../../src/disasm.h', '../../src/disasm.h',
'../../src/disassembler.cc', '../../src/disassembler.cc',
'../../src/disassembler.h', '../../src/disassembler.h',
'../../src/dtoa.cc',
'../../src/dtoa.h',
'../../src/dtoa-config.c', '../../src/dtoa-config.c',
'../../src/diy-fp.cc', '../../src/diy-fp.cc',
'../../src/diy-fp.h', '../../src/diy-fp.h',
...@@ -288,6 +290,8 @@ ...@@ -288,6 +290,8 @@
'../../src/fast-dtoa.cc', '../../src/fast-dtoa.cc',
'../../src/fast-dtoa.h', '../../src/fast-dtoa.h',
'../../src/flag-definitions.h', '../../src/flag-definitions.h',
'../../src/fixed-dtoa.cc',
'../../src/fixed-dtoa.h',
'../../src/flags.cc', '../../src/flags.cc',
'../../src/flags.h', '../../src/flags.h',
'../../src/flow-graph.cc', '../../src/flow-graph.cc',
......
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