Joshua
open source statistical hierarchical phrase-based machine translation system
|
00001 // Copyright 2010 the V8 project authors. All rights reserved. 00002 // Redistribution and use in source and binary forms, with or without 00003 // modification, are permitted provided that the following conditions are 00004 // met: 00005 // 00006 // * Redistributions of source code must retain the above copyright 00007 // notice, this list of conditions and the following disclaimer. 00008 // * Redistributions in binary form must reproduce the above 00009 // copyright notice, this list of conditions and the following 00010 // disclaimer in the documentation and/or other materials provided 00011 // with the distribution. 00012 // * Neither the name of Google Inc. nor the names of its 00013 // contributors may be used to endorse or promote products derived 00014 // from this software without specific prior written permission. 00015 // 00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 00028 #ifndef DOUBLE_CONVERSION_FAST_DTOA_H_ 00029 #define DOUBLE_CONVERSION_FAST_DTOA_H_ 00030 00031 #include "utils.h" 00032 00033 namespace double_conversion { 00034 00035 enum FastDtoaMode { 00036 // Computes the shortest representation of the given input. The returned 00037 // result will be the most accurate number of this length. Longer 00038 // representations might be more accurate. 00039 FAST_DTOA_SHORTEST, 00040 // Same as FAST_DTOA_SHORTEST but for single-precision floats. 00041 FAST_DTOA_SHORTEST_SINGLE, 00042 // Computes a representation where the precision (number of digits) is 00043 // given as input. The precision is independent of the decimal point. 00044 FAST_DTOA_PRECISION 00045 }; 00046 00047 // FastDtoa will produce at most kFastDtoaMaximalLength digits. This does not 00048 // include the terminating '\0' character. 00049 static const int kFastDtoaMaximalLength = 17; 00050 // Same for single-precision numbers. 00051 static const int kFastDtoaMaximalSingleLength = 9; 00052 00053 // Provides a decimal representation of v. 00054 // The result should be interpreted as buffer * 10^(point - length). 00055 // 00056 // Precondition: 00057 // * v must be a strictly positive finite double. 00058 // 00059 // Returns true if it succeeds, otherwise the result can not be trusted. 00060 // There will be *length digits inside the buffer followed by a null terminator. 00061 // If the function returns true and mode equals 00062 // - FAST_DTOA_SHORTEST, then 00063 // the parameter requested_digits is ignored. 00064 // The result satisfies 00065 // v == (double) (buffer * 10^(point - length)). 00066 // The digits in the buffer are the shortest representation possible. E.g. 00067 // if 0.099999999999 and 0.1 represent the same double then "1" is returned 00068 // with point = 0. 00069 // The last digit will be closest to the actual v. That is, even if several 00070 // digits might correctly yield 'v' when read again, the buffer will contain 00071 // the one closest to v. 00072 // - FAST_DTOA_PRECISION, then 00073 // the buffer contains requested_digits digits. 00074 // the difference v - (buffer * 10^(point-length)) is closest to zero for 00075 // all possible representations of requested_digits digits. 00076 // If there are two values that are equally close, then FastDtoa returns 00077 // false. 00078 // For both modes the buffer must be large enough to hold the result. 00079 bool FastDtoa(double d, 00080 FastDtoaMode mode, 00081 int requested_digits, 00082 Vector<char> buffer, 00083 int* length, 00084 int* decimal_point); 00085 00086 } // namespace double_conversion 00087 00088 #endif // DOUBLE_CONVERSION_FAST_DTOA_H_