V8 Project
v8::internal::Double Class Reference

#include <double.h>

+ Collaboration diagram for v8::internal::Double:

Public Member Functions

 Double ()
 
 Double (double d)
 
 Double (uint64_t d64)
 
 Double (DiyFp diy_fp)
 
DiyFp AsDiyFp () const
 
DiyFp AsNormalizedDiyFp () const
 
uint64_t AsUint64 () const
 
double NextDouble () const
 
int Exponent () const
 
uint64_t Significand () const
 
bool IsDenormal () const
 
bool IsSpecial () const
 
bool IsInfinite () const
 
int Sign () const
 
DiyFp UpperBoundary () const
 
void NormalizedBoundaries (DiyFp *out_m_minus, DiyFp *out_m_plus) const
 
double value () const
 

Static Public Member Functions

static int SignificandSizeForOrderOfMagnitude (int order)
 

Static Public Attributes

static const uint64_t kSignMask = V8_2PART_UINT64_C(0x80000000, 00000000)
 
static const uint64_t kExponentMask = V8_2PART_UINT64_C(0x7FF00000, 00000000)
 
static const uint64_t kSignificandMask
 
static const uint64_t kHiddenBit = V8_2PART_UINT64_C(0x00100000, 00000000)
 
static const int kPhysicalSignificandSize = 52
 
static const int kSignificandSize = 53
 

Static Private Member Functions

static uint64_t DiyFpToUint64 (DiyFp diy_fp)
 

Private Attributes

const uint64_t d64_
 

Static Private Attributes

static const int kExponentBias = 0x3FF + kPhysicalSignificandSize
 
static const int kDenormalExponent = -kExponentBias + 1
 
static const int kMaxExponent = 0x7FF - kExponentBias
 
static const uint64_t kInfinity = V8_2PART_UINT64_C(0x7FF00000, 00000000)
 

Detailed Description

Definition at line 18 of file double.h.

Constructor & Destructor Documentation

◆ Double() [1/4]

v8::internal::Double::Double ( )
inline

Definition at line 28 of file double.h.

28 : d64_(0) {}
const uint64_t d64_
Definition: double.h:177

Referenced by NextDouble().

+ Here is the caller graph for this function:

◆ Double() [2/4]

v8::internal::Double::Double ( double  d)
inlineexplicit

Definition at line 29 of file double.h.

29 : d64_(double_to_uint64(d)) {}
uint64_t double_to_uint64(double d)
Definition: double.h:14

◆ Double() [3/4]

v8::internal::Double::Double ( uint64_t  d64)
inlineexplicit

Definition at line 30 of file double.h.

30 : d64_(d64) {}

◆ Double() [4/4]

v8::internal::Double::Double ( DiyFp  diy_fp)
inlineexplicit

Definition at line 31 of file double.h.

32  : d64_(DiyFpToUint64(diy_fp)) {}
static uint64_t DiyFpToUint64(DiyFp diy_fp)
Definition: double.h:179

Member Function Documentation

◆ AsDiyFp()

DiyFp v8::internal::Double::AsDiyFp ( ) const
inline

Definition at line 36 of file double.h.

36  {
37  DCHECK(Sign() > 0);
38  DCHECK(!IsSpecial());
39  return DiyFp(Significand(), Exponent());
40  }
bool IsSpecial() const
Definition: double.h:105
uint64_t Significand() const
Definition: double.h:87
int Exponent() const
Definition: double.h:78
int Sign() const
Definition: double.h:116
#define DCHECK(condition)
Definition: logging.h:205

References DCHECK, Exponent(), IsSpecial(), Sign(), and Significand().

Referenced by NormalizedBoundaries().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AsNormalizedDiyFp()

DiyFp v8::internal::Double::AsNormalizedDiyFp ( ) const
inline

Definition at line 43 of file double.h.

