V8 Project
dtoa.cc
Go to the documentation of this file.
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 "include/v8stdint.h"
8 #include "src/base/logging.h"
9 #include "src/utils.h"
10 
11 #include "src/dtoa.h"
12 
13 #include "src/bignum-dtoa.h"
14 #include "src/double.h"
15 #include "src/fast-dtoa.h"
16 #include "src/fixed-dtoa.h"
17 
18 namespace v8 {
19 namespace internal {
20 
22  switch (dtoa_mode) {
24  case DTOA_FIXED: return BIGNUM_DTOA_FIXED;
26  default:
27  UNREACHABLE();
28  return BIGNUM_DTOA_SHORTEST; // To silence compiler.
29  }
30 }
31 
32 
33 void DoubleToAscii(double v, DtoaMode mode, int requested_digits,
34  Vector<char> buffer, int* sign, int* length, int* point) {
35  DCHECK(!Double(v).IsSpecial());
36  DCHECK(mode == DTOA_SHORTEST || requested_digits >= 0);
37 
38  if (Double(v).Sign() < 0) {
39  *sign = 1;
40  v = -v;
41  } else {
42  *sign = 0;
43  }
44 
45  if (v == 0) {
46  buffer[0] = '0';
47  buffer[1] = '\0';
48  *length = 1;
49  *point = 1;
50  return;
51  }
52 
53  if (mode == DTOA_PRECISION && requested_digits == 0) {
54  buffer[0] = '\0';
55  *length = 0;
56  return;
57  }
58 
59  bool fast_worked;
60  switch (mode) {
61  case DTOA_SHORTEST:
62  fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, length, point);
63  break;
64  case DTOA_FIXED:
65  fast_worked = FastFixedDtoa(v, requested_digits, buffer, length, point);
66  break;
67  case DTOA_PRECISION:
68  fast_worked = FastDtoa(v, FAST_DTOA_PRECISION, requested_digits,
69  buffer, length, point);
70  break;
71  default:
72  UNREACHABLE();
73  fast_worked = false;
74  }
75  if (fast_worked) return;
76 
77  // If the fast dtoa didn't succeed use the slower bignum version.
79  BignumDtoa(v, bignum_mode, requested_digits, buffer, length, point);
80  buffer[*length] = '\0';
81 }
82 
83 } } // namespace v8::internal
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
#define UNREACHABLE()
Definition: logging.h:30
#define DCHECK(condition)
Definition: logging.h:205
bool FastFixedDtoa(double v, int fractional_count, Vector< char > buffer, int *length, int *decimal_point)
Definition: fixed-dtoa.cc:289
@ FAST_DTOA_SHORTEST
Definition: fast-dtoa.h:15
@ FAST_DTOA_PRECISION
Definition: fast-dtoa.h:18
@ BIGNUM_DTOA_SHORTEST
Definition: bignum-dtoa.h:15
@ BIGNUM_DTOA_PRECISION
Definition: bignum-dtoa.h:21
void DoubleToAscii(double v, DtoaMode mode, int requested_digits, Vector< char > buffer, int *sign, int *length, int *point)
Definition: dtoa.cc:33
@ DTOA_PRECISION
Definition: dtoa.h:21
@ DTOA_FIXED
Definition: dtoa.h:19
@ DTOA_SHORTEST
Definition: dtoa.h:15
static BignumDtoaMode DtoaToBignumDtoaMode(DtoaMode dtoa_mode)
Definition: dtoa.cc:21
bool FastDtoa(double v, FastDtoaMode mode, int requested_digits, Vector< char > buffer, int *length, int *decimal_point)
Definition: fast-dtoa.cc:686
void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits, Vector< char > buffer, int *length, int *decimal_point)
Definition: bignum-dtoa.cc:69
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20