All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
nlohmann::detail::dtoa_impl::diyfp Struct Reference

#include <json.hpp>

Public Member Functions

constexpr diyfp (std::uint64_t f_, int e_) noexcept
 

Static Public Member Functions

static diyfp sub (const diyfp &x, const diyfp &y) noexcept
 returns x - y More...
 
static diyfp mul (const diyfp &x, const diyfp &y) noexcept
 returns x * y More...
 
static diyfp normalize (diyfp x) noexcept
 normalize x such that the significand is >= 2^(q-1) More...
 
static diyfp normalize_to (const diyfp &x, const int target_exponent) noexcept
 normalize x such that the result has the exponent E More...
 

Public Attributes

std::uint64_t f = 0
 
int e = 0
 

Static Public Attributes

static constexpr int kPrecision = 64
 

Detailed Description

Definition at line 12699 of file json.hpp.

Constructor & Destructor Documentation

constexpr nlohmann::detail::dtoa_impl::diyfp::diyfp ( std::uint64_t  f_,
int  e_ 
)
inlinenoexcept

Definition at line 12706 of file json.hpp.

Member Function Documentation

static diyfp nlohmann::detail::dtoa_impl::diyfp::mul ( const diyfp x,
const diyfp y 
)
inlinestaticnoexcept

returns x * y

Note
The result is rounded. (Only the upper q bits are returned.)

Definition at line 12724 of file json.hpp.

12725  {
12726  static_assert(kPrecision == 64, "internal error");
12727 
12728  // Computes:
12729  // f = round((x.f * y.f) / 2^q)
12730  // e = x.e + y.e + q
12731 
12732  // Emulate the 64-bit * 64-bit multiplication:
12733  //
12734  // p = u * v
12735  // = (u_lo + 2^32 u_hi) (v_lo + 2^32 v_hi)
12736  // = (u_lo v_lo ) + 2^32 ((u_lo v_hi ) + (u_hi v_lo )) + 2^64 (u_hi v_hi )
12737  // = (p0 ) + 2^32 ((p1 ) + (p2 )) + 2^64 (p3 )
12738  // = (p0_lo + 2^32 p0_hi) + 2^32 ((p1_lo + 2^32 p1_hi) + (p2_lo + 2^32 p2_hi)) + 2^64 (p3 )
12739  // = (p0_lo ) + 2^32 (p0_hi + p1_lo + p2_lo ) + 2^64 (p1_hi + p2_hi + p3)
12740  // = (p0_lo ) + 2^32 (Q ) + 2^64 (H )
12741  // = (p0_lo ) + 2^32 (Q_lo + 2^32 Q_hi ) + 2^64 (H )
12742  //
12743  // (Since Q might be larger than 2^32 - 1)
12744  //
12745  // = (p0_lo + 2^32 Q_lo) + 2^64 (Q_hi + H)
12746  //
12747  // (Q_hi + H does not overflow a 64-bit int)
12748  //
12749  // = p_lo + 2^64 p_hi
12750 
12751  const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
12752  const std::uint64_t u_hi = x.f >> 32u;
12753  const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
12754  const std::uint64_t v_hi = y.f >> 32u;
12755 
12756  const std::uint64_t p0 = u_lo * v_lo;
12757  const std::uint64_t p1 = u_lo * v_hi;
12758  const std::uint64_t p2 = u_hi * v_lo;
12759  const std::uint64_t p3 = u_hi * v_hi;
12760 
12761  const std::uint64_t p0_hi = p0 >> 32u;
12762  const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
12763  const std::uint64_t p1_hi = p1 >> 32u;
12764  const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
12765  const std::uint64_t p2_hi = p2 >> 32u;
12766 
12767  std::uint64_t Q = p0_hi + p1_lo + p2_lo;
12768 
12769  // The full product might now be computed as
12770  //
12771  // p_hi = p3 + p2_hi + p1_hi + (Q >> 32)
12772  // p_lo = p0_lo + (Q << 32)
12773  //
12774  // But in this particular case here, the full p_lo is not required.
12775  // Effectively we only need to add the highest bit in p_lo to p_hi (and
12776  // Q_hi + 1 does not overflow).
12777 
12778  Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up
12779 
12780  const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
12781 
12782  return {h, x.e + y.e + 64};
12783  }
process_name opflash particleana ie x
while getopts h
static constexpr int kPrecision
Definition: json.hpp:12701
process_name opflash particleana ie ie y
physics associatedGroupsWithLeft p1
static diyfp nlohmann::detail::dtoa_impl::diyfp::normalize ( diyfp  x)
inlinestaticnoexcept

normalize x such that the significand is >= 2^(q-1)

Precondition
x.f != 0

Definition at line 12789 of file json.hpp.

12790  {
12791  assert(x.f != 0);
12792 
12793  while ((x.f >> 63u) == 0)
12794  {
12795  x.f <<= 1u;
12796  x.e--;
12797  }
12798 
12799  return x;
12800  }
process_name opflash particleana ie x
static diyfp nlohmann::detail::dtoa_impl::diyfp::normalize_to ( const diyfp x,
const int  target_exponent 
)
inlinestaticnoexcept

normalize x such that the result has the exponent E

Precondition
e >= x.e and the upper e - x.e bits of x.f must be zero.

Definition at line 12806 of file json.hpp.

12807  {
12808  const int delta = x.e - target_exponent;
12809 
12810  assert(delta >= 0);
12811  assert(((x.f << delta) >> delta) == x.f);
12812 
12813  return {x.f << delta, target_exponent};
12814  }
process_name opflash particleana ie x
static diyfp nlohmann::detail::dtoa_impl::diyfp::sub ( const diyfp x,
const diyfp y 
)
inlinestaticnoexcept

returns x - y

Precondition
x.e == y.e and x.f >= y.f

Definition at line 12712 of file json.hpp.

12713  {
12714  assert(x.e == y.e);
12715  assert(x.f >= y.f);
12716 
12717  return {x.f - y.f, x.e};
12718  }
process_name opflash particleana ie x
process_name opflash particleana ie ie y

Member Data Documentation

int nlohmann::detail::dtoa_impl::diyfp::e = 0

Definition at line 12704 of file json.hpp.

std::uint64_t nlohmann::detail::dtoa_impl::diyfp::f = 0

Definition at line 12703 of file json.hpp.

constexpr int nlohmann::detail::dtoa_impl::diyfp::kPrecision = 64
static

Definition at line 12701 of file json.hpp.


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