java/dfp/src/main/java/com/epam/deltix/dfp/JavaImplRound.java [460:545]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        long /*BID_UINT128*/ P128_w0, P128_w1;

        x_sign = x & MASK_SIGN;    // 0 for positive, MASK_SIGN for negative

        // check for NaNs and infinities
        if ((x & MASK_NAN) == MASK_NAN) {    // check for NaN
            if ((x & 0x0003ffffffffffffL) >= 1000000000000000L)
                x = x & 0xfe00000000000000L;    // clear G6-G12 and the payload bits
            else
                x = x & 0xfe03ffffffffffffL;    // clear G6-G12
            if ((x & MASK_SNAN) == MASK_SNAN) {    // SNaN
                // set invalid flag
//                __set_status_flags(pfpsf, BID_INVALID_EXCEPTION);
                // return quiet (SNaN)
                res = x & 0xfdffffffffffffffL;
            } else {    // QNaN
                res = x;
            }
            return res;
        } else if ((x & MASK_INF) == MASK_INF) {    // check for Infinity
            return x_sign | 0x7800000000000000L;
        }
        // unpack x
        if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
            // if the steering bits are 11 (condition will be 0), then
            // the exponent is G[0:w+1]
            exp = (int) (((x & MASK_BINARY_EXPONENT2) >>> 51) - 398);
            C1 = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
            if (C1 > 9999999999999999L) {    // non-canonical
                C1 = 0;
            }
        } else {    // if ((x & MASK_STEERING_BITS) != MASK_STEERING_BITS)
            exp = (int) (((x & MASK_BINARY_EXPONENT1) >>> 53) - 398);
            C1 = (x & MASK_BINARY_SIG1);
        }

        // if x is 0 or non-canonical
        if (C1 == 0) {
            if (exp < 0)
                exp = 0;
            return x_sign | (((long) exp + 398) << 53);
        }
        // x is a finite non-zero number (not 0, non-canonical, or special)

        // return 0 if (exp <= -(p+1))
        if (exp <= -17) {
            return x_sign | 0x31c0000000000000L;
        }
        // q = nr. of decimal digits in x (1 <= q <= 54)
        //  determine first the nr. of bits in x
        if (UnsignedLong.isGreaterOrEqual(C1, 0x0020000000000000L)) {    // x >= 2^53
            q = 16;
        } else {    // if x < 2^53
            final long tmp1_ui64 = Double.doubleToRawLongBits((double) C1);    // exact conversion
            x_nr_bits = 1 + ((((/*unsigned*/ int) (tmp1_ui64 >>> 52)) & 0x7ff) - 0x3ff);
            q = (int) bid_nr_digits_flat[((x_nr_bits - 1) << 2) /*+ 0 .digits*/];
            if (q == 0) {
                q = (int) bid_nr_digits_flat[((x_nr_bits - 1) << 2) + 3 /*.digits1*/];
                if (UnsignedLong.isGreaterOrEqual(C1, bid_nr_digits_flat[((x_nr_bits - 1) << 2) + 2 /*.threshold_lo*/]))
                    q++;
            }
        }

        if (exp >= 0) {    // -exp <= 0
            // the argument is an integer already
            return x;
        } else if ((q + exp) >= 0) {    // exp < 0 and 1 <= -exp <= q
            // need to shift right -exp digits from the coefficient; the exp will be 0
            ind = -exp;    // 1 <= ind <= 16; ind is a synonym for 'x'
            // chop off ind digits from the lower part of C1
            // C1 = C1 + 1/2 * 10^x where the result C1 fits in 64 bits
            // FOR ROUND_TO_NEAREST, WE ADD 1/2 ULP(y) then truncate
            C1 = C1 + bid_midpoint64[ind - 1];
            // calculate C* and f*
            // C* is actually floor(C*) in this case
            // C* and f* need shifting and masking, as shown by
            // bid_shiftright128[] and bid_maskhigh128[]
            // 1 <= x <= 16
            // kx = 10^(-x) = bid_ten2mk64[ind - 1]
            // C* = (C1 + 1/2 * 10^x) * 10^(-x)
            // the approximation of 10^(-x) was rounded up to 64 bits

            //__mul_64x64_to_128(P128, C1, bid_ten2mk64[ind - 1]);
            {
                final long __CY = bid_ten2mk64[ind - 1];
                P128_w1 = Mul64Impl.unsignedMultiplyHigh(C1, __CY);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



java/dfp/src/main/java/com/epam/deltix/dfp/JavaImplRound.java [987:1072]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        long /*BID_UINT128*/ P128_w0, P128_w1;

        x_sign = x & MASK_SIGN;    // 0 for positive, MASK_SIGN for negative

        // check for NaNs and infinities
        if ((x & MASK_NAN) == MASK_NAN) {    // check for NaN
            if ((x & 0x0003ffffffffffffL) >= 1000000000000000L)
                x = x & 0xfe00000000000000L;    // clear G6-G12 and the payload bits
            else
                x = x & 0xfe03ffffffffffffL;    // clear G6-G12
            if ((x & MASK_SNAN) == MASK_SNAN) {    // SNaN
                // set invalid flag
//                __set_status_flags(pfpsf, BID_INVALID_EXCEPTION);
                // return quiet (SNaN)
                res = x & 0xfdffffffffffffffL;
            } else {    // QNaN
                res = x;
            }
            return res;
        } else if ((x & MASK_INF) == MASK_INF) {    // check for Infinity
            return x_sign | 0x7800000000000000L;
        }
        // unpack x
        if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
            // if the steering bits are 11 (condition will be 0), then
            // the exponent is G[0:w+1]
            exp = (int) (((x & MASK_BINARY_EXPONENT2) >>> 51) - 398);
            C1 = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
            if (C1 > 9999999999999999L) {    // non-canonical
                C1 = 0;
            }
        } else {    // if ((x & MASK_STEERING_BITS) != MASK_STEERING_BITS)
            exp = (int) (((x & MASK_BINARY_EXPONENT1) >>> 53) - 398);
            C1 = (x & MASK_BINARY_SIG1);
        }

        // if x is 0 or non-canonical
        if (C1 == 0) {
            if (exp < 0)
                exp = 0;
            return x_sign | (((long) exp + 398) << 53);
        }
        // x is a finite non-zero number (not 0, non-canonical, or special)

        // return 0 if (exp <= -(p+1))
        if (exp <= -17) {
            return x_sign | 0x31c0000000000000L;
        }
        // q = nr. of decimal digits in x (1 <= q <= 54)
        //  determine first the nr. of bits in x
        if (UnsignedLong.isGreaterOrEqual(C1, 0x0020000000000000L)) {    // x >= 2^53
            q = 16;
        } else {    // if x < 2^53
            final long tmp1_ui64 = Double.doubleToRawLongBits((double) C1);    // exact conversion
            x_nr_bits = 1 + ((((/*unsigned*/ int) (tmp1_ui64 >>> 52)) & 0x7ff) - 0x3ff);
            q = (int) bid_nr_digits_flat[((x_nr_bits - 1) << 2) /*+ 0 .digits*/];
            if (q == 0) {
                q = (int) bid_nr_digits_flat[((x_nr_bits - 1) << 2) + 3 /*.digits1*/];
                if (UnsignedLong.isGreaterOrEqual(C1, bid_nr_digits_flat[((x_nr_bits - 1) << 2) + 2 /*.threshold_lo*/]))
                    q++;
            }
        }

        if (exp >= 0) {    // -exp <= 0
            // the argument is an integer already
            return x;
        } else if ((q + exp) >= 0) {    // exp < 0 and 1 <= -exp <= q
            // need to shift right -exp digits from the coefficient; the exp will be 0
            ind = -exp;    // 1 <= ind <= 16; ind is a synonym for 'x'
            // chop off ind digits from the lower part of C1
            // C1 = C1 + 1/2 * 10^x where the result C1 fits in 64 bits
            // FOR ROUND_TO_NEAREST, WE ADD 1/2 ULP(y) then truncate
            C1 = C1 + bid_midpoint64[ind - 1];
            // calculate C* and f*
            // C* is actually floor(C*) in this case
            // C* and f* need shifting and masking, as shown by
            // bid_shiftright128[] and bid_maskhigh128[]
            // 1 <= x <= 16
            // kx = 10^(-x) = bid_ten2mk64[ind - 1]
            // C* = (C1 + 1/2 * 10^x) * 10^(-x)
            // the approximation of 10^(-x) was rounded up to 64 bits

            //__mul_64x64_to_128(P128, C1, bid_ten2mk64[ind - 1]);
            {
                final long __CY = bid_ten2mk64[ind - 1];
                P128_w1 = Mul64Impl.unsignedMultiplyHigh(C1, __CY);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



