LCOV - code coverage report
Current view: top level - src - dtoa.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 28 33 84.8 %
Date: 2019-04-18 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright 2011 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include <cmath>
       6             : 
       7             : #include "src/base/logging.h"
       8             : #include "src/utils.h"
       9             : 
      10             : #include "src/dtoa.h"
      11             : 
      12             : #include "src/bignum-dtoa.h"
      13             : #include "src/double.h"
      14             : #include "src/fast-dtoa.h"
      15             : #include "src/fixed-dtoa.h"
      16             : 
      17             : namespace v8 {
      18             : namespace internal {
      19             : 
      20       73030 : static BignumDtoaMode DtoaToBignumDtoaMode(DtoaMode dtoa_mode) {
      21       73030 :   switch (dtoa_mode) {
      22             :     case DTOA_SHORTEST:  return BIGNUM_DTOA_SHORTEST;
      23          36 :     case DTOA_FIXED:     return BIGNUM_DTOA_FIXED;
      24       66078 :     case DTOA_PRECISION: return BIGNUM_DTOA_PRECISION;
      25             :     default:
      26           0 :       UNREACHABLE();
      27             :   }
      28             : }
      29             : 
      30             : 
      31     2640459 : void DoubleToAscii(double v, DtoaMode mode, int requested_digits,
      32             :                    Vector<char> buffer, int* sign, int* length, int* point) {
      33             :   DCHECK(!Double(v).IsSpecial());
      34             :   DCHECK(mode == DTOA_SHORTEST || requested_digits >= 0);
      35             : 
      36     2640459 :   if (Double(v).Sign() < 0) {
      37      106073 :     *sign = 1;
      38      106073 :     v = -v;
      39             :   } else {
      40     2534386 :     *sign = 0;
      41             :   }
      42             : 
      43     2640459 :   if (v == 0) {
      44         608 :     buffer[0] = '0';
      45         608 :     buffer[1] = '\0';
      46         608 :     *length = 1;
      47         608 :     *point = 1;
      48         608 :     return;
      49             :   }
      50             : 
      51     2639851 :   if (mode == DTOA_PRECISION && requested_digits == 0) {
      52           0 :     buffer[0] = '\0';
      53           0 :     *length = 0;
      54           0 :     return;
      55             :   }
      56             : 
      57             :   bool fast_worked;
      58     2639851 :   switch (mode) {
      59             :     case DTOA_SHORTEST:
      60     1631665 :       fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, length, point);
      61     1631665 :       break;
      62             :     case DTOA_FIXED:
      63      502586 :       fast_worked = FastFixedDtoa(v, requested_digits, buffer, length, point);
      64      502586 :       break;
      65             :     case DTOA_PRECISION:
      66             :       fast_worked = FastDtoa(v, FAST_DTOA_PRECISION, requested_digits,
      67      505600 :                              buffer, length, point);
      68      505600 :       break;
      69             :     default:
      70           0 :       UNREACHABLE();
      71             :   }
      72     2639851 :   if (fast_worked) return;
      73             : 
      74             :   // If the fast dtoa didn't succeed use the slower bignum version.
      75       73030 :   BignumDtoaMode bignum_mode = DtoaToBignumDtoaMode(mode);
      76       73030 :   BignumDtoa(v, bignum_mode, requested_digits, buffer, length, point);
      77      146060 :   buffer[*length] = '\0';
      78             : }
      79             : 
      80             : }  // namespace internal
      81      122036 : }  // namespace v8

Generated by: LCOV version 1.10