43  {
44  DCHECK(value() > 0.0);
45  uint64_t f = Significand();
46  int e = Exponent();
47 
48  // The current double could be a denormal.
49  while ((f & kHiddenBit) == 0) {
50  f <<= 1;
51  e--;
52  }
53  // Do the final shifts in one go.
56  return DiyFp(f, e);
57  }
static const int kSignificandSize
Definition: diy-fp.h:18
static const uint64_t kHiddenBit
Definition: double.h:24
static const int kSignificandSize
Definition: double.h:26
double value() const
Definition: double.h:155

References DCHECK, Exponent(), kHiddenBit, v8::internal::DiyFp::kSignificandSize, kSignificandSize, Significand(), and value().

Referenced by v8::internal::Grisu3(), and v8::internal::Grisu3Counted().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AsUint64()

uint64_t v8::internal::Double::AsUint64 ( ) const
inline

Definition at line 60 of file double.h.

60  {
61  return d64_;
62  }

References d64_.

Referenced by Exponent(), v8::internal::InitialScaledStartValuesNegativeExponentNegativePower(), v8::internal::InitialScaledStartValuesNegativeExponentPositivePower(), v8::internal::InitialScaledStartValuesPositiveExponent(), IsDenormal(), IsInfinite(), IsSpecial(), Sign(), and Significand().

+ Here is the caller graph for this function:

◆ DiyFpToUint64()

static uint64_t v8::internal::Double::DiyFpToUint64 ( DiyFp  diy_fp)
inlinestaticprivate

Definition at line 179 of file double.h.

179  {
180  uint64_t significand = diy_fp.f();
181  int exponent = diy_fp.e();
182  while (significand > kHiddenBit + kSignificandMask) {
183  significand >>= 1;
184  exponent++;
185  }
186  if (exponent >= kMaxExponent) {
187  return kInfinity;
188  }
189  if (exponent < kDenormalExponent) {
190  return 0;
191  }
192  while (exponent > kDenormalExponent && (significand & kHiddenBit) == 0) {
193  significand <<= 1;
194  exponent--;
195  }
196  uint64_t biased_exponent;
197  if (exponent == kDenormalExponent && (significand & kHiddenBit) == 0) {
198  biased_exponent = 0;
199  } else {
200  biased_exponent = static_cast<uint64_t>(exponent + kExponentBias);
201  }
202  return (significand & kSignificandMask) |
203  (biased_exponent << kPhysicalSignificandSize);
204  }
static const int kExponentBias
Definition: double.h:172
static const int kDenormalExponent
Definition: double.h:173
static const uint64_t kInfinity
Definition: double.h:175
static const uint64_t kSignificandMask
Definition: double.h:22
static const int kPhysicalSignificandSize
Definition: double.h:25
static const int kMaxExponent
Definition: double.h:174

References v8::internal::DiyFp::e(), v8::internal::DiyFp::f(), kDenormalExponent, kExponentBias, kHiddenBit, kInfinity, kMaxExponent, kPhysicalSignificandSize, and kSignificandMask.

+ Here is the call graph for this function:

◆ Exponent()

int v8::internal::Double::Exponent ( ) const
inline

Definition at line 78 of file double.h.

78  {
79  if (IsDenormal()) return kDenormalExponent;
80 
81  uint64_t d64 = AsUint64();
82  int biased_e =
83  static_cast<int>((d64 & kExponentMask) >> kPhysicalSignificandSize);
84  return biased_e - kExponentBias;
85  }
uint64_t AsUint64() const
Definition: double.h:60
bool IsDenormal() const
Definition: double.h:98
static const uint64_t kExponentMask
Definition: double.h:21

References AsUint64(), IsDenormal(), kDenormalExponent, kExponentBias, kExponentMask, and kPhysicalSignificandSize.

Referenced by AsDiyFp(), AsNormalizedDiyFp(), v8::internal::BignumDtoa(), v8::internal::DoubleToInt32(), v8::internal::FastFixedDtoa(), v8::internal::InitialScaledStartValuesNegativeExponentNegativePower(), v8::internal::InitialScaledStartValuesNegativeExponentPositivePower(), and UpperBoundary().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsDenormal()

