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

#include <diy-fp.h>

Public Member Functions

 DiyFp ()
 
 DiyFp (const uint64_t significand, const int32_t exponent)
 
void Subtract (const DiyFp &other)
 
void Multiply (const DiyFp &other)
 
void Normalize ()
 
uint64_t f () const
 
int32_t e () const
 
void set_f (uint64_t new_value)
 
void set_e (int32_t new_value)
 

Static Public Member Functions

static DiyFp Minus (const DiyFp &a, const DiyFp &b)
 
static DiyFp Times (const DiyFp &a, const DiyFp &b)
 
static DiyFp Normalize (const DiyFp &a)
 

Static Public Attributes

static const int kSignificandSize = 64
 

Detailed Description

Definition at line 41 of file diy-fp.h.

Constructor & Destructor Documentation

◆ DiyFp() [1/2]

double_conversion::DiyFp::DiyFp ( )
inline

Definition at line 45 of file diy-fp.h.

45: f_(0), e_(0) {}

◆ DiyFp() [2/2]

double_conversion::DiyFp::DiyFp ( const uint64_t  significand,
const int32_t  exponent 
)
inline

Definition at line 46 of file diy-fp.h.

46: f_(significand), e_(exponent) {}

Member Function Documentation

◆ e()

int32_t double_conversion::DiyFp::e ( ) const
inline

Definition at line 123 of file diy-fp.h.

123{ return e_; }

◆ f()

uint64_t double_conversion::DiyFp::f ( ) const
inline

Definition at line 122 of file diy-fp.h.

122{ return f_; }

◆ Minus()

static DiyFp double_conversion::DiyFp::Minus ( const DiyFp a,
const DiyFp b 
)
inlinestatic

Definition at line 61 of file diy-fp.h.

61 {
62 DiyFp result = a;
63 result.Subtract(b);
64 return result;
65 }
static bool b
struct MyStruct a[10]
GAsyncResult * result

◆ Multiply()

void double_conversion::DiyFp::Multiply ( const DiyFp other)
inline

Definition at line 68 of file diy-fp.h.

68 {
69 // Simply "emulates" a 128 bit multiplication.
70 // However: the resulting number only contains 64 bits. The least
71 // significant 64 bits are only used for rounding the most significant 64
72 // bits.
73 const uint64_t kM32 = 0xFFFFFFFFU;
74 const uint64_t a = f_ >> 32;
75 const uint64_t b = f_ & kM32;
76 const uint64_t c = other.f_ >> 32;
77 const uint64_t d = other.f_ & kM32;
78 const uint64_t ac = a * c;
79 const uint64_t bc = b * c;
80 const uint64_t ad = a * d;
81 const uint64_t bd = b * d;
82 // By adding 1U << 31 to tmp we round the final result.
83 // Halfway cases will be rounded up.
84 const uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32) + (1U << 31);
85 e_ += other.e_ + 64;
86 f_ = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
87 }
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19

◆ Normalize() [1/2]

void double_conversion::DiyFp::Normalize ( )
inline

Definition at line 96 of file diy-fp.h.

96 {
98 uint64_t significand = f_;
99 int32_t exponent = e_;
100
101 // This method is mainly called for normalizing boundaries. In general,
102 // boundaries need to be shifted by 10 bits, and we optimize for this case.
103 const uint64_t k10MSBits = DOUBLE_CONVERSION_UINT64_2PART_C(0xFFC00000, 00000000);
104 while ((significand & k10MSBits) == 0) {
105 significand <<= 10;
106 exponent -= 10;
107 }
108 while ((significand & kUint64MSB) == 0) {
109 significand <<= 1;
110 exponent--;
111 }
112 f_ = significand;
113 e_ = exponent;
114 }
#define DOUBLE_CONVERSION_ASSERT(condition)
Definition: utils.h:46
#define DOUBLE_CONVERSION_UINT64_2PART_C(a, b)
Definition: utils.h:195

◆ Normalize() [2/2]

static DiyFp double_conversion::DiyFp::Normalize ( const DiyFp a)
inlinestatic

Definition at line 116 of file diy-fp.h.

116 {
117 DiyFp result = a;
118 result.Normalize();
119 return result;
120 }

◆ set_e()

void double_conversion::DiyFp::set_e ( int32_t  new_value)
inline

Definition at line 126 of file diy-fp.h.

126{ e_ = new_value; }

◆ set_f()

void double_conversion::DiyFp::set_f ( uint64_t  new_value)
inline

Definition at line 125 of file diy-fp.h.

125{ f_ = new_value; }

◆ Subtract()

void double_conversion::DiyFp::Subtract ( const DiyFp other)
inline

Definition at line 52 of file diy-fp.h.

52 {
53 DOUBLE_CONVERSION_ASSERT(e_ == other.e_);
54 DOUBLE_CONVERSION_ASSERT(f_ >= other.f_);
55 f_ -= other.f_;
56 }

◆ Times()

static DiyFp double_conversion::DiyFp::Times ( const DiyFp a,
const DiyFp b 
)
inlinestatic

Definition at line 90 of file diy-fp.h.

90 {
91 DiyFp result = a;
92 result.Multiply(b);
93 return result;
94 }

Member Data Documentation

◆ kSignificandSize

const int double_conversion::DiyFp::kSignificandSize = 64
static

Definition at line 43 of file diy-fp.h.


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