14a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// Copyright 2010 the V8 project authors. All rights reserved. 23484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org// Use of this source code is governed by a BSD-style license that can be 33484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org// found in the LICENSE file. 44a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com 54a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com#ifndef V8_BIGNUM_DTOA_H_ 64a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com#define V8_BIGNUM_DTOA_H_ 74a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com 84a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.comnamespace v8 { 94a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.comnamespace internal { 104a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com 114a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.comenum BignumDtoaMode { 124a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com // Return the shortest correct representation. 134a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com // For example the output of 0.299999999999999988897 is (the less accurate but 144a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com // correct) 0.3. 154a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com BIGNUM_DTOA_SHORTEST, 164a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com // Return a fixed number of digits after the decimal point. 174a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com // For instance fixed(0.1, 4) becomes 0.1000 184a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com // If the input number is big, the output will be big. 194a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com BIGNUM_DTOA_FIXED, 204a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com // Return a fixed number of digits, no matter what the exponent is. 214a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com BIGNUM_DTOA_PRECISION 224a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com}; 234a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com 242efb900e7350b14be905abdeab077f3a64c583cfulan@chromium.org// Converts the given double 'v' to ASCII. 254a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// The result should be interpreted as buffer * 10^(point-length). 264a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// The buffer will be null-terminated. 274a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// 284a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// The input v must be > 0 and different from NaN, and Infinity. 294a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// 304a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// The output depends on the given mode: 314a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// - SHORTEST: produce the least amount of digits for which the internal 324a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// identity requirement is still satisfied. If the digits are printed 334a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// (together with the correct exponent) then reading this number will give 344a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// 'v' again. The buffer will choose the representation that is closest to 354a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// 'v'. If there are two at the same distance, than the number is round up. 364a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// In this mode the 'requested_digits' parameter is ignored. 374a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// - FIXED: produces digits necessary to print a given number with 384a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// 'requested_digits' digits after the decimal point. The produced digits 394a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// might be too short in which case the caller has to fill the gaps with '0's. 404a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2. 414a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// Halfway cases are rounded up. The call toFixed(0.15, 2) thus returns 424a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// buffer="2", point=0. 434a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// Note: the length of the returned buffer has no meaning wrt the significance 444a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// of its digits. That is, just because it contains '0's does not mean that 454a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// any other digit would not satisfy the internal identity requirement. 464a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// - PRECISION: produces 'requested_digits' where the first digit is not '0'. 474a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// Even though the length of produced digits usually equals 484a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// 'requested_digits', the function is allowed to return fewer digits, in 494a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// which case the caller has to fill the missing digits with '0's. 504a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// Halfway cases are again rounded up. 514a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// 'BignumDtoa' expects the given buffer to be big enough to hold all digits 524a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com// and a terminating null-character. 534a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.comvoid BignumDtoa(double v, BignumDtoaMode mode, int requested_digits, 544a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com Vector<char> buffer, int* length, int* point); 554a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com 564a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com} } // namespace v8::internal 574a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com 584a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com#endif // V8_BIGNUM_DTOA_H_ 59