Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
double_conversion::Double Class Reference

#include <ieee.h>

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
 
double PreviousDouble () const
 
int Exponent () const
 
uint64_t Significand () const
 
bool IsDenormal () const
 
bool IsSpecial () const
 
bool IsNan () const
 
bool IsQuietNan () const
 
bool IsSignalingNan () const
 
bool IsInfinite () const
 
int Sign () const
 
DiyFp UpperBoundary () const
 
void NormalizedBoundaries (DiyFp *out_m_minus, DiyFp *out_m_plus) const
 
bool LowerBoundaryIsCloser () const
 
double value () const
 

Static Public Member Functions

static int SignificandSizeForOrderOfMagnitude (int order)
 
static double Infinity ()
 
static double NaN ()
 

Static Public Attributes

static const uint64_t kSignMask = DOUBLE_CONVERSION_UINT64_2PART_C(0x80000000, 00000000)
 
static const uint64_t kExponentMask = DOUBLE_CONVERSION_UINT64_2PART_C(0x7FF00000, 00000000)
 
static const uint64_t kSignificandMask = DOUBLE_CONVERSION_UINT64_2PART_C(0x000FFFFF, FFFFFFFF)
 
static const uint64_t kHiddenBit = DOUBLE_CONVERSION_UINT64_2PART_C(0x00100000, 00000000)
 
static const uint64_t kQuietNanBit = DOUBLE_CONVERSION_UINT64_2PART_C(0x00080000, 00000000)
 
static const int kPhysicalSignificandSize = 52
 
static const int kSignificandSize = 53
 
static const int kExponentBias = 0x3FF + kPhysicalSignificandSize
 
static const int kMaxExponent = 0x7FF - kExponentBias
 

Detailed Description

Definition at line 42 of file ieee.h.

Constructor & Destructor Documentation

◆ Double() [1/4]

double_conversion::Double::Double ( )
inline

Definition at line 54 of file ieee.h.

54: d64_(0) {}

◆ Double() [2/4]

double_conversion::Double::Double ( double  d)
inlineexplicit

Definition at line 55 of file ieee.h.

55: d64_(double_to_uint64(d)) {}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
static uint64_t double_to_uint64(double d)
Definition: ieee.h:36

◆ Double() [3/4]

double_conversion::Double::Double ( uint64_t  d64)
inlineexplicit

Definition at line 56 of file ieee.h.

56: d64_(d64) {}

◆ Double() [4/4]

double_conversion::Double::Double ( DiyFp  diy_fp)
inlineexplicit

Definition at line 57 of file ieee.h.

58 : d64_(DiyFpToUint64(diy_fp)) {}

Member Function Documentation

◆ AsDiyFp()

DiyFp double_conversion::Double::AsDiyFp ( ) const
inline

Definition at line 62 of file ieee.h.

62 {
65 return DiyFp(Significand(), Exponent());
66 }
uint64_t Significand() const
Definition: ieee.h:123
bool IsSpecial() const
Definition: ieee.h:141
int Exponent() const
Definition: ieee.h:114
int Sign() const
Definition: ieee.h:175
#define DOUBLE_CONVERSION_ASSERT(condition)
Definition: utils.h:46

◆ AsNormalizedDiyFp()

DiyFp double_conversion::Double::AsNormalizedDiyFp ( ) const
inline

Definition at line 69 of file ieee.h.

69 {
71 uint64_t f = Significand();
72 int e = Exponent();
73
74 // The current double could be a denormal.
75 while ((f & kHiddenBit) == 0) {
76 f <<= 1;
77 e--;
78 }
79 // Do the final shifts in one go.
82 return DiyFp(f, e);
83 }
static const int kSignificandSize
Definition: diy-fp.h:43
static const uint64_t kHiddenBit
Definition: ieee.h:47
static const int kSignificandSize
Definition: ieee.h:50
double value() const
Definition: ieee.h:220

◆ AsUint64()

uint64_t double_conversion::Double::AsUint64 ( ) const
inline

Definition at line 86 of file ieee.h.

86 {
87 return d64_;
88 }

◆ Exponent()

int double_conversion::Double::Exponent ( ) const
inline

Definition at line 114 of file ieee.h.

