Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:27

0001 // Copyright 2010 the V8 project authors. All rights reserved.
0002 // Redistribution and use in source and binary forms, with or without
0003 // modification, are permitted provided that the following conditions are
0004 // met:
0005 //
0006 //     * Redistributions of source code must retain the above copyright
0007 //       notice, this list of conditions and the following disclaimer.
0008 //     * Redistributions in binary form must reproduce the above
0009 //       copyright notice, this list of conditions and the following
0010 //       disclaimer in the documentation and/or other materials provided
0011 //       with the distribution.
0012 //     * Neither the name of Google Inc. nor the names of its
0013 //       contributors may be used to endorse or promote products derived
0014 //       from this software without specific prior written permission.
0015 //
0016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0027 
0028 #ifndef DOUBLE_CONVERSION_FAST_DTOA_H_
0029 #define DOUBLE_CONVERSION_FAST_DTOA_H_
0030 
0031 #include "utils.h"
0032 
0033 namespace double_conversion {
0034 
0035 enum FastDtoaMode {
0036   // Computes the shortest representation of the given input. The returned
0037   // result will be the most accurate number of this length. Longer
0038   // representations might be more accurate.
0039   FAST_DTOA_SHORTEST,
0040   // Same as FAST_DTOA_SHORTEST but for single-precision floats.
0041   FAST_DTOA_SHORTEST_SINGLE,
0042   // Computes a representation where the precision (number of digits) is
0043   // given as input. The precision is independent of the decimal point.
0044   FAST_DTOA_PRECISION
0045 };
0046 
0047 // FastDtoa will produce at most kFastDtoaMaximalLength digits. This does not
0048 // include the terminating '\0' character.
0049 static const int kFastDtoaMaximalLength = 17;
0050 // Same for single-precision numbers.
0051 static const int kFastDtoaMaximalSingleLength = 9;
0052 
0053 // Provides a decimal representation of v.
0054 // The result should be interpreted as buffer * 10^(point - length).
0055 //
0056 // Precondition:
0057 //   * v must be a strictly positive finite double.
0058 //
0059 // Returns true if it succeeds, otherwise the result can not be trusted.
0060 // There will be *length digits inside the buffer followed by a null terminator.
0061 // If the function returns true and mode equals
0062 //   - FAST_DTOA_SHORTEST, then
0063 //     the parameter requested_digits is ignored.
0064 //     The result satisfies
0065 //         v == (double) (buffer * 10^(point - length)).
0066 //     The digits in the buffer are the shortest representation possible. E.g.
0067 //     if 0.099999999999 and 0.1 represent the same double then "1" is returned
0068 //     with point = 0.
0069 //     The last digit will be closest to the actual v. That is, even if several
0070 //     digits might correctly yield 'v' when read again, the buffer will contain
0071 //     the one closest to v.
0072 //   - FAST_DTOA_PRECISION, then
0073 //     the buffer contains requested_digits digits.
0074 //     the difference v - (buffer * 10^(point-length)) is closest to zero for
0075 //     all possible representations of requested_digits digits.
0076 //     If there are two values that are equally close, then FastDtoa returns
0077 //     false.
0078 // For both modes the buffer must be large enough to hold the result.
0079 bool FastDtoa(double d,
0080               FastDtoaMode mode,
0081               int requested_digits,
0082               Vector<char> buffer,
0083               int* length,
0084               int* decimal_point);
0085 
0086 }  // namespace double_conversion
0087 
0088 #endif  // DOUBLE_CONVERSION_FAST_DTOA_H_