michael@0: // Copyright 2010 the V8 project authors. All rights reserved. michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are michael@0: // met: michael@0: // michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above michael@0: // copyright notice, this list of conditions and the following michael@0: // disclaimer in the documentation and/or other materials provided michael@0: // with the distribution. michael@0: // * Neither the name of Google Inc. nor the names of its michael@0: // contributors may be used to endorse or promote products derived michael@0: // from this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: michael@0: #ifndef DOUBLE_CONVERSION_BIGNUM_DTOA_H_ michael@0: #define DOUBLE_CONVERSION_BIGNUM_DTOA_H_ michael@0: michael@0: #include "utils.h" michael@0: michael@0: namespace double_conversion { michael@0: michael@0: enum BignumDtoaMode { michael@0: // Return the shortest correct representation. michael@0: // For example the output of 0.299999999999999988897 is (the less accurate but michael@0: // correct) 0.3. michael@0: BIGNUM_DTOA_SHORTEST, michael@0: // Same as BIGNUM_DTOA_SHORTEST but for single-precision floats. michael@0: BIGNUM_DTOA_SHORTEST_SINGLE, michael@0: // Return a fixed number of digits after the decimal point. michael@0: // For instance fixed(0.1, 4) becomes 0.1000 michael@0: // If the input number is big, the output will be big. michael@0: BIGNUM_DTOA_FIXED, michael@0: // Return a fixed number of digits, no matter what the exponent is. michael@0: BIGNUM_DTOA_PRECISION michael@0: }; michael@0: michael@0: // Converts the given double 'v' to ascii. michael@0: // The result should be interpreted as buffer * 10^(point-length). michael@0: // The buffer will be null-terminated. michael@0: // michael@0: // The input v must be > 0 and different from NaN, and Infinity. michael@0: // michael@0: // The output depends on the given mode: michael@0: // - SHORTEST: produce the least amount of digits for which the internal michael@0: // identity requirement is still satisfied. If the digits are printed michael@0: // (together with the correct exponent) then reading this number will give michael@0: // 'v' again. The buffer will choose the representation that is closest to michael@0: // 'v'. If there are two at the same distance, than the number is round up. michael@0: // In this mode the 'requested_digits' parameter is ignored. michael@0: // - FIXED: produces digits necessary to print a given number with michael@0: // 'requested_digits' digits after the decimal point. The produced digits michael@0: // might be too short in which case the caller has to fill the gaps with '0's. michael@0: // Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2. michael@0: // Halfway cases are rounded up. The call toFixed(0.15, 2) thus returns michael@0: // buffer="2", point=0. michael@0: // Note: the length of the returned buffer has no meaning wrt the significance michael@0: // of its digits. That is, just because it contains '0's does not mean that michael@0: // any other digit would not satisfy the internal identity requirement. michael@0: // - PRECISION: produces 'requested_digits' where the first digit is not '0'. michael@0: // Even though the length of produced digits usually equals michael@0: // 'requested_digits', the function is allowed to return fewer digits, in michael@0: // which case the caller has to fill the missing digits with '0's. michael@0: // Halfway cases are again rounded up. michael@0: // 'BignumDtoa' expects the given buffer to be big enough to hold all digits michael@0: // and a terminating null-character. michael@0: void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits, michael@0: Vector buffer, int* length, int* point); michael@0: michael@0: } // namespace double_conversion michael@0: michael@0: #endif // DOUBLE_CONVERSION_BIGNUM_DTOA_H_