29 #ifndef XAPIAN_UNITTEST 30 # define UNITTEST_ASSERT_NOTHROW(COND,RET) 42 # error Code currently assumes FLT_RADIX == 2 47 # pragma warning(disable:4146) 56 if (
rare(!isfinite(value))) {
63 memset(buf,
'\xff', 9);
69 double mantissa = frexp(value, &exponent);
79 if (mantissa == 0.0 ||
rare(exponent < -2039)) {
84 if (
rare(exponent > 2055)) {
86 goto handle_as_infinity;
89 bool negative = (mantissa < 0);
90 if (negative) mantissa = -mantissa;
100 unsigned char next = (negative ? 0 : 0xe0);
104 bool exponent_negative = (exponent < 0);
105 if (exponent_negative) {
106 exponent = -exponent;
123 next |=
static_cast<unsigned char>(exponent << 2);
124 if (negative ^ exponent_negative) next ^= 0x1c;
129 next |=
static_cast<unsigned char>(exponent >> 6);
130 if (negative ^ exponent_negative) next ^= 0x1f;
134 next =
static_cast<unsigned char>(exponent << 2);
135 if (negative ^ exponent_negative) next ^= 0xfc;
139 mantissa *= 1 << (negative ? 26 : 27);
140 unsigned word1 =
static_cast<unsigned>(mantissa);
142 unsigned word2 =
static_cast<unsigned>(mantissa * 4294967296.0);
155 if (word2 != 0) ++word1;
160 next |=
static_cast<unsigned char>(word1 >> 24);
162 buf[len++] = char(word1 >> 16);
163 buf[len++] = char(word1 >> 8);
164 buf[len++] = char(word1);
166 buf[len++] = char(word2 >> 24);
167 buf[len++] = char(word2 >> 16);
168 buf[len++] = char(word2 >> 8);
169 buf[len++] = char(word2);
172 while (len > 0 && buf[len - 1] ==
'\0') {
181 static inline unsigned char 184 return (pos < str.size()) ? static_cast<unsigned char>(str[pos]) :
'\0';
191 if (value.size() == 1 && value[0] ==
'\x80')
return 0.0;
194 if (value.size() == 9 &&
195 memcmp(value.data(),
"\xff\xff\xff\xff\xff\xff\xff\xff\xff", 9) == 0) {
210 first ^=
static_cast<unsigned char>(first & 0xc0) >> 1;
211 bool negative = !(first & 0x80);
212 bool exponent_negative = (first & 0x40);
213 bool explen = !(first & 0x20);
214 int exponent = first & 0x1f;
217 if (negative ^ exponent_negative) exponent ^= 0x07;
221 exponent |= (first >> 2);
222 if (negative ^ exponent_negative) exponent ^= 0x07ff;
226 word1 = (unsigned(first & 0x03) << 24);
232 if (i < value.size()) {
241 if (word2 != 0) ++word1;
246 if (!negative) word1 |= 1<<26;
249 if (word2) mantissa = word2 / 4294967296.0;
251 mantissa /= 1 << (negative ? 26 : 27);
253 if (exponent_negative) exponent = -exponent;
256 if (negative) mantissa = -mantissa;
263 return scalbn(mantissa, exponent);
size_t sortable_serialise_(double value, char *buf)
string str(int value)
Convert int to std::string.
static unsigned char numfromstr(const std::string &str, std::string::size_type pos)
Get a number from the character at a given position in a string, returning 0 if the string isn't long...
double sortable_unserialise(const std::string &serialised)
Convert a string encoded using sortable_serialise back to a floating point number.
#define UNITTEST_ASSERT_NOTHROW(COND, RET)
parsing a user query string to build a Xapian::Query object