- uint32_t n = Prob.getNumerator();
- uint32_t d = Prob.getDenominator();
-
- assert(n <= d && "Probability must be less or equal to 1.");
-
- // Calculate Frequency * n.
- uint64_t mulLo = (Frequency & UINT32_MAX) * n;
- uint64_t mulHi = (Frequency >> 32) * n;
- uint64_t mulRes = (mulHi << 32) + mulLo;
-
- // If there was overflow use 96-bit operations.
- if (mulHi > UINT32_MAX || mulRes < mulLo) {
- // 96-bit value represented as W[1]:W[0].
- uint64_t W[2];
-
- // Probability is less or equal to 1 which means that results must fit
- // 64-bit.
- mult96bit(Frequency, n, W);
- Frequency = div96bit(W, d);
- return *this;
- }
-
- Frequency = mulRes / d;