20#ifndef RAPIDJSON_DIYFP_H_
21#define RAPIDJSON_DIYFP_H_
23#include "../rapidjson.h"
27#if defined(_MSC_VER) && defined(_M_AMD64) && !defined(__INTEL_COMPILER)
29#pragma intrinsic(_umul128)
37RAPIDJSON_DIAG_OFF(effc++)
42RAPIDJSON_DIAG_OFF(padded)
50 explicit DiyFp(
double d) {
56 int biased_e =
static_cast<int>((u.u64 & kDpExponentMask) >> kDpSignificandSize);
57 uint64_t significand = (u.u64 & kDpSignificandMask);
59 f = significand + kDpHiddenBit;
60 e = biased_e - kDpExponentBias;
64 e = kDpMinExponent + 1;
69 return DiyFp(f - rhs.f, e);
73#if defined(_MSC_VER) && defined(_M_AMD64)
78 return DiyFp(h, e + rhs.e + 64);
79#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) && !defined(__NVCOMPILER)
80 __extension__
typedef unsigned __int128 uint128;
81 uint128 p =
static_cast<uint128
>(f) *
static_cast<uint128
>(rhs.f);
86 return DiyFp(h, e + rhs.e + 64);
97 uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32);
99 return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64);
103 DiyFp Normalize()
const {
104 int s =
static_cast<int>(RAPIDJSON_CLZLL(f));
105 return DiyFp(f << s, e - s);
108 DiyFp NormalizeBoundary()
const {
110 while (!(res.f & (kDpHiddenBit << 1))) {
114 res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
115 res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
119 void NormalizedBoundaries(DiyFp* minus, DiyFp* plus)
const {
120 DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary();
121 DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1);
122 mi.f <<= mi.e - pl.e;
128 double ToDouble()
const {
134 if (e < kDpDenormalExponent) {
138 if (e >= kDpMaxExponent) {
140 return std::numeric_limits<double>::infinity();
142 const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 :
143 static_cast<uint64_t>(e + kDpExponentBias);
144 u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize);
148 static const int kDiySignificandSize = 64;
149 static const int kDpSignificandSize = 52;
150 static const int kDpExponentBias = 0x3FF + kDpSignificandSize;
151 static const int kDpMaxExponent = 0x7FF - kDpExponentBias;
152 static const int kDpMinExponent = -kDpExponentBias;
153 static const int kDpDenormalExponent = -kDpExponentBias + 1;
162inline DiyFp GetCachedPowerByIndex(
size_t index) {
164 static const uint64_t kCachedPowers_F[] = {
210 static const int16_t kCachedPowers_E[] = {
211 -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,
212 -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,
213 -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,
214 -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,
215 -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,
216 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,
217 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,
218 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,
219 907, 933, 960, 986, 1013, 1039, 1066
222 return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
225inline DiyFp GetCachedPower(
int e,
int* K) {
228 double dk = (-61 - e) * 0.30102999566398114 + 347;
229 int k =
static_cast<int>(dk);
233 unsigned index =
static_cast<unsigned>((k >> 3) + 1);
234 *K = -(-348 +
static_cast<int>(index << 3));
236 return GetCachedPowerByIndex(index);
239inline DiyFp GetCachedPower10(
int exp,
int *outExp) {
241 unsigned index =
static_cast<unsigned>(
exp + 348) / 8u;
242 *outExp = -348 +
static_cast<int>(index) * 8;
243 return GetCachedPowerByIndex(index);
252RAPIDJSON_DIAG_OFF(padded)
Lecteur des fichiers de maillage via la bibliothèque LIMA.
#define RAPIDJSON_ASSERT(x)
Assertion.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
ARCCORE_HOST_DEVICE double exp(double v)
Exponentielle de v.
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
DiyFp operator*(const DiyFp &rhs) const