114 {
115 if (IsDenormal()) return kDenormalExponent;
116
117 uint64_t d64 = AsUint64();
118 int biased_e =
119 static_cast<int>((d64 & kExponentMask) >> kPhysicalSignificandSize);
120 return biased_e - kExponentBias;
121 }
uint64_t AsUint64() const
Definition: ieee.h:86
static const int kExponentBias
Definition: ieee.h:51
bool IsDenormal() const
Definition: ieee.h:134
static const uint64_t kExponentMask
Definition: ieee.h:45
static const int kPhysicalSignificandSize
Definition: ieee.h:49

◆ Infinity()

static double double_conversion::Double::Infinity ( )
inlinestatic

Definition at line 236 of file ieee.h.

236 {
237 return Double(kInfinity).value();
238 }

◆ IsDenormal()

bool double_conversion::Double::IsDenormal ( ) const
inline

Definition at line 134 of file ieee.h.

134 {
135 uint64_t d64 = AsUint64();
136 return (d64 & kExponentMask) == 0;
137 }

◆ IsInfinite()

bool double_conversion::Double::IsInfinite ( ) const
inline

Definition at line 169 of file ieee.h.

169 {
170 uint64_t d64 = AsUint64();
171 return ((d64 & kExponentMask) == kExponentMask) &&
172 ((d64 & kSignificandMask) == 0);
173 }
static const uint64_t kSignificandMask
Definition: ieee.h:46

◆ IsNan()

bool double_conversion::Double::IsNan ( ) const
inline

Definition at line 146 of file ieee.h.

146 {
147 uint64_t d64 = AsUint64();
148 return ((d64 & kExponentMask) == kExponentMask) &&
149 ((d64 & kSignificandMask) != 0);
150 }

◆ IsQuietNan()

bool double_conversion::Double::IsQuietNan ( ) const
inline

Definition at line 152 of file ieee.h.

152 {
153#if (defined(__mips__) && !defined(__mips_nan2008)) || defined(__hppa__)
154 return IsNan() && ((AsUint64() & kQuietNanBit) == 0);
155#else
156 return IsNan() && ((AsUint64() & kQuietNanBit) != 0);
157#endif
158 }
static const uint64_t kQuietNanBit
Definition: ieee.h:48
bool IsNan() const
Definition: ieee.h:146

◆ IsSignalingNan()

bool double_conversion::Double::IsSignalingNan ( ) const
inline

Definition at line 160 of file ieee.h.

160 {
161#if (defined(__mips__) && !defined(__mips_nan2008)) || defined(__hppa__)
162 return IsNan() && ((AsUint64() & kQuietNanBit) != 0);
163#else
164 return IsNan() && ((AsUint64() & kQuietNanBit) == 0);
165#endif
166 }

◆ IsSpecial()

bool double_conversion::Double::IsSpecial ( ) const
inline

Definition at line 141 of file ieee.h.

141 {
142 uint64_t d64 = AsUint64();
143 return (d64 & kExponentMask) == kExponentMask;
144 }

◆ LowerBoundaryIsCloser()

bool double_conversion::Double::LowerBoundaryIsCloser ( ) const
inline

Definition at line 207 of file ieee.h.

207 {
208 // The boundary is closer if the significand is of the form f == 2^p-1 then
209 // the lower boundary is closer.
210 // Think of v = 1000e10 and v- = 9999e9.
211 // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but
212 // at a distance of 1e8.
213 // The only exception is for the smallest normal: the largest denormal is
214 // at the same distance as its successor.
215 // Note: denormals have the same exponent as the smallest normals.
216 bool physical_significand_is_zero = ((AsUint64() & kSignificandMask) == 0);
217 return physical_significand_is_zero && (Exponent() != kDenormalExponent);
218 }

◆ NaN()

static double double_conversion::Double::NaN ( )
inlinestatic

Definition at line 240 of file ieee.h.

240 {
241 return Double(kNaN).value();
242 }

◆ NextDouble()

double double_conversion::Double::NextDouble ( ) const
inline

Definition at line 91 of file ieee.h.

91 {
92 if (d64_ == kInfinity) return Double(kInfinity).value();
93 if (Sign() < 0 && Significand() == 0) {
94 // -0.0
95 return 0.0;
96 }
97 if (Sign() < 0) {
98 return Double(d64_ - 1).value();
99 } else {
100 return Double(d64_ + 1).value();
101 }
102 }

◆ NormalizedBoundaries()

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

Definition at line 191 of file ieee.h.

