29 #ifndef XAPIAN_UNITTEST 30 # define UNITTEST_ASSERT_NOTHROW(COND,RET) 42 # error Code currently assumes FLT_RADIX == 2 47 # pragma warning(disable:4146) 57 if (value < -DBL_MAX)
return 0;
59 mantissa = frexp(value, &exponent);
69 if (mantissa == 0.0 || exponent < -2039) {
74 bool negative = (mantissa < 0);
75 if (negative) mantissa = -mantissa;
78 if (value > DBL_MAX || exponent > 2055) {
84 memset(buf,
'\xff', 9);
97 unsigned char next = (negative ? 0 : 0xe0);
101 bool exponent_negative = (exponent < 0);
102 if (exponent_negative) {
103 exponent = -exponent;
120 next |=
static_cast<unsigned char>(exponent << 2);
121 if (negative ^ exponent_negative) next ^= 0x1c;
126 next |=
static_cast<unsigned char>(exponent >> 6);
127 if (negative ^ exponent_negative) next ^= 0x1f;
131 next =
static_cast<unsigned char>(exponent << 2);
132 if (negative ^ exponent_negative) next ^= 0xfc;
136 mantissa *= 1 << (negative ? 26 : 27);
137 unsigned word1 =
static_cast<unsigned>(mantissa);
139 unsigned word2 =
static_cast<unsigned>(mantissa * 4294967296.0);
152 if (word2 != 0) ++word1;
157 next |=
static_cast<unsigned char>(word1 >> 24);
159 buf[len++] = char(word1 >> 16);
160 buf[len++] = char(word1 >> 8);
161 buf[len++] = char(word1);
163 buf[len++] = char(word2 >> 24);
164 buf[len++] = char(word2 >> 16);
165 buf[len++] = char(word2 >> 8);
166 buf[len++] = char(word2);
169 while (len > 0 && buf[len - 1] ==
'\0') {
178 static inline unsigned char 181 return (pos < str.size()) ? static_cast<unsigned char>(str[pos]) :
'\0';
188 if (value.size() == 1 && value[0] ==
'\x80')
return 0.0;
191 if (value.size() == 9 &&
192 memcmp(value.data(),
"\xff\xff\xff\xff\xff\xff\xff\xff\xff", 9) == 0) {
207 first ^=
static_cast<unsigned char>(first & 0xc0) >> 1;
208 bool negative = !(first & 0x80);
209 bool exponent_negative = (first & 0x40);
210 bool explen = !(first & 0x20);
211 int exponent = first & 0x1f;
214 if (negative ^ exponent_negative) exponent ^= 0x07;
218 exponent |= (first >> 2);
219 if (negative ^ exponent_negative) exponent ^= 0x07ff;
223 word1 = (unsigned(first & 0x03) << 24);
229 if (i < value.size()) {
238 if (word2 != 0) ++word1;
243 if (!negative) word1 |= 1<<26;
246 if (word2) mantissa = word2 / 4294967296.0;
248 mantissa /= 1 << (negative ? 26 : 27);
250 if (exponent_negative) exponent = -exponent;
253 if (negative) mantissa = -mantissa;
260 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