The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / conversions.h @ 40c0f755

History | View | Annotate | Download (4.47 KB)

1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
#ifndef V8_CONVERSIONS_H_
29
#define V8_CONVERSIONS_H_
30

    
31
namespace v8 { namespace internal {
32

    
33
// The fast double-to-int conversion routine does not guarantee
34
// rounding towards zero.
35
// The result is unspecified if x is infinite or NaN, or if the rounded
36
// integer value is outside the range of type int.
37
static inline int FastD2I(double x);
38

    
39

    
40
static inline double FastI2D(int x) {
41
  // There is no rounding involved in converting an integer to a
42
  // double, so this code should compile to a few instructions without
43
  // any FPU pipeline stalls.
44
  return static_cast<double>(x);
45
}
46

    
47

    
48
static inline double FastUI2D(unsigned x) {
49
  // There is no rounding involved in converting an unsigned integer to a
50
  // double, so this code should compile to a few instructions without
51
  // any FPU pipeline stalls.
52
  return static_cast<double>(x);
53
}
54

    
55

    
56
// This function should match the exact semantics of ECMA-262 9.4.
57
static inline double DoubleToInteger(double x);
58

    
59

    
60
// This function should match the exact semantics of ECMA-262 9.5.
61
static inline int32_t DoubleToInt32(double x);
62

    
63

    
64
// This function should match the exact semantics of ECMA-262 9.6.
65
static inline uint32_t DoubleToUint32(double x) {
66
  return static_cast<uint32_t>(DoubleToInt32(x));
67
}
68

    
69

    
70
// Returns the value (0 .. 15) of a hexadecimal character c.
71
// If c is not a legal hexadecimal character, returns a value < 0.
72
int HexValue(uc32 c);
73

    
74

    
75
// Enumeration for allowing octals and ignoring junk when converting
76
// strings to numbers.
77
enum ConversionFlags {
78
  NO_FLAGS = 0,
79
  ALLOW_HEX = 1,
80
  ALLOW_OCTALS = 2,
81
  ALLOW_TRAILING_JUNK = 4
82
};
83

    
84

    
85
// Convert from Number object to C integer.
86
static inline int32_t NumberToInt32(Object* number);
87
static inline uint32_t NumberToUint32(Object* number);
88

    
89

    
90
// Converts a string into a double value according to ECMA-262 9.3.1
91
double StringToDouble(const char* str, int flags, double empty_string_val = 0);
92
double StringToDouble(String* str, int flags, double empty_string_val = 0);
93

    
94
// Converts a string into an integer.
95
int StringToInt(String* str, int index, int radix, double* value);
96
int StringToInt(const char* str, int index, int radix, double* value);
97

    
98
// Converts a double to a string value according to ECMA-262 9.8.1.
99
// The buffer should be large enough for any floating point number.
100
// 100 characters is enough.
101
const char* DoubleToCString(double value, Vector<char> buffer);
102

    
103
// Convert an int to a null-terminated string. The returned string is
104
// located inside the buffer, but not necessarily at the start.
105
const char* IntToCString(int n, Vector<char> buffer);
106

    
107
// Additional number to string conversions for the number type.
108
// The caller is responsible for calling free on the returned pointer.
109
char* DoubleToFixedCString(double value, int f);
110
char* DoubleToExponentialCString(double value, int f);
111
char* DoubleToPrecisionCString(double value, int f);
112
char* DoubleToRadixCString(double value, int radix);
113

    
114
} }  // namespace v8::internal
115

    
116
#endif  // V8_CONVERSIONS_H_