25 #include "qofmath128.h"
35 #define HIBIT (0x8000000000000000ULL)
50 guint64 sum, carry, roll, pmax;
100 prod.lo = d0 + (sum << 32);
101 prod.hi = carry + e1 + f1 + g0 + (g1 << 32);
103 prod.
isbig = prod.hi || (prod.lo >> 63);
112 guint64 sbit = x.hi & 0x1;
172 a.
isbig = (a.hi != 0) || (a.lo >> 63);
184 gint64 remainder = 0;
194 for (i = 0; i < 128; i++)
196 guint64 sbit = HIBIT & quotient.hi;
209 quotient.
isbig = (quotient.hi || (quotient.lo >> 63));
226 gint64 nn = 0x7fffffffffffffffULL & n.lo;
227 gint64 rr = 0x7fffffffffffffffULL & mu.lo;
301 guint64 gcf =
gcf64 (a, b);
314 sum.hi = a.hi + b.hi;
315 sum.lo = a.lo + b.lo;
316 if ((sum.lo < a.lo) || (sum.lo < b.lo))
320 sum.
isbig = sum.hi || (sum.lo >> 63);
323 if ((b.hi > a.hi) || ((b.hi == a.hi) && (b.lo > a.lo)))
331 sum.hi = a.hi - b.hi;
332 sum.lo = a.lo - b.lo;
339 sum.
isbig = sum.hi || (sum.lo >> 63);
344 #ifdef TEST_128_BIT_MULT
346 pr (gint64 a, gint64 b)
349 printf (
"%" G_GINT64_FORMAT
" * %" G_GINT64_FORMAT
" = %"
350 G_GUINT64_FORMAT
" %" G_GUINT64_FORMAT
" (0x%llx %llx) %hd\n", a,
351 b, prod.hi, prod.lo, prod.hi, prod.lo, prod.
isbig);
355 prd (gint64 a, gint64 b, gint64 c)
359 gint64 rem =
rem128 (prod, c);
360 printf (
"%" G_GINT64_FORMAT
" * %" G_GINT64_FORMAT
" / %"
361 G_GINT64_FORMAT
" = %" G_GUINT64_FORMAT
" %" G_GUINT64_FORMAT
362 " + %" G_GINT64_FORMAT
" (0x%llx %llx) %hd\n", a, b, c, quot.hi,
363 quot.lo, rem, quot.hi, quot.lo, quot.
isbig);
388 pr (1000000, 10000000000000);
408 n.lo = 0x6c5abefbb9e13480ULL;
410 gint64 d = 0x2ae79964d3ae1d04ULL;
413 for (i = 0; i < 20; i++)
417 printf (
"%d result = %llx %llx\n", i, quot.hi, quot.lo);