191 {
193 DiyFp v = this->AsDiyFp();
194 DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1));
195 DiyFp m_minus;
196 if (LowerBoundaryIsCloser()) {
197 m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2);
198 } else {
199 m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1);
200 }
201 m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e()));
202 m_minus.set_e(m_plus.e());
203 *out_m_plus = m_plus;
204 *out_m_minus = m_minus;
205 }
DiyFp AsDiyFp() const
Definition: ieee.h:62
bool LowerBoundaryIsCloser() const
Definition: ieee.h:207

◆ PreviousDouble()

double double_conversion::Double::PreviousDouble ( ) const
inline

Definition at line 104 of file ieee.h.

104 {
105 if (d64_ == (kInfinity | kSignMask)) return -Infinity();
106 if (Sign() < 0) {
107 return Double(d64_ + 1).value();
108 } else {
109 if (Significand() == 0) return -0.0;
110 return Double(d64_ - 1).value();
111 }
112 }
static double Infinity()
Definition: ieee.h:236
static const uint64_t kSignMask
Definition: ieee.h:44

◆ Sign()

int double_conversion::Double::Sign ( ) const
inline

Definition at line 175 of file ieee.h.

175 {
176 uint64_t d64 = AsUint64();
177 return (d64 & kSignMask) == 0? 1: -1;
178 }

◆ Significand()

uint64_t double_conversion::Double::Significand ( ) const
inline

Definition at line 123 of file ieee.h.

123 {
124 uint64_t d64 = AsUint64();
125 uint64_t significand = d64 & kSignificandMask;
126 if (!IsDenormal()) {
127 return significand + kHiddenBit;
128 } else {
129 return significand;
130 }
131 }

◆ SignificandSizeForOrderOfMagnitude()

static int double_conversion::Double::SignificandSizeForOrderOfMagnitude ( int  order)
inlinestatic

Definition at line 228 of file ieee.h.

228 {
229 if (order >= (kDenormalExponent + kSignificandSize)) {
230 return kSignificandSize;
231 }
232 if (order <= kDenormalExponent) return 0;
233 return order - kDenormalExponent;
234 }

◆ UpperBoundary()

DiyFp double_conversion::Double::UpperBoundary ( ) const
inline

Definition at line 182 of file ieee.h.

182 {
184 return DiyFp(Significand() * 2 + 1, Exponent() - 1);
185 }

◆ value()

double double_conversion::Double::value ( ) const
inline

Definition at line 220 of file ieee.h.

220{ return uint64_to_double(d64_); }
static double uint64_to_double(uint64_t d64)
Definition: ieee.h:37

Member Data Documentation

◆ kExponentBias

const int double_conversion::Double::kExponentBias = 0x3FF + kPhysicalSignificandSize
static

Definition at line 51 of file ieee.h.

◆ kExponentMask

const uint64_t double_conversion::Double::kExponentMask = DOUBLE_CONVERSION_UINT64_2PART_C(0x7FF00000, 00000000)
static

Definition at line 45 of file ieee.h.

◆ kHiddenBit

const uint64_t double_conversion::Double::kHiddenBit = DOUBLE_CONVERSION_UINT64_2PART_C(0x00100000, 00000000)
static

Definition at line 47 of file ieee.h.

◆ kMaxExponent

const int double_conversion::Double::kMaxExponent = 0x7FF - kExponentBias
static

Definition at line 52 of file ieee.h.

◆ kPhysicalSignificandSize

const int double_conversion::Double::kPhysicalSignificandSize = 52
static

Definition at line 49 of file ieee.h.

◆ kQuietNanBit

const uint64_t double_conversion::Double::kQuietNanBit = DOUBLE_CONVERSION_UINT64_2PART_C(0x00080000, 00000000)
static

Definition at line 48 of file ieee.h.

◆ kSignificandMask

const uint64_t double_conversion::Double::kSignificandMask = DOUBLE_CONVERSION_UINT64_2PART_C(0x000FFFFF, FFFFFFFF)
static

Definition at line 46 of file ieee.h.

◆ kSignificandSize

const int double_conversion::Double::kSignificandSize = 53
static

Definition at line 50 of file ieee.h.

◆ kSignMask

const uint64_t double_conversion::Double::kSignMask = DOUBLE_CONVERSION_UINT64_2PART_C(0x80000000, 00000000)
static

Definition at line 44 of file ieee.h.


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