bool v8::internal::Double::IsDenormal ( ) const
inline

Definition at line 98 of file double.h.

98  {
99  uint64_t d64 = AsUint64();
100  return (d64 & kExponentMask) == 0;
101  }

References AsUint64(), and kExponentMask.

Referenced by Exponent(), and Significand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsInfinite()

bool v8::internal::Double::IsInfinite ( ) const
inline

Definition at line 110 of file double.h.

110  {
111  uint64_t d64 = AsUint64();
112  return ((d64 & kExponentMask) == kExponentMask) &&
113  ((d64 & kSignificandMask) == 0);
114  }

References AsUint64(), kExponentMask, and kSignificandMask.

+ Here is the call graph for this function:

◆ IsSpecial()

bool v8::internal::Double::IsSpecial ( ) const
inline

Definition at line 105 of file double.h.

105  {
106  uint64_t d64 = AsUint64();
107  return (d64 & kExponentMask) == kExponentMask;
108  }

References AsUint64(), and kExponentMask.

Referenced by AsDiyFp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NextDouble()

double v8::internal::Double::NextDouble ( ) const
inline

Definition at line 65 of file double.h.

65  {
66  if (d64_ == kInfinity) return Double(kInfinity).value();
67  if (Sign() < 0 && Significand() == 0) {
68  // -0.0
69  return 0.0;
70  }
71  if (Sign() < 0) {
72  return Double(d64_ - 1).value();
73  } else {
74  return Double(d64_ + 1).value();
75  }
76  }

References d64_, Double(), kInfinity, Sign(), and Significand().

Referenced by v8::internal::BignumStrtod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NormalizedBoundaries()

void v8::internal::Double::NormalizedBoundaries ( DiyFp out_m_minus,
DiyFp out_m_plus 
) const
inline

Definition at line 132 of file double.h.

132  {
133  DCHECK(value() > 0.0);
134  DiyFp v = this->AsDiyFp();
135  bool significand_is_zero = (v.f() == kHiddenBit);
136  DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1));
137  DiyFp m_minus;
138  if (significand_is_zero && v.e() != kDenormalExponent) {
139  // The boundary is closer. Think of v = 1000e10 and v- = 9999e9.
140  // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but
141  // at a distance of 1e8.
142  // The only exception is for the smallest normal: the largest denormal is
143  // at the same distance as its successor.
144  // Note: denormals have the same exponent as the smallest normals.
145  m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2);
146  } else {
147  m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1);
148  }
149  m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e()));
150  m_minus.set_e(m_plus.e());
151  *out_m_plus = m_plus;
152  *out_m_minus = m_minus;
153  }
void Normalize()
Definition: diy-fp.h:53
DiyFp AsDiyFp() const
Definition: double.h:36

References AsDiyFp(), DCHECK, v8::internal::DiyFp::e(), v8::internal::DiyFp::f(), kDenormalExponent, kHiddenBit, v8::internal::DiyFp::Normalize(), v8::internal::DiyFp::set_e(), v8::internal::DiyFp::set_f(), and value().

Referenced by v8::internal::Grisu3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Sign()

int v8::internal::Double::Sign ( ) const
inline

Definition at line 116 of file double.h.

116  {
117  uint64_t d64 = AsUint64();
118  return (d64 & kSignMask) == 0? 1: -1;
119  }
static const uint64_t kSignMask
Definition: double.h:20

References AsUint64(), and kSignMask.

Referenced by AsDiyFp(), v8::internal::DoubleToInt32(), NextDouble(), and UpperBoundary().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Significand()

uint64_t v8::internal::Double::Significand ( ) const
inline

Definition at line 87 of file double.h.

