34#ifdef ECL_RAW_DATA_HADRON_STANDALONE_BUILD
36 printf(
"%s:%d: Error! Amplitude can never be negative, you have to call this function as packAmplitude(peak_amp + 128).\n",
41 B2FATAL(
"Amplitude can never be negative, you have to call this function as packAmplitude(peak_amp + 128).");
44 unsigned long long exponent;
45 unsigned long long fraction;
46 unsigned long long amp_packed = 0;
51 if ((fraction & 0x20000) != 0)
53 else if ((fraction & 0x10000) != 0)
55 else if ((fraction & 0x08000) != 0)
57 else if ((fraction & 0x04000) != 0)
59 else if ((fraction & 0x02000) != 0)
61 else if ((fraction & 0x01000) != 0)
63 else if ((fraction & 0x00800) != 0)
70 fraction += 1 << (exponent - 2);
71 fraction = (fraction >> (exponent - 1)) - (1 << 11);
80 if ((fraction & 0x00800) != 0)
83 amp_packed = (exponent << 11) | fraction;
108 unsigned int exponent = 0;
109 unsigned int sign = 0;
110 int fraction = peak_time;
111 if ((fraction & 0x800) != 0) {
113 fraction = -fraction;
116 if ((fraction & 0x400) != 0)
118 else if ((fraction & 0x200) != 0)
120 else if ((fraction & 0x100) != 0)
130 fraction += 1 << (exponent - 2);
132 fraction = (fraction >> (exponent - 1)) - (1 << 8);
146 if ((fraction & 0x100) != 0)
150 int peak_time_packed = (sign << 10) | (exponent << 8) | fraction;
151 return peak_time_packed;
223 if (dividend >= (1 << 18) || dividend < 0) {
224 fprintf(stderr,
"\n\033[31m");
225 fprintf(stderr,
"%s:%d: Error! Dividend outside of expected range: %d\n", __FILE__, __LINE__, dividend);
226 fprintf(stderr,
"\033[0m\n");
229 if (divisor >= (1 << 19)) {
230 fprintf(stderr,
"\n\033[31m");
231 fprintf(stderr,
"%s:%d: Error! Divisor outside of expected range: %d\n", __FILE__, __LINE__, divisor);
232 fprintf(stderr,
"\033[0m\n");
245 if ((divisor & (1 << i)) != 0) {
274 dividend = dividend << 5;
276 int n_S = dividend >> p;
277 int m_S = divisor >> p;
280 const int precalculated_constants[] = {
283 2016, 1956, 1900, 1846, 1796, 1748, 1702, 1659,
284 1618, 1579, 1542, 1507, 1473, 1440, 1409, 1380,
285 1351, 1324, 1298, 1273, 1248, 1225, 1202, 1181,
286 1160, 1140, 1120, 1101, 1083, 1066, 1049, 1032
295 return ((n_S + m_S / 2) * precalculated_constants[m_S - 32]) >> 16;