// 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 <cmath> #include "fixed-dtoa.h" #include "ieee.h" namespace double_conversion { // Represents a 128bit type. This class should be replaced by a native type on // platforms that support 128bit integers. class UInt128 { … }; static const int kDoubleSignificandSize = …; // Includes the hidden bit. static void FillDigits32FixedLength(uint32_t number, int requested_length, Vector<char> buffer, int* length) { … } static void FillDigits32(uint32_t number, Vector<char> buffer, int* length) { … } static void FillDigits64FixedLength(uint64_t number, Vector<char> buffer, int* length) { … } static void FillDigits64(uint64_t number, Vector<char> buffer, int* length) { … } static void RoundUp(Vector<char> buffer, int* length, int* decimal_point) { … } // The given fractionals number represents a fixed-point number with binary // point at bit (-exponent). // Preconditions: // -128 <= exponent <= 0. // 0 <= fractionals * 2^exponent < 1 // The buffer holds the result. // The function will round its result. During the rounding-process digits not // generated by this function might be updated, and the decimal-point variable // might be updated. If this function generates the digits 99 and the buffer // already contained "199" (thus yielding a buffer of "19999") then a // rounding-up will change the contents of the buffer to "20000". static void FillFractionals(uint64_t fractionals, int exponent, int fractional_count, Vector<char> buffer, int* length, int* decimal_point) { … } // Removes leading and trailing zeros. // If leading zeros are removed then the decimal point position is adjusted. static void TrimZeros(Vector<char> buffer, int* length, int* decimal_point) { … } bool FastFixedDtoa(double v, int fractional_count, Vector<char> buffer, int* length, int* decimal_point) { … } } // namespace double_conversion