87  {
88  uint64_t d64 = AsUint64();
89  uint64_t significand = d64 & kSignificandMask;
90  if (!IsDenormal()) {
91  return significand + kHiddenBit;
92  } else {
93  return significand;
94  }
95  }

References AsUint64(), IsDenormal(), kHiddenBit, and kSignificandMask.

Referenced by AsDiyFp(), AsNormalizedDiyFp(), v8::internal::BignumDtoa(), v8::internal::DoubleToInt32(), v8::internal::FastFixedDtoa(), v8::internal::InitialScaledStartValuesNegativeExponentNegativePower(), v8::internal::InitialScaledStartValuesNegativeExponentPositivePower(), NextDouble(), and UpperBoundary().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SignificandSizeForOrderOfMagnitude()

static int v8::internal::Double::SignificandSizeForOrderOfMagnitude ( int  order)
inlinestatic

Definition at line 163 of file double.h.

163  {
164  if (order >= (kDenormalExponent + kSignificandSize)) {
165  return kSignificandSize;
166  }
167  if (order <= kDenormalExponent) return 0;
168  return order - kDenormalExponent;
169  }

References kDenormalExponent, and kSignificandSize.

Referenced by v8::internal::DiyFpStrtod().

+ Here is the caller graph for this function:

◆ UpperBoundary()

DiyFp v8::internal::Double::UpperBoundary ( ) const
inline

Definition at line 123 of file double.h.

123  {
124  DCHECK(Sign() > 0);
125  return DiyFp(Significand() * 2 + 1, Exponent() - 1);
126  }

References DCHECK, Exponent(), Sign(), and Significand().

Referenced by v8::internal::BignumStrtod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ value()

double v8::internal::Double::value ( ) const
inline

Definition at line 155 of file double.h.

155 { return uint64_to_double(d64_); }
double uint64_to_double(uint64_t d64)
Definition: double.h:15

References d64_, and v8::internal::uint64_to_double().

Referenced by AsNormalizedDiyFp(), v8::internal::DiyFpStrtod(), and NormalizedBoundaries().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ d64_

const uint64_t v8::internal::Double::d64_
private

Definition at line 177 of file double.h.

Referenced by AsUint64(), NextDouble(), and value().

◆ kDenormalExponent

const int v8::internal::Double::kDenormalExponent = -kExponentBias + 1
staticprivate

◆ kExponentBias

const int v8::internal::Double::kExponentBias = 0x3FF + kPhysicalSignificandSize
staticprivate

Definition at line 172 of file double.h.

Referenced by DiyFpToUint64(), and Exponent().

◆ kExponentMask

const uint64_t v8::internal::Double::kExponentMask = V8_2PART_UINT64_C(0x7FF00000, 00000000)
static

◆ kHiddenBit

const uint64_t v8::internal::Double::kHiddenBit = V8_2PART_UINT64_C(0x00100000, 00000000)
static

◆ kInfinity

const uint64_t v8::internal::Double::kInfinity = V8_2PART_UINT64_C(0x7FF00000, 00000000)
staticprivate

Definition at line 175 of file double.h.

Referenced by DiyFpToUint64(), and NextDouble().

◆ kMaxExponent

const int v8::internal::Double::kMaxExponent = 0x7FF - kExponentBias
staticprivate

Definition at line 174 of file double.h.

Referenced by DiyFpToUint64().

◆ kPhysicalSignificandSize

const int v8::internal::Double::kPhysicalSignificandSize = 52
static

Definition at line 25 of file double.h.

Referenced by DiyFpToUint64(), and Exponent().

◆ kSignificandMask

const uint64_t v8::internal::Double::kSignificandMask
static

◆ kSignificandSize

const int v8::internal::Double::kSignificandSize = 53
static

◆ kSignMask

const uint64_t v8::internal::Double::kSignMask = V8_2PART_UINT64_C(0x80000000, 00000000)
static

Definition at line 20 of file double.h.

Referenced by Sign(), and v8::internal::SignedZero().


The documentation for this class was generated from the following file: