Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Static Private Attributes | List of all members
internal::fp Class Reference

#include <format-inl.h>

Public Member Functions

 fp ()
 
 fp (uint64_t f_val, int e_val)
 
template<typename Double >
 fp (Double d)
 
template<int SHIFT = 0>
void normalize ()
 
void compute_boundaries (fp &lower, fp &upper) const
 

Public Attributes

significand_type f
 
int e
 

Static Public Attributes

static FMT_CONSTEXPR_DECL const int significand_size
 

Private Types

typedef uint64_t significand_type
 

Static Private Attributes

static FMT_CONSTEXPR_DECL const int char_size
 
static FMT_CONSTEXPR_DECL const int double_significand_size
 
static FMT_CONSTEXPR_DECL const uint64_t implicit_bit
 

Detailed Description

Definition at line 353 of file format-inl.h.

Member Typedef Documentation

Definition at line 355 of file format-inl.h.

Constructor & Destructor Documentation

internal::fp::fp ( )
inline

Definition at line 374 of file format-inl.h.

374 : f(0), e(0) {}
significand_type f
Definition: format-inl.h:368
internal::fp::fp ( uint64_t  f_val,
int  e_val 
)
inline

Definition at line 375 of file format-inl.h.

375 : f(f_val), e(e_val) {}
significand_type f
Definition: format-inl.h:368
template<typename Double >
internal::fp::fp ( Double  d)
inlineexplicit

Definition at line 380 of file format-inl.h.

380  {
381  // Assume double is in the format [sign][exponent][significand].
382  typedef std::numeric_limits<Double> limits;
383  const int double_size = static_cast<int>(sizeof(Double) * char_size);
384  const int exponent_size =
385  double_size - double_significand_size - 1; // -1 for sign
386  const uint64_t significand_mask = implicit_bit - 1;
387  const uint64_t exponent_mask = (~0ull >> 1) & ~significand_mask;
388  const int exponent_bias = (1 << exponent_size) - limits::max_exponent - 1;
389  auto u = bit_cast<uint64_t>(d);
390  auto biased_e = (u & exponent_mask) >> double_significand_size;
391  f = u & significand_mask;
392  if (biased_e != 0)
393  f += implicit_bit;
394  else
395  biased_e = 1; // Subnormals use biased exponent 1 (min exponent).
396  e = static_cast<int>(biased_e - exponent_bias - double_significand_size);
397  }
static FMT_CONSTEXPR_DECL const uint64_t implicit_bit
Definition: format-inl.h:364
static FMT_CONSTEXPR_DECL const int double_significand_size
Definition: format-inl.h:362
significand_type f
Definition: format-inl.h:368
Dest bit_cast(const Source &source)
Definition: format.h:242
unsigned __int64 uint64_t
Definition: stdint.h:136
static FMT_CONSTEXPR_DECL const int char_size
Definition: format-inl.h:358

Member Function Documentation

void internal::fp::compute_boundaries ( fp lower,
fp upper 
) const
inline

Definition at line 418 of file format-inl.h.

418  {
419  lower = f == implicit_bit ?
420  fp((f << 2) - 1, e - 2) : fp((f << 1) - 1, e - 1);
421  upper = fp((f << 1) + 1, e - 1);
422  upper.normalize<1>(); // 1 is to account for the exponent shift above.
423  lower.f <<= lower.e - upper.e;
424  lower.e = upper.e;
425  }
static FMT_CONSTEXPR_DECL const uint64_t implicit_bit
Definition: format-inl.h:364
significand_type f
Definition: format-inl.h:368
template<int SHIFT = 0>
void internal::fp::normalize ( )
inline

Definition at line 401 of file format-inl.h.

401  {
402  // Handle subnormals.
403  auto shifted_implicit_bit = implicit_bit << SHIFT;
404  while ((f & shifted_implicit_bit) == 0) {
405  f <<= 1;
406  --e;
407  }
408  // Subtract 1 to account for hidden bit.
409  auto offset = significand_size - double_significand_size - SHIFT - 1;
410  f <<= offset;
411  e -= offset;
412  }
static FMT_CONSTEXPR_DECL const uint64_t implicit_bit
Definition: format-inl.h:364
static FMT_CONSTEXPR_DECL const int double_significand_size
Definition: format-inl.h:362
significand_type f
Definition: format-inl.h:368
static FMT_CONSTEXPR_DECL const int significand_size
Definition: format-inl.h:371

Member Data Documentation

FMT_CONSTEXPR_DECL const int internal::fp::char_size
staticprivate
Initial value:
=
std::numeric_limits<unsigned char>::digits

Definition at line 358 of file format-inl.h.

FMT_CONSTEXPR_DECL const int internal::fp::double_significand_size
staticprivate
Initial value:
=
std::numeric_limits<double>::digits - 1

Definition at line 362 of file format-inl.h.

int internal::fp::e

Definition at line 369 of file format-inl.h.

significand_type internal::fp::f

Definition at line 368 of file format-inl.h.

FMT_CONSTEXPR_DECL const uint64_t internal::fp::implicit_bit
staticprivate
Initial value:

Definition at line 364 of file format-inl.h.

FMT_CONSTEXPR_DECL const int internal::fp::significand_size
static
Initial value:

Definition at line 371 of file format-inl.h.


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