diff --git a/src/bid128_add.rs b/src/bid128_add.rs index 208282c..d5a6fd0 100644 --- a/src/bid128_add.rs +++ b/src/bid128_add.rs @@ -350,7 +350,7 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo res.w[1] = if x_exp < y_exp { x_exp } else { y_exp }; if x_sign != 0 && y_sign != 0 { res.w[1] |= x_sign; // both negative - } else if rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != y_sign { + } else if rnd_mode == RoundingMode::Downward && x_sign != y_sign { res.w[1] |= 0x8000000000000000u64; // -0 } // else; // res = +0 @@ -614,8 +614,8 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo // subtract 1 ulp // Note: do this only for rounding to nearest; for other rounding // modes the correction will be applied next - if (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST - || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY) && delta == (P34 + 1) + if (rnd_mode == RoundingMode::NearestEven + || rnd_mode == RoundingMode::NearestAway) && delta == (P34 + 1) && C1_hi == 0x0000314dc6448d93u64 && C1_lo == 0x38c15b0a00000000u64 && x_sign != y_sign && ((q2 <= 19 && C2_lo > BID_MIDPOINT64[(q2 - 1) as usize]) || (q2 >= 20 && (C2_hi > BID_MIDPOINT128[(q2 - 20) as usize].w[1] @@ -626,9 +626,9 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_lo = 0x378d8e63ffffffffu64; x_exp -= EXP_P1; } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { - if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0 && y_sign == 0) { + if rnd_mode != RoundingMode::NearestEven { + if (rnd_mode == RoundingMode::Downward && x_sign != 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign == 0 && y_sign == 0) { // add 1 ulp and then check for overflow C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -647,9 +647,9 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo *pfpsf |= StatusFlags::BID_OVERFLOW_EXCEPTION; } } - } else if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign == 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign != 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO && x_sign != y_sign) { + } else if (rnd_mode == RoundingMode::Downward && x_sign == 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign != 0 && y_sign == 0) + || (rnd_mode == RoundingMode::TowardZero && x_sign != y_sign) { // subtract 1 ulp from C1 // Note: because delta >= P34 + 1 the result cannot be zero C1_lo -= 1; @@ -719,9 +719,9 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_hi = C1.w[1]; C1_lo = C1.w[0]; } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { - if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0 && y_sign != 0) || - (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0 && y_sign == 0) { + if rnd_mode != RoundingMode::NearestEven { + if (rnd_mode == RoundingMode::Downward && x_sign != 0 && y_sign != 0) || + (rnd_mode == RoundingMode::Upward && x_sign == 0 && y_sign == 0) { // add 1 ulp and then check for overflow C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -740,9 +740,9 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo *pfpsf |= StatusFlags::BID_OVERFLOW_EXCEPTION; } } - } else if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign == 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign != 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO && x_sign != y_sign) { + } else if (rnd_mode == RoundingMode::Downward && x_sign == 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign != 0 && y_sign == 0) + || (rnd_mode == RoundingMode::TowardZero && x_sign != y_sign) { // subtract 1 ulp from C1 // Note: because delta >= P34 + 1 the result cannot be zero C1_lo -= 1; @@ -799,10 +799,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_hi = C1.w[1]; C1_lo = C1.w[0]; } - if (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && x_sign == y_sign && (C1_lo & 0x01) == 0x01) - || (rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY && x_sign == y_sign) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0 && y_sign != 0) { + if (rnd_mode == RoundingMode::NearestEven && x_sign == y_sign && (C1_lo & 0x01) == 0x01) + || (rnd_mode == RoundingMode::NearestAway && x_sign == y_sign) + || (rnd_mode == RoundingMode::Upward && x_sign == 0 && y_sign == 0) + || (rnd_mode == RoundingMode::Downward && x_sign != 0 && y_sign != 0) { // add 1 ulp and then check for overflow C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -821,10 +821,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo *pfpsf |= StatusFlags::BID_OVERFLOW_EXCEPTION; } } - } else if (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && x_sign != y_sign && (C1_lo & 0x01) == 0x01) - || (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign == 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign != 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO && x_sign != y_sign) { + } else if (rnd_mode == RoundingMode::NearestEven && x_sign != y_sign && (C1_lo & 0x01) == 0x01) + || (rnd_mode == RoundingMode::Downward && x_sign == 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign != 0 && y_sign == 0) + || (rnd_mode == RoundingMode::TowardZero && x_sign != y_sign) { // subtract 1 ulp from C1 // Note: because delta >= P34 + 1 the result cannot be zero C1_lo -= 1; @@ -888,11 +888,11 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo x_exp += EXP_P1; } } - if (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && x_sign != y_sign) - || (rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY && x_sign != y_sign && C2_lo != halfulp64) - || (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign == 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign != 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO && x_sign != y_sign) { + if (rnd_mode == RoundingMode::NearestEven && x_sign != y_sign) + || (rnd_mode == RoundingMode::NearestAway && x_sign != y_sign && C2_lo != halfulp64) + || (rnd_mode == RoundingMode::Downward && x_sign == 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign != 0 && y_sign == 0) + || (rnd_mode == RoundingMode::TowardZero && x_sign != y_sign) { // the result is x - 1 // for RN n1 * n2 < 0; underflow not possible C1_lo -= 1; @@ -905,10 +905,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_lo = 0x378d8e63ffffffffu64; x_exp -= EXP_P1; // no underflow, because n1 >> n2 } - } else if (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && x_sign == y_sign) - || (rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY && x_sign == y_sign) - || (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0 && y_sign == 0) { + } else if (rnd_mode == RoundingMode::NearestEven && x_sign == y_sign) + || (rnd_mode == RoundingMode::NearestAway && x_sign == y_sign) + || (rnd_mode == RoundingMode::Downward && x_sign != 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign == 0 && y_sign == 0) { // the result is x + 1 // for RN x_sign = y_sign, i.e. n1*n2 > 0 C1_lo += 1; @@ -970,9 +970,9 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_lo = C1.w[0]; x_exp -= (scale as BID_UINT64) << 49; } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { - if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0 && y_sign == 0) { + if rnd_mode != RoundingMode::NearestEven { + if (rnd_mode == RoundingMode::Downward && x_sign != 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign == 0 && y_sign == 0) { // add 1 ulp and then check for overflow C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -991,9 +991,9 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo *pfpsf |= StatusFlags::BID_OVERFLOW_EXCEPTION; } } - } else if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign == 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign != 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO && x_sign != y_sign) { + } else if (rnd_mode == RoundingMode::Downward && x_sign == 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign != 0 && y_sign == 0) + || (rnd_mode == RoundingMode::TowardZero && x_sign != y_sign) { // subtract 1 ulp from C1 // Note: because delta >= P34 + 1 the result cannot be zero C1_lo -= 1; @@ -1052,10 +1052,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_hi = C1.w[1]; C1_lo = C1.w[0]; } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { - if (rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY && x_sign == y_sign) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0 && y_sign != 0) { + if rnd_mode != RoundingMode::NearestEven { + if (rnd_mode == RoundingMode::NearestAway && x_sign == y_sign) + || (rnd_mode == RoundingMode::Upward && x_sign == 0 && y_sign == 0) + || (rnd_mode == RoundingMode::Downward && x_sign != 0 && y_sign != 0) { // add 1 ulp and then check for overflow C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -1074,9 +1074,9 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo *pfpsf |= StatusFlags::BID_OVERFLOW_EXCEPTION; } } - } else if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign == 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign != 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO && x_sign != y_sign) { + } else if (rnd_mode == RoundingMode::Downward && x_sign == 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign != 0 && y_sign == 0) + || (rnd_mode == RoundingMode::TowardZero && x_sign != y_sign) { // subtract 1 ulp from C1 // Note: because delta >= P34 + 1 the result cannot be zero C1_lo -= 1; @@ -1134,11 +1134,11 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_lo = C1.w[0]; x_exp -= (scale as BID_UINT64) << 49; } - if (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && x_sign != y_sign) - || (rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY && x_sign != y_sign && (C2_hi != halfulp128.w[1] || C2_lo != halfulp128.w[0])) - || (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign == 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign != 0 && y_sign == 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO && x_sign != y_sign) { + if (rnd_mode == RoundingMode::NearestEven && x_sign != y_sign) + || (rnd_mode == RoundingMode::NearestAway && x_sign != y_sign && (C2_hi != halfulp128.w[1] || C2_lo != halfulp128.w[0])) + || (rnd_mode == RoundingMode::Downward && x_sign == 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign != 0 && y_sign == 0) + || (rnd_mode == RoundingMode::TowardZero && x_sign != y_sign) { // the result is x - 1 // for RN n1 * n2 < 0; underflow not possible C1_lo -= 1; @@ -1151,10 +1151,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_lo = 0x378d8e63ffffffffu64; x_exp -= EXP_P1; // no underflow, because n1 >> n2 } - } else if (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && x_sign == y_sign) - || (rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY && x_sign == y_sign) - || (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0 && y_sign != 0) - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0 && y_sign == 0) { + } else if (rnd_mode == RoundingMode::NearestEven && x_sign == y_sign) + || (rnd_mode == RoundingMode::NearestAway && x_sign == y_sign) + || (rnd_mode == RoundingMode::Downward && x_sign != 0 && y_sign != 0) + || (rnd_mode == RoundingMode::Upward && x_sign == 0 && y_sign == 0) { // the result is x + 1 // for RN x_sign = y_sign, i.e. n1*n2 > 0 C1_lo += 1; @@ -1420,13 +1420,13 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_hi = C1.w[1]; C1_lo = C1.w[0]; // general correction from RN to RA, RM, RP, RZ; result uses y_exp - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { - if (x_sign == 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_UP && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_UP) && is_midpoint_gt_even))) - || (x_sign != 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_DOWN && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_DOWN) && is_midpoint_gt_even))) { + if rnd_mode != RoundingMode::NearestEven { + if (x_sign == 0 && ((rnd_mode == RoundingMode::Upward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Upward) && is_midpoint_gt_even))) + || (x_sign != 0 && ((rnd_mode == RoundingMode::Downward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Downward) && is_midpoint_gt_even))) { // C1 = C1 + 1 C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -1439,10 +1439,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo y_exp += EXP_P1; } } else if (is_midpoint_lt_even || is_inexact_gt_midpoint) - && ((x_sign != 0 && (rnd_mode == RoundingMode::BID_ROUNDING_UP - || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO)) - || (x_sign != 0 && (rnd_mode == RoundingMode::BID_ROUNDING_DOWN - || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO))) { + && ((x_sign != 0 && (rnd_mode == RoundingMode::Upward + || rnd_mode == RoundingMode::TowardZero)) + || (x_sign != 0 && (rnd_mode == RoundingMode::Downward + || rnd_mode == RoundingMode::TowardZero))) { // C1 = C1 - 1 C1_lo -= 1; if C1_lo == 0xffffffffffffffffu64 { @@ -1511,7 +1511,7 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo // assemble the result res.w[1] = if x_exp < y_exp { x_exp } else { y_exp }; res.w[0] = 0; - if rnd_mode == RoundingMode::BID_ROUNDING_DOWN { + if rnd_mode == RoundingMode::Downward { res.w[1] |= 0x8000000000000000u64; } @@ -1620,8 +1620,8 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo y_exp += EXP_P1; // C* != 10^P because C* has P34 digits // check for overflow - if y_exp == EXP_MAX_P1 && (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST - || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY) { + if y_exp == EXP_MAX_P1 && (rnd_mode == RoundingMode::NearestEven + || rnd_mode == RoundingMode::NearestAway) { // overflow for RN res.w[1] = x_sign | 0x7800000000000000u64; // +/-inf res.w[0] = 0x0u64; @@ -1661,13 +1661,13 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo } // general correction from RN to RA, RM, RP, RZ; // result uses y_exp - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { - if (x_sign == 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_UP && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_UP) && is_midpoint_gt_even))) - || (x_sign != 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_DOWN && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_DOWN) && is_midpoint_gt_even))) { + if rnd_mode != RoundingMode::NearestEven { + if (x_sign == 0 && ((rnd_mode == RoundingMode::Upward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Upward) && is_midpoint_gt_even))) + || (x_sign != 0 && ((rnd_mode == RoundingMode::Downward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Downward) && is_midpoint_gt_even))) { // C1 = C1 + 1 C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -1680,10 +1680,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo y_exp += EXP_P1; } } else if (is_midpoint_lt_even || is_inexact_gt_midpoint) - && ((x_sign != 0 && (rnd_mode == RoundingMode::BID_ROUNDING_UP - || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO)) - || (x_sign == 0 && (rnd_mode == RoundingMode::BID_ROUNDING_DOWN - || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO))) { + && ((x_sign != 0 && (rnd_mode == RoundingMode::Upward + || rnd_mode == RoundingMode::TowardZero)) + || (x_sign == 0 && (rnd_mode == RoundingMode::Downward + || rnd_mode == RoundingMode::TowardZero))) { // C1 = C1 - 1 C1_lo -= 1; if C1_lo == 0xffffffffffffffffu64 { @@ -1701,8 +1701,8 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo } // in all cases check for overflow (RN and RA solved already) if y_exp == EXP_MAX_P1 { // overflow - if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0) // RM and res < 0 - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0) { // RP and res > 0 + if (rnd_mode == RoundingMode::Downward && x_sign != 0) // RM and res < 0 + || (rnd_mode == RoundingMode::Upward && x_sign == 0) { // RP and res > 0 C1_hi = 0x7800000000000000u64; // +inf C1_lo = 0x0u64; } else { // RM and res > 0, RP and res < 0, or RZ @@ -1728,7 +1728,7 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo // assemble the result res.w[1] = if x_exp < y_exp { x_exp } else { y_exp }; res.w[0] = 0; - if rnd_mode == RoundingMode::BID_ROUNDING_DOWN { + if rnd_mode == RoundingMode::Downward { res.w[1] |= 0x8000000000000000u64; } @@ -2142,8 +2142,8 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo y_exp += (x1 as BID_UINT64) << 49; } // check for overflow - if y_exp == EXP_MAX_P1 && (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST - || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY) { + if y_exp == EXP_MAX_P1 && (rnd_mode == RoundingMode::NearestEven + || rnd_mode == RoundingMode::NearestAway) { res.w[1] = 0x7800000000000000u64 | x_sign; // +/-inf res.w[0] = 0x0u64; // set the inexact flag @@ -2217,13 +2217,13 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo C1_hi = C1.w[1]; C1_lo = C1.w[0]; // general correction from RN to RA, RM, RP, RZ; result uses y_exp - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { - if (x_sign == 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_UP && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_UP) && is_midpoint_gt_even))) - || (x_sign != 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_DOWN && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_DOWN) && is_midpoint_gt_even))) { + if rnd_mode != RoundingMode::NearestEven { + if (x_sign == 0 && ((rnd_mode == RoundingMode::Upward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Upward) && is_midpoint_gt_even))) + || (x_sign != 0 && ((rnd_mode == RoundingMode::Downward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Downward) && is_midpoint_gt_even))) { // C1 = C1 + 1 C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -2236,10 +2236,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo y_exp += EXP_P1; } } else if (is_midpoint_lt_even || is_inexact_gt_midpoint) - && ((x_sign != 0 && (rnd_mode == RoundingMode::BID_ROUNDING_UP - || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO)) - || (x_sign == 0 && (rnd_mode == RoundingMode::BID_ROUNDING_DOWN - || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO))) { + && ((x_sign != 0 && (rnd_mode == RoundingMode::Upward + || rnd_mode == RoundingMode::TowardZero)) + || (x_sign == 0 && (rnd_mode == RoundingMode::Downward + || rnd_mode == RoundingMode::TowardZero))) { // C1 = C1 - 1 C1_lo -= 1; if C1_lo == 0xffffffffffffffffu64 { @@ -2257,8 +2257,8 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo } // in all cases check for overflow (RN and RA solved already) if y_exp == EXP_MAX_P1 { // overflow - if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0) // RM and res < 0 - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0) { // RP and res > 0 + if (rnd_mode == RoundingMode::Downward && x_sign != 0) // RM and res < 0 + || (rnd_mode == RoundingMode::Upward && x_sign == 0) { // RP and res > 0 C1_hi = 0x7800000000000000u64; // +inf C1_lo = 0x0u64; } else { // RM and res > 0, RP and res < 0, or RZ @@ -2375,8 +2375,8 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo y_exp += EXP_P1; // C* != 10^P34 because C* has P34 digits // check for overflow - if y_exp == EXP_MAX_P1 && (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST - || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY) { + if y_exp == EXP_MAX_P1 && (rnd_mode == RoundingMode::NearestEven + || rnd_mode == RoundingMode::NearestAway) { // overflow for RN res.w[1] = x_sign | 0x7800000000000000u64; // +/-inf res.w[0] = 0x0u64; @@ -2416,13 +2416,13 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo is_inexact_gt_midpoint = is_inexact && (P256.w[1] & 0x8000000000000000u64) != 0x8000000000000000u64; } // general correction from RN to RA, RM, RP, RZ; result uses y_exp - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { - if (x_sign == 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_UP && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_UP) && is_midpoint_gt_even))) - || (x_sign != 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_DOWN && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_DOWN) && is_midpoint_gt_even))) { + if rnd_mode != RoundingMode::NearestEven { + if (x_sign == 0 && ((rnd_mode == RoundingMode::Upward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Upward) && is_midpoint_gt_even))) + || (x_sign != 0 && ((rnd_mode == RoundingMode::Downward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Downward) && is_midpoint_gt_even))) { // C1 = C1 + 1 C1_lo += 1; if C1_lo == 0 { // rounding overflow in the low 64 bits @@ -2435,10 +2435,10 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo y_exp += EXP_P1; } } else if (is_midpoint_lt_even || is_inexact_gt_midpoint) - && ((x_sign != 0 && (rnd_mode == RoundingMode::BID_ROUNDING_UP - || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO)) - || (x_sign == 0 && (rnd_mode == RoundingMode::BID_ROUNDING_DOWN - || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO))) { + && ((x_sign != 0 && (rnd_mode == RoundingMode::Upward + || rnd_mode == RoundingMode::TowardZero)) + || (x_sign == 0 && (rnd_mode == RoundingMode::Downward + || rnd_mode == RoundingMode::TowardZero))) { // C1 = C1 - 1 C1_lo -= 1; if C1_lo == 0xffffffffffffffffu64 { @@ -2456,8 +2456,8 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo } // in all cases check for overflow (RN and RA solved already) if y_exp == EXP_MAX_P1 { // overflow - if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN && x_sign != 0) // RM and res < 0 - || (rnd_mode == RoundingMode::BID_ROUNDING_UP && x_sign == 0) { // RP and res > 0 + if (rnd_mode == RoundingMode::Downward && x_sign != 0) // RM and res < 0 + || (rnd_mode == RoundingMode::Upward && x_sign == 0) { // RP and res > 0 C1_hi = 0x7800000000000000u64; // +inf C1_lo = 0x0u64; } else { // RM and res > 0, RP and res < 0, or RZ @@ -2495,7 +2495,7 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo // assemble the result res.w[1] = if x_exp < y_exp { x_exp } else { y_exp }; res.w[0] = 0; - if rnd_mode == RoundingMode::BID_ROUNDING_DOWN { + if rnd_mode == RoundingMode::Downward { res.w[1] |= 0x8000000000000000u64; } diff --git a/src/bid128_div.rs b/src/bid128_div.rs index 0779854..8dfbdc1 100644 --- a/src/bid128_div.rs +++ b/src/bid128_div.rs @@ -381,7 +381,7 @@ pub (crate) fn bid128_div(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo rmode = RoundingMode::from(3 - (rmode as u32)); } match rmode { - RoundingMode::BID_ROUNDING_TO_NEAREST => { // round to nearest code + RoundingMode::NearestEven => { // round to nearest code // rounding // 2*CA4 - CY CA4r.w[1] = (CA4.w[1] + CA4.w[1]) | (CA4.w[0] >> 63); @@ -397,7 +397,7 @@ pub (crate) fn bid128_div(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo CQ.w[1] += 1; } }, - RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestAway => { // rounding // 2*CA4 - CY CA4r.w[1] = (CA4.w[1] + CA4.w[1]) | (CA4.w[0] >> 63); @@ -413,7 +413,7 @@ pub (crate) fn bid128_div(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo CQ.w[1] += 1; } }, - RoundingMode::BID_ROUNDING_DOWN | RoundingMode::BID_ROUNDING_TO_ZERO => { }, + RoundingMode::Downward | RoundingMode::TowardZero => { }, _ => { CQ.w[0] += 1; if CQ.w[0] == 0 { @@ -816,7 +816,7 @@ if (diff_expon >= 0) { if (sign_x ^ sign_y && (unsigned)(rmode - 1) < 2) rmode = 3 - rmode; switch (rmode) { - case BID_ROUNDING_TO_NEAREST: // round to nearest code + case BidRoundingToNearest: // round to nearest code // rounding // 2*CA4 - CY CA4r.w[1] = (CA4.w[1] + CA4.w[1]) | (CA4.w[0] >> 63); @@ -842,7 +842,7 @@ if (diff_expon >= 0) { if (CQ.w[0] < carry64) CQ.w[1]++; break; - case BID_ROUNDING_DOWN: + case BidRoundingDown: case BID_ROUNDING_TO_ZERO: break; default: // rounding up @@ -1252,7 +1252,7 @@ if (diff_expon >= 0) { if (sign_x ^ sign_y && (unsigned)(rmode - 1) < 2) rmode = 3 - rmode; switch (rmode) { - case BID_ROUNDING_TO_NEAREST: // round to nearest code + case BidRoundingToNearest: // round to nearest code // rounding // 2*CA4 - CY CA4r.w[1] = (CA4.w[1] + CA4.w[1]) | (CA4.w[0] >> 63); @@ -1278,7 +1278,7 @@ if (diff_expon >= 0) { if (CQ.w[0] < carry64) CQ.w[1]++; break; - case BID_ROUNDING_DOWN: + case BidRoundingDown: case BID_ROUNDING_TO_ZERO: break; default: // rounding up @@ -1679,7 +1679,7 @@ if (diff_expon >= 0) { if (sign_x ^ sign_y && (unsigned)(rmode - 1) < 2) rmode = 3 - rmode; switch (rmode) { - case BID_ROUNDING_TO_NEAREST: // round to nearest code + case BidRoundingToNearest: // round to nearest code // rounding // 2*CA4 - CY CA4r.w[1] = (CA4.w[1] + CA4.w[1]) | (CA4.w[0] >> 63); @@ -1705,7 +1705,7 @@ if (diff_expon >= 0) { if (CQ.w[0] < carry64) CQ.w[1]++; break; - case BID_ROUNDING_DOWN: + case BidRoundingDown: case BID_ROUNDING_TO_ZERO: break; default: // rounding up diff --git a/src/bid128_fma.rs b/src/bid128_fma.rs index 214fb67..457b524 100644 --- a/src/bid128_fma.rs +++ b/src/bid128_fma.rs @@ -58,12 +58,12 @@ pub (crate) fn bid_rounding_correction( C_hi = res.w[1] & MASK_COEFF; C_lo = res.w[0]; if (sign == 0 - && ((rnd_mode == RoundingMode::BID_ROUNDING_UP && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_UP) && is_midpoint_gt_even))) - || (sign != 0 && ((rnd_mode == RoundingMode::BID_ROUNDING_DOWN && is_inexact_lt_midpoint) - || ((rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY - || rnd_mode == RoundingMode::BID_ROUNDING_DOWN) && is_midpoint_gt_even))) { + && ((rnd_mode == RoundingMode::Upward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Upward) && is_midpoint_gt_even))) + || (sign != 0 && ((rnd_mode == RoundingMode::Downward && is_inexact_lt_midpoint) + || ((rnd_mode == RoundingMode::NearestAway + || rnd_mode == RoundingMode::Downward) && is_midpoint_gt_even))) { // C = C + 1 C_lo += 1; if C_lo == 0 { @@ -78,8 +78,8 @@ pub (crate) fn bid_rounding_correction( exp = ((unbexp + 6176)as BID_UINT64) << 49; } } else if (is_midpoint_lt_even || is_inexact_gt_midpoint) - && ((sign != 0 && (rnd_mode == RoundingMode::BID_ROUNDING_UP || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO)) - || (sign == 0 && (rnd_mode == RoundingMode::BID_ROUNDING_DOWN || rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO))) { + && ((sign != 0 && (rnd_mode == RoundingMode::Upward || rnd_mode == RoundingMode::TowardZero)) + || (sign == 0 && (rnd_mode == RoundingMode::Downward || rnd_mode == RoundingMode::TowardZero))) { // C = C - 1 C_lo -= 1; if C_lo == 0xffffffffffffffffu64 { @@ -105,13 +105,13 @@ pub (crate) fn bid_rounding_correction( *ptrfpsf |= StatusFlags::BID_INEXACT_EXCEPTION | StatusFlags::BID_OVERFLOW_EXCEPTION; exp = 0; (C_hi, C_lo) = if sign == 0 { // result is positive - if rnd_mode == RoundingMode::BID_ROUNDING_UP || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY { // +inf + if rnd_mode == RoundingMode::Upward || rnd_mode == RoundingMode::NearestAway { // +inf (0x7800000000000000u64, 0x0000000000000000u64) } else { // res = +MAXFP = (10^34-1) * 10^emax (0x5fffed09bead87c0u64, 0x378d8e63ffffffffu64) } } else { // result is negative - if rnd_mode == RoundingMode::BID_ROUNDING_DOWN || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY { // -inf + if rnd_mode == RoundingMode::Downward || rnd_mode == RoundingMode::NearestAway { // -inf (0xf800000000000000u64, 0x0000000000000000u64) } else { // res = -MAXFP = -(10^34-1) * 10^emax (0xdfffed09bead87c0u64, 0x378d8e63ffffffffu64) @@ -358,7 +358,7 @@ pub (crate) fn bid_add_and_round( // (x*y and z had opposite signs) if R256.w[3] == 0x0u64 && R256.w[2] == 0x0u64 && R256.w[1] == 0x0u64 && R256.w[0] == 0x0u64 { - p_sign = if rnd_mode != RoundingMode::BID_ROUNDING_DOWN { + p_sign = if rnd_mode != RoundingMode::Downward { 0x0000000000000000u64 } else { 0x8000000000000000u64 @@ -437,7 +437,7 @@ pub (crate) fn bid_add_and_round( // the rounded result has p34 = 34 digits e4 = e4 + x0 + if incr_exp { 1 } else { 0 }; - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode == RoundingMode::NearestEven { #[cfg(feature = "DECIMAL_TINY_DETECTION_AFTER_ROUNDING")] if e4 < EXP_MIN_UNBIASED { is_tiny = true; // for other rounding modes apply correction @@ -476,7 +476,7 @@ pub (crate) fn bid_add_and_round( // Note: res is correct only if EXP_MIN_UNBIASED <= e4 <= EXP_MAX_UNBIASED // check for overflow if RN - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && (ind + e4) > (p34 + EXP_MAX_UNBIASED) { + if rnd_mode == RoundingMode::NearestEven && (ind + e4) > (p34 + EXP_MAX_UNBIASED) { res.w[1] = p_sign | 0x7800000000000000u64; res.w[0] = 0x0000000000000000u64; ptrres = res; @@ -639,7 +639,7 @@ pub (crate) fn bid_add_and_round( } // res contains the correct result // apply correction if not rounding to nearest - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -1048,7 +1048,7 @@ pub (crate) fn bid128_ext_fma( res.w[1] |= z_sign; res.w[0] = 0x0; } else { // x * y and z have opposite signs - if rnd_mode == RoundingMode::BID_ROUNDING_DOWN { + if rnd_mode == RoundingMode::Downward { // res = -0.0 res.w[1] |= MASK_SIGN; res.w[0] = 0x0; @@ -1459,7 +1459,7 @@ pub (crate) fn bid128_ext_fma( // check for overflow if q4 + e4 > p34 + EXP_MAX_UNBIASED { - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode == RoundingMode::NearestEven { res.w[1] = p_sign | 0x7800000000000000u64; // +/-inf res.w[0] = 0x0000000000000000u64; *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION | StatusFlags::BID_OVERFLOW_EXCEPTION; @@ -1675,7 +1675,7 @@ pub (crate) fn bid128_ext_fma( *pfpsf |= StatusFlags::BID_UNDERFLOW_EXCEPTION; } res.w[1] |= p_sign | (((e4 + 6176) as BID_UINT64) << 49); - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -1700,7 +1700,7 @@ pub (crate) fn bid128_ext_fma( // get here if incr_exp = 1 and then q4 + e4 == EXP_MIN_UNBIASED + p34) res.w[1] |= p_sign | (((e4 + 6176) as BID_UINT64) << 49); - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -1788,7 +1788,7 @@ pub (crate) fn bid128_ext_fma( if (q3 + e3) > (p34 + EXP_MAX_UNBIASED) && p34 <= delta - 1 { // e3 > EXP_MAX_UNBIASED implies p34 <= delta-1 and e3 > EXP_MAX_UNBIASED is a necessary // condition for (q3 + e3) > (p34 + EXP_MAX_UNBIASED) - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode == RoundingMode::NearestEven { res.w[1] = z_sign | 0x7800000000000000u64; // +/-inf res.w[0] = 0x0000000000000000u64; *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION | StatusFlags::BID_OVERFLOW_EXCEPTION; @@ -2059,7 +2059,7 @@ pub (crate) fn bid128_ext_fma( && (res.w[1] & MASK_COEFF) == 0x0000314dc6448d93u64 // 10^33_high && res.w[0] == 0x38c15b0a00000000u64 // 10^33_low && z_sign != p_sign - && (rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY) + && (rnd_mode == RoundingMode::NearestEven || rnd_mode == RoundingMode::NearestAway) && (delta == (p34 + 1)) && C4gt5toq4m1) { *pfpsf |= StatusFlags::BID_UNDERFLOW_EXCEPTION; } @@ -2073,7 +2073,7 @@ pub (crate) fn bid128_ext_fma( } } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -2219,7 +2219,7 @@ pub (crate) fn bid128_ext_fma( // set the inexact flag *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION; // check for overflow - if e3 > EXP_MAX_UNBIASED && rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST { + if e3 > EXP_MAX_UNBIASED && rnd_mode == RoundingMode::NearestEven { res.w[1] = z_sign | 0x7800000000000000u64; // +/-inf res.w[0] = 0x0000000000000000u64; *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION | StatusFlags::BID_OVERFLOW_EXCEPTION; @@ -2233,7 +2233,7 @@ pub (crate) fn bid128_ext_fma( return res; } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -2271,7 +2271,7 @@ pub (crate) fn bid128_ext_fma( // the result is always inexact, and never tiny // check for overflow for RN if e3 > EXP_MAX_UNBIASED { - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode == RoundingMode::NearestEven { res.w[1] = z_sign | 0x7800000000000000u64; // +/-inf res.w[0] = 0x0000000000000000u64; *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION | StatusFlags::BID_OVERFLOW_EXCEPTION; @@ -2296,7 +2296,7 @@ pub (crate) fn bid128_ext_fma( } // set the inexact flag *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION; - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -2412,7 +2412,7 @@ pub (crate) fn bid128_ext_fma( // the result is always inexact, and never tiny // check for overflow for RN if e3 > EXP_MAX_UNBIASED { - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode == RoundingMode::NearestEven { res.w[1] = z_sign | 0x7800000000000000u64; // +/-inf res.w[0] = 0x0000000000000000u64; *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION | StatusFlags::BID_OVERFLOW_EXCEPTION; @@ -2438,7 +2438,7 @@ pub (crate) fn bid128_ext_fma( // set the inexact flag *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION; res.w[1] |= z_sign | (((e3 + 6176) as BID_UINT64) << 49); - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -2478,7 +2478,7 @@ pub (crate) fn bid128_ext_fma( is_inexact_lt_midpoint = true; //if(z_sign), as if for absolute value } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -2804,7 +2804,7 @@ pub (crate) fn bid128_ext_fma( // if the result is pure zero, the sign depends on the rounding // mode (x*y and z had opposite signs) if res.w[1] == 0x0u64 && res.w[0] == 0x0u64 { - z_sign = if rnd_mode != RoundingMode::BID_ROUNDING_DOWN { + z_sign = if rnd_mode != RoundingMode::Downward { 0x0000000000000000u64 } else { 0x8000000000000000u64 @@ -2902,7 +2902,7 @@ pub (crate) fn bid128_ext_fma( // if the result is pure zero, the sign depends on the rounding // mode (x*y and z had opposite signs) if res.w[1] == 0x0u64 && res.w[0] == 0x0u64 { - z_sign = if rnd_mode != RoundingMode::BID_ROUNDING_DOWN { + z_sign = if rnd_mode != RoundingMode::Downward { 0x0000000000000000u64 } else { 0x8000000000000000u64 @@ -3111,12 +3111,12 @@ pub (crate) fn bid128_ext_fma( } res.w[1] |= z_sign | (((e3 + 6176) as BID_UINT64) << 49); // check for overflow - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && e3 > EXP_MAX_UNBIASED { + if rnd_mode == RoundingMode::NearestEven && e3 > EXP_MAX_UNBIASED { res.w[1] = z_sign | 0x7800000000000000u64; // +/-inf res.w[0] = 0x0000000000000000u64; *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION | StatusFlags::BID_OVERFLOW_EXCEPTION; } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -3325,7 +3325,7 @@ pub (crate) fn bid128_ext_fma( // the rounded result is already correct } // check for overflow - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && e4 > EXP_MAX_UNBIASED { + if rnd_mode == RoundingMode::NearestEven && e4 > EXP_MAX_UNBIASED { res.w[1] = p_sign | 0x7800000000000000u64; res.w[0] = 0x0000000000000000u64; *pfpsf |= StatusFlags::BID_OVERFLOW_EXCEPTION | StatusFlags::BID_INEXACT_EXCEPTION; @@ -3333,7 +3333,7 @@ pub (crate) fn bid128_ext_fma( p_exp = ((e4 + 6176) as BID_UINT64) << 49; res.w[1] |= p_sign | (p_exp & MASK_EXP); } - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -3626,7 +3626,7 @@ pub (crate) fn bid128_ext_fma( } // determine tininess - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode == RoundingMode::NearestEven { if e4 < EXP_MIN_UNBIASED { is_tiny = true; // for other rounding modes apply correction } @@ -3664,7 +3664,7 @@ pub (crate) fn bid128_ext_fma( // Note: res is correct only if EXP_MIN_UNBIASED <= e4 <= EXP_MAX_UNBIASED // check for overflow if RN - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && (ind + e4) > (p34 + EXP_MAX_UNBIASED) { + if rnd_mode == RoundingMode::NearestEven && (ind + e4) > (p34 + EXP_MAX_UNBIASED) { res.w[1] = p_sign | 0x7800000000000000u64; res.w[0] = 0x0000000000000000u64; *pfpsf |= StatusFlags::BID_INEXACT_EXCEPTION | StatusFlags::BID_OVERFLOW_EXCEPTION; @@ -3841,7 +3841,7 @@ pub (crate) fn bid128_ext_fma( } // res contains the correct result // apply correction if not rounding to nearest - if rnd_mode != RoundingMode::BID_ROUNDING_TO_NEAREST { + if rnd_mode != RoundingMode::NearestEven { bid_rounding_correction( rnd_mode, is_inexact_lt_midpoint, @@ -3853,11 +3853,11 @@ pub (crate) fn bid128_ext_fma( #[cfg(not(feature = "DECIMAL_TINY_DETECTION_AFTER_ROUNDING"))] if (((res.w[1] & 0x7fffffffffffffffu64) == 0x0000314dc6448d93u64) // 10^33*10^-6176_high && (res.w[0] == 0x38c15b0a00000000u64)) // 10^33*10^-6176_low - && (((rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST - || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY) + && (((rnd_mode == RoundingMode::NearestEven + || rnd_mode == RoundingMode::NearestAway) && (is_midpoint_lt_even || is_inexact_gt_midpoint)) - || ((((rnd_mode == RoundingMode::BID_ROUNDING_UP) && (res.w[1] & MASK_SIGN) == 0) - || ((rnd_mode == RoundingMode::BID_ROUNDING_DOWN) && (res.w[1] & MASK_SIGN) != 0)) + || ((((rnd_mode == RoundingMode::Upward) && (res.w[1] & MASK_SIGN) == 0) + || ((rnd_mode == RoundingMode::Downward) && (res.w[1] & MASK_SIGN) != 0)) && (is_midpoint_lt_even || is_midpoint_gt_even || is_inexact_lt_midpoint || is_inexact_gt_midpoint))) { is_tiny = true; @@ -4142,8 +4142,8 @@ pub (crate) fn bid64qqq_fma(x: &BID_UINT128, y: &BID_UINT128, z: &BID_UINT128, r x, y, z, rnd_mode, pfpsf); - if (rnd_mode == RoundingMode::BID_ROUNDING_DOWN) || (rnd_mode == RoundingMode::BID_ROUNDING_UP) || - (rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO) || // no double rounding error is possible + if (rnd_mode == RoundingMode::Downward) || (rnd_mode == RoundingMode::Upward) || + (rnd_mode == RoundingMode::TowardZero) || // no double rounding error is possible ((res.w[BID_HIGH_128W] & MASK_NAN) == MASK_NAN) || // res=QNaN (cannot be SNaN) ((res.w[BID_HIGH_128W] & MASK_ANY_INF) == MASK_INF) { // result is infinity res1 = bid128_to_bid64(&res, rnd_mode, pfpsf); @@ -4168,11 +4168,11 @@ pub (crate) fn bid64qqq_fma(x: &BID_UINT128, y: &BID_UINT128, z: &BID_UINT128, r // correction needed for tininess detection before rounding if ((res1 & 0x7fffffffffffffffu64) == 1000000000000000u64) && // 10^15*10^-398 - (((rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST - || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY) + (((rnd_mode == RoundingMode::NearestEven + || rnd_mode == RoundingMode::NearestAway) && (is_midpoint_lt_even || is_inexact_gt_midpoint)) - || ((((rnd_mode == RoundingMode::BID_ROUNDING_UP) && (res1 & MASK_SIGN) == 0) - || ((rnd_mode == RoundingMode::BID_ROUNDING_DOWN) && (res1 & MASK_SIGN) != 0)) + || ((((rnd_mode == RoundingMode::Upward) && (res1 & MASK_SIGN) == 0) + || ((rnd_mode == RoundingMode::Downward) && (res1 & MASK_SIGN) != 0)) && (is_midpoint_lt_even || is_midpoint_gt_even || is_inexact_lt_midpoint || is_inexact_gt_midpoint))) { *pfpsf |= StatusFlags::BID_UNDERFLOW_EXCEPTION; @@ -4200,7 +4200,7 @@ pub (crate) fn bid64qqq_fma(x: &BID_UINT128, y: &BID_UINT128, z: &BID_UINT128, r } // else continue // -398 - 34 <= unbexp <= 369 + 15 - if rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY { + if rnd_mode == RoundingMode::NearestAway { // apply correction, if needed, to make the result rounded to nearest-even if is_midpoint_gt_even { // res = res - 1 @@ -4435,7 +4435,7 @@ pub (crate) fn bid64qqq_fma(x: &BID_UINT128, y: &BID_UINT128, z: &BID_UINT128, r } // this is the result rounded correctly to nearest, with bounded exponent - if rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY && is_midpoint_gt_even { // correction + if rnd_mode == RoundingMode::NearestAway && is_midpoint_gt_even { // correction // res = res + 1 res1 += 1; // res1 is now odd } // else the result is already correct @@ -4450,10 +4450,10 @@ pub (crate) fn bid64qqq_fma(x: &BID_UINT128, y: &BID_UINT128, z: &BID_UINT128, r // correction needed for tininess detection before rounding if ((res1 & 0x7fffffffffffffffu64) == 1000000000000000u64) && // 10^15*10^-398 - (((rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST || rnd_mode == RoundingMode::BID_ROUNDING_TIES_AWAY) && + (((rnd_mode == RoundingMode::NearestEven || rnd_mode == RoundingMode::NearestAway) && (is_midpoint_lt_even || is_inexact_gt_midpoint)) || - ((((rnd_mode == RoundingMode::BID_ROUNDING_UP) && (res1 & MASK_SIGN) == 0) || - ((rnd_mode == RoundingMode::BID_ROUNDING_DOWN) && (res1 & MASK_SIGN) == MASK_SIGN)) + ((((rnd_mode == RoundingMode::Upward) && (res1 & MASK_SIGN) == 0) || + ((rnd_mode == RoundingMode::Downward) && (res1 & MASK_SIGN) == MASK_SIGN)) && (is_midpoint_lt_even || is_midpoint_gt_even || is_inexact_lt_midpoint || is_inexact_gt_midpoint))) { *pfpsf |= StatusFlags::BID_UNDERFLOW_EXCEPTION; diff --git a/src/bid128_llrint.rs b/src/bid128_llrint.rs index e97f76c..20f462b 100644 --- a/src/bid128_llrint.rs +++ b/src/bid128_llrint.rs @@ -23,10 +23,10 @@ use crate::d128::_IDEC_flags; /// invalid and inexact pub (crate) fn bid128_llrint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: &mut _IDEC_flags) -> i64 { match rnd_mode { - RoundingMode::BID_ROUNDING_TO_NEAREST => bid128_to_int64_xrnint(x, pfpsf), - RoundingMode::BID_ROUNDING_TIES_AWAY => bid128_to_int64_xrninta(x, pfpsf), - RoundingMode::BID_ROUNDING_DOWN => bid128_to_int64_xfloor(x, pfpsf), - RoundingMode::BID_ROUNDING_UP => bid128_to_int64_xceil(x, pfpsf), + RoundingMode::NearestEven => bid128_to_int64_xrnint(x, pfpsf), + RoundingMode::NearestAway => bid128_to_int64_xrninta(x, pfpsf), + RoundingMode::Downward => bid128_to_int64_xfloor(x, pfpsf), + RoundingMode::Upward => bid128_to_int64_xceil(x, pfpsf), _ => bid128_to_int64_xint(x, pfpsf) // if (rnd_mode == BID_ROUNDING_TO_ZERO) } } diff --git a/src/bid128_lrint.rs b/src/bid128_lrint.rs index 170df81..ff20b64 100644 --- a/src/bid128_lrint.rs +++ b/src/bid128_lrint.rs @@ -22,10 +22,10 @@ use crate::d128::{_IDEC_flags, RoundingMode}; /// invalid and inexact pub (crate) fn bid128_lrint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: &mut _IDEC_flags) -> i64 { match rnd_mode { - RoundingMode::BID_ROUNDING_TO_NEAREST => bid128_to_int64_xrnint(x, pfpsf), - RoundingMode::BID_ROUNDING_TIES_AWAY => bid128_to_int64_xrninta(x, pfpsf), - RoundingMode::BID_ROUNDING_DOWN => bid128_to_int64_xfloor(x, pfpsf), - RoundingMode::BID_ROUNDING_UP => bid128_to_int64_xceil(x, pfpsf), + RoundingMode::NearestEven => bid128_to_int64_xrnint(x, pfpsf), + RoundingMode::NearestAway => bid128_to_int64_xrninta(x, pfpsf), + RoundingMode::Downward => bid128_to_int64_xfloor(x, pfpsf), + RoundingMode::Upward => bid128_to_int64_xceil(x, pfpsf), _ => bid128_to_int64_xint(x, pfpsf) } } diff --git a/src/bid128_modf.rs b/src/bid128_modf.rs index bf23b83..4dcc10d 100644 --- a/src/bid128_modf.rs +++ b/src/bid128_modf.rs @@ -23,7 +23,7 @@ pub (crate) fn bid128_modf(x: &BID_UINT128, pfpsf: &mut _IDEC_flags) -> (BID_UIN res.w[BID_HIGH_128W]= (x.w[BID_HIGH_128W] & 0x8000000000000000u64)|0x5ffe000000000000u64; res.w[BID_LOW_128W] = 0; } else { - res = bid128_sub(x, &xi, RoundingMode::BID_ROUNDING_TO_NEAREST, pfpsf); + res = bid128_sub(x, &xi, RoundingMode::NearestEven, pfpsf); } xi.w[BID_HIGH_128W] |= x.w[BID_HIGH_128W] & 0x8000000000000000u64; diff --git a/src/bid128_nearbyint.rs b/src/bid128_nearbyint.rs index 73b0e91..79ec9e7 100644 --- a/src/bid128_nearbyint.rs +++ b/src/bid128_nearbyint.rs @@ -104,7 +104,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: // x is not special and is not zero match rnd_mode { - RoundingMode::BID_ROUNDING_TO_NEAREST | RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestEven | RoundingMode::NearestAway => { // if (exp <= -(p+1)) return 0.0 if x_exp <= 0x2ffa000000000000u64 { // 0x2ffa000000000000u64 == -35 res.w[1] = x_sign | 0x3040000000000000u64; @@ -112,7 +112,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: return res; } }, - RoundingMode::BID_ROUNDING_DOWN => { + RoundingMode::Downward => { // if (exp <= -p) return -1.0 or +0.0 if x_exp <= 0x2ffc000000000000u64 { // 0x2ffa000000000000u64 == -34 if x_sign != 0 { @@ -129,7 +129,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: return res; } }, - RoundingMode::BID_ROUNDING_UP => { + RoundingMode::Upward => { // if (exp <= -p) return -0.0 or +1.0 if x_exp <= 0x2ffc000000000000u64 { // 0x2ffc000000000000u64 == -34 if x_sign != 0 { @@ -146,7 +146,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: return res; } }, - RoundingMode::BID_ROUNDING_TO_ZERO => { + RoundingMode::TowardZero => { // if (exp <= -p) return -0.0 or +0.0 if x_exp <= 0x2ffc000000000000u64 { // 0x2ffc000000000000u64 == -34 res.w[1] = x_sign | 0x3040000000000000u64; @@ -192,7 +192,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: } // exp < 0 match rnd_mode { - RoundingMode::BID_ROUNDING_TO_NEAREST => { + RoundingMode::NearestEven => { if (q + exp) >= 0 { // exp < 0 and 1 <= -exp <= q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' @@ -285,7 +285,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: res } }, - RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestAway => { if (q + exp) >= 0 { // exp < 0 and 1 <= -exp <= q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' @@ -348,7 +348,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: res } }, - RoundingMode::BID_ROUNDING_DOWN => { + RoundingMode::Downward => { if (q + exp) > 0 { // exp < 0 and 1 <= -exp < q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' @@ -463,7 +463,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: res } }, - RoundingMode::BID_ROUNDING_UP => { + RoundingMode::Upward => { if (q + exp) > 0 { // exp < 0 and 1 <= -exp < q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' @@ -578,7 +578,7 @@ pub (crate) fn bid128_nearbyint(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: res } }, - RoundingMode::BID_ROUNDING_TO_ZERO => { + RoundingMode::TowardZero => { if (q + exp) > 0 { // exp < 0 and 1 <= -exp < q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' diff --git a/src/bid128_quantize.rs b/src/bid128_quantize.rs index 7f02182..916bf4c 100644 --- a/src/bid128_quantize.rs +++ b/src/bid128_quantize.rs @@ -168,7 +168,7 @@ pub (crate) fn bid128_quantize(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: Round CR = __shr_128(&CX2, amount); } - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && (CR.w[0] & 1) == 1 { + if rnd_mode == RoundingMode::NearestEven && (CR.w[0] & 1) == 1 { // check whether fractional part of initial_P/10^extra_digits is // exactly .5 this is the same as fractional part of // (initial_P + 0.5*10^extra_digits)/10^extra_digits is exactly zero @@ -201,7 +201,7 @@ pub (crate) fn bid128_quantize(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: Round } match rmode { - RoundingMode::BID_ROUNDING_TO_NEAREST | RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestEven | RoundingMode::NearestAway => { // test whether fractional part is 0 if REM_H.w[1] == 0x8000000000000000u64 && REM_H.w[0] == 0 && (CT.w[1] < BID_RECIPROCALS10_128[extra_digits as usize].w[1] @@ -210,7 +210,7 @@ pub (crate) fn bid128_quantize(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: Round status = StatusFlags::BID_EXACT_STATUS; } }, - RoundingMode::BID_ROUNDING_DOWN | RoundingMode::BID_ROUNDING_TO_ZERO => { + RoundingMode::Downward | RoundingMode::TowardZero => { if (REM_H.w[1] | REM_H.w[0]) == 0 && (CT.w[1] < BID_RECIPROCALS10_128[extra_digits as usize].w[1] || (CT.w[1] == BID_RECIPROCALS10_128[extra_digits as usize].w[1] @@ -255,7 +255,7 @@ pub (crate) fn bid128_quantize(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: Round if sign_x != 0 && ((rmode as u32 - 1u32) < 2) { rmode = RoundingMode::from(3 - (rmode as u32)); } - if rmode == RoundingMode::BID_ROUNDING_UP { + if rmode == RoundingMode::Upward { CR.w[0] = 1; } __set_status_flags(pfpsf, StatusFlags::BID_INEXACT_EXCEPTION); diff --git a/src/bid128_round_integral.rs b/src/bid128_round_integral.rs index 297b330..960657b 100644 --- a/src/bid128_round_integral.rs +++ b/src/bid128_round_integral.rs @@ -111,7 +111,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo // x is not special and is not zero match rnd_mode { - RoundingMode::BID_ROUNDING_TO_NEAREST | RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestEven | RoundingMode::NearestAway => { // if (exp <= -(p+1)) return 0.0 if x_exp <= 0x2ffa000000000000u64 { // 0x2ffa000000000000u64 == -35 res.w[1] = x_sign | 0x3040000000000000u64; @@ -120,7 +120,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo return res; } }, - RoundingMode::BID_ROUNDING_DOWN => { + RoundingMode::Downward => { // if (exp <= -p) return -1.0 or +0.0 if x_exp <= 0x2ffc000000000000u64 { // 0x2ffa000000000000u64 == -34 if x_sign != 0 { @@ -138,7 +138,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo return res; } }, - RoundingMode::BID_ROUNDING_UP => { + RoundingMode::Upward => { // if (exp <= -p) return -0.0 or +1.0 if x_exp <= 0x2ffc000000000000u64 { // 0x2ffc000000000000u64 == -34 if x_sign != 0 { @@ -156,7 +156,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo return res; } }, - RoundingMode::BID_ROUNDING_TO_ZERO => { + RoundingMode::TowardZero => { // if (exp <= -p) return -0.0 or +0.0 if x_exp <= 0x2ffc000000000000u64 { // 0x2ffc000000000000u64 == -34 res.w[1] = x_sign | 0x3040000000000000u64; @@ -202,7 +202,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo } // exp < 0 match rnd_mode { - RoundingMode::BID_ROUNDING_TO_NEAREST => { + RoundingMode::NearestEven => { if (q + exp) >= 0 { // exp < 0 and 1 <= -exp <= q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' @@ -354,7 +354,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo res } }, - RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestAway => { if (q + exp) >= 0 { // exp < 0 and 1 <= -exp <= q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' @@ -484,7 +484,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo res } }, - RoundingMode::BID_ROUNDING_DOWN => { + RoundingMode::Downward => { if (q + exp) > 0 { // exp < 0 and 1 <= -exp < q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' @@ -598,7 +598,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo res } } - RoundingMode::BID_ROUNDING_UP => { + RoundingMode::Upward => { if (q + exp) > 0 { // exp < 0 and 1 <= -exp < q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' @@ -712,7 +712,7 @@ pub (crate) fn bid128_round_integral_exact(x: &BID_UINT128, rnd_mode: RoundingMo res } }, - RoundingMode::BID_ROUNDING_TO_ZERO => { + RoundingMode::TowardZero => { if (q + exp) > 0 { // exp < 0 and 1 <= -exp < q // need to shift right -exp digits from the coefficient; exp will be 0 ind = -exp; // 1 <= ind <= 34; ind is a synonym for 'x' diff --git a/src/bid128_sqrt.rs b/src/bid128_sqrt.rs index 3d0f960..a16415c 100644 --- a/src/bid128_sqrt.rs +++ b/src/bid128_sqrt.rs @@ -252,7 +252,7 @@ pub(crate) fn bid128_sqrt(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: &mut _ } } // RU? - if (rnd_mode) == RoundingMode::BID_ROUNDING_UP { + if (rnd_mode) == RoundingMode::Upward { CS.w[0] += 1; if CS.w[0] == 0 { CS.w[1] += 1; diff --git a/src/bid128_string.rs b/src/bid128_string.rs index ba906bd..41ac2e5 100644 --- a/src/bid128_string.rs +++ b/src/bid128_string.rs @@ -569,7 +569,7 @@ pub (crate) fn bid128_from_string(str: &str, rnd_mode: RoundingMode, pfpsf: &mut i = MAX_FORMAT_DIGITS_128; match rnd_mode { - RoundingMode::BID_ROUNDING_TO_NEAREST => { + RoundingMode::NearestEven => { carry = ((('4' as i32 - buffer[i] as i32) as u32) >> 31) as BID_UINT64; if (buffer[i] == '5' && (coeff_low & 1) != 1) || dec_expon < 0 { if dec_expon >= 0 { @@ -581,22 +581,22 @@ pub (crate) fn bid128_from_string(str: &str, rnd_mode: RoundingMode, pfpsf: &mut } } }, - RoundingMode::BID_ROUNDING_DOWN => { + RoundingMode::Downward => { if sign_x != 0 && buffer[i..ndigits_total].iter().any(|c| *c as i32 > '0' as i32) { carry = 1; } }, - RoundingMode::BID_ROUNDING_UP => { + RoundingMode::Upward => { if sign_x == 0 && buffer[i..ndigits_total].iter().any(|c| *c as i32 > '0' as i32) { carry = 1; } }, - RoundingMode::BID_ROUNDING_TO_ZERO => { + RoundingMode::TowardZero => { carry = 0; }, - RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestAway => { let digit = char::to_digit(buffer[i], 10).unwrap() as i32; carry = (((4 - digit) as u32) >> 31) as BID_UINT64; if dec_expon < 0 diff --git a/src/bid64_to_bid128.rs b/src/bid64_to_bid128.rs index 1a751a2..c07ee4d 100644 --- a/src/bid64_to_bid128.rs +++ b/src/bid64_to_bid128.rs @@ -143,7 +143,7 @@ pub (crate) fn bid128_to_bid64(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: & exponent_x = DECIMAL_EXPONENT_BIAS_128 - DECIMAL_EXPONENT_BIAS; //uf_check = 2; } else { - rmode = RoundingMode::BID_ROUNDING_TO_ZERO; + rmode = RoundingMode::TowardZero; } } @@ -163,7 +163,7 @@ pub (crate) fn bid128_to_bid64(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: & CX = __shr_128(&Qh, amount); } - if rmode == RoundingMode::BID_ROUNDING_TO_NEAREST && (CX.w[0] & 1) == 1 { + if rmode == RoundingMode::NearestEven && (CX.w[0] & 1) == 1 { // check whether fractional part of initial_P/10^ed1 is exactly .5 // get remainder @@ -182,7 +182,7 @@ pub (crate) fn bid128_to_bid64(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: & // get remainder Qh1 = __shl_128_long(&Qh, 128 - amount); match rmode { - RoundingMode::BID_ROUNDING_TO_NEAREST | RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestEven | RoundingMode::NearestAway => { // test whether fractional part is 0 if Qh1.w[1] == 0x8000000000000000u64 && Qh1.w[0] == 0 && (Ql.w[1] < BID_RECIPROCALS10_128[extra_digits as usize].w[1] @@ -191,7 +191,7 @@ pub (crate) fn bid128_to_bid64(x: &BID_UINT128, rnd_mode: RoundingMode, pfpsf: & status = StatusFlags::BID_EXACT_STATUS; } }, - RoundingMode::BID_ROUNDING_DOWN | RoundingMode::BID_ROUNDING_TO_ZERO => { + RoundingMode::Downward | RoundingMode::TowardZero => { if (Qh1.w[1] == 0) && (Qh1.w[0] == 0) && (Ql.w[1] < BID_RECIPROCALS10_128[extra_digits as usize].w[1] || (Ql.w[1] == BID_RECIPROCALS10_128[extra_digits as usize].w[1] diff --git a/src/bid_internal.rs b/src/bid_internal.rs index a6819d7..21157b5 100644 --- a/src/bid_internal.rs +++ b/src/bid_internal.rs @@ -382,10 +382,10 @@ pub (crate) fn get_BID64(sgn: BID_UINT64, mut expon: i32, mut coeff: BID_UINT64, if expon + (MAX_FORMAT_DIGITS as i32) < 0 { __set_status_flags(pfpsc, StatusFlags::BID_UNDERFLOW_EXCEPTION | StatusFlags::BID_INEXACT_EXCEPTION); - if rmode == RoundingMode::BID_ROUNDING_DOWN && sgn != 0 { + if rmode == RoundingMode::Downward && sgn != 0 { return 0x8000000000000001u64; } - if rmode == RoundingMode::BID_ROUNDING_UP && sgn == 0 { + if rmode == RoundingMode::Upward && sgn == 0 { return 1u64; } // result is 0 @@ -407,7 +407,7 @@ pub (crate) fn get_BID64(sgn: BID_UINT64, mut expon: i32, mut coeff: BID_UINT64, _C64 = QH >> amount; - if rmode == RoundingMode::BID_ROUNDING_TO_NEAREST { + if rmode == RoundingMode::NearestEven { if (_C64 & 1) == 1 { // check whether fractional part of initial_P/10^extra_digits is exactly .5 @@ -434,7 +434,7 @@ pub (crate) fn get_BID64(sgn: BID_UINT64, mut expon: i32, mut coeff: BID_UINT64, remainder_h = QH << (64 - amount); match rmode { - RoundingMode::BID_ROUNDING_TO_NEAREST | RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestEven | RoundingMode::NearestAway => { if remainder_h == 0x8000000000000000u64 && (Q_low.w[1] < BID_RECIPROCALS10_128[extra_digits as usize].w[1] || (Q_low.w[1] == BID_RECIPROCALS10_128[extra_digits as usize].w[1] @@ -442,7 +442,7 @@ pub (crate) fn get_BID64(sgn: BID_UINT64, mut expon: i32, mut coeff: BID_UINT64, status = StatusFlags::BID_EXACT_STATUS; } }, - RoundingMode::BID_ROUNDING_DOWN | RoundingMode::BID_ROUNDING_TO_ZERO => { // test whether fractional part is 0 + RoundingMode::Downward | RoundingMode::TowardZero => { // test whether fractional part is 0 if remainder_h == 0 && (Q_low.w[1] < BID_RECIPROCALS10_128[extra_digits as usize].w[1] || (Q_low.w[1] == BID_RECIPROCALS10_128[extra_digits as usize].w[1] @@ -479,13 +479,13 @@ pub (crate) fn get_BID64(sgn: BID_UINT64, mut expon: i32, mut coeff: BID_UINT64, // overflow r = sgn | INFINITY_MASK64; match rmode { - RoundingMode::BID_ROUNDING_DOWN => { + RoundingMode::Downward => { if sgn == 0 { r = LARGEST_BID64; } }, - RoundingMode::BID_ROUNDING_TO_ZERO => r = sgn | LARGEST_BID64, - RoundingMode::BID_ROUNDING_UP => { // round up + RoundingMode::TowardZero => r = sgn | LARGEST_BID64, + RoundingMode::Upward => { // round up if sgn != 0 { r = SMALLEST_BID64; } @@ -559,8 +559,8 @@ pub (crate) fn bid_handle_UF_128_rem(sgn: BID_UINT64, mut expon: i32, CQ: &BID_U __set_status_flags(pfpsc, StatusFlags::BID_UNDERFLOW_EXCEPTION | StatusFlags::BID_INEXACT_EXCEPTION); pres.w[1] = sgn; pres.w[0] = 0; - if (sgn != 0 && rnd_mode == RoundingMode::BID_ROUNDING_DOWN) - || (sgn == 0 && rnd_mode == RoundingMode::BID_ROUNDING_UP) { + if (sgn != 0 && rnd_mode == RoundingMode::Downward) + || (sgn == 0 && rnd_mode == RoundingMode::Upward) { pres.w[0] = 1u64; } return pres; @@ -603,7 +603,7 @@ pub (crate) fn bid_handle_UF_128_rem(sgn: BID_UINT64, mut expon: i32, CQ: &BID_U // #ifndef IEEE_ROUND_NEAREST_TIES_AWAY // #ifndef IEEE_ROUND_NEAREST - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && (CQ.w[0] & 1) == 1{ + if rnd_mode == RoundingMode::NearestEven && (CQ.w[0] & 1) == 1{ // check whether fractional part of initial_P/10^ed1 is exactly .5 // get remainder @@ -626,7 +626,7 @@ pub (crate) fn bid_handle_UF_128_rem(sgn: BID_UINT64, mut expon: i32, CQ: &BID_U Qh1 = __shl_128_long(&Qh, 128 - amount); match rmode { - RoundingMode::BID_ROUNDING_TO_NEAREST | RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestEven | RoundingMode::NearestAway => { // test whether fractional part is 0 if (Qh1.w[1] == 0x8000000000000000u64) && (Qh1.w[0] == 0) @@ -636,7 +636,7 @@ pub (crate) fn bid_handle_UF_128_rem(sgn: BID_UINT64, mut expon: i32, CQ: &BID_U status = StatusFlags::BID_EXACT_STATUS; } }, - RoundingMode::BID_ROUNDING_DOWN | RoundingMode::BID_ROUNDING_TO_ZERO => { + RoundingMode::Downward | RoundingMode::TowardZero => { if (Qh1.w[1] == 0) && (Qh1.w[0] == 0) && (Ql.w[1] < BID_RECIPROCALS10_128[ed2 as usize].w[1] @@ -702,8 +702,8 @@ pub (crate) fn handle_UF_128(sgn: BID_UINT64, expon: i32, CQ: &BID_UINT128, rnd_ __set_status_flags(pfpsc, StatusFlags::BID_UNDERFLOW_EXCEPTION | StatusFlags::BID_INEXACT_EXCEPTION); pres.w[1] = sgn; pres.w[0] = 0; - if (sgn != 0 && rnd_mode == RoundingMode::BID_ROUNDING_DOWN) - || (sgn == 0 && rnd_mode == RoundingMode::BID_ROUNDING_UP) { + if (sgn != 0 && rnd_mode == RoundingMode::Downward) + || (sgn == 0 && rnd_mode == RoundingMode::Upward) { pres.w[0] = 1u64; } return pres; @@ -733,7 +733,7 @@ pub (crate) fn handle_UF_128(sgn: BID_UINT64, expon: i32, CQ: &BID_UINT128, rnd_ expon = 0; - if rnd_mode == RoundingMode::BID_ROUNDING_TO_NEAREST && (CQ.w[0] & 1) == 1 { + if rnd_mode == RoundingMode::NearestEven && (CQ.w[0] & 1) == 1 { // check whether fractional part of initial_P/10^ed1 is exactly .5 // get remainder @@ -756,7 +756,7 @@ pub (crate) fn handle_UF_128(sgn: BID_UINT64, expon: i32, CQ: &BID_UINT128, rnd_ Qh1 = __shl_128_long(&Qh, 128 - amount); match rmode { - RoundingMode::BID_ROUNDING_TO_NEAREST | RoundingMode::BID_ROUNDING_TIES_AWAY => { + RoundingMode::NearestEven | RoundingMode::NearestAway => { // test whether fractional part is 0 if Qh1.w[1] == 0x8000000000000000u64 && (Qh1.w[0] == 0) @@ -766,7 +766,7 @@ pub (crate) fn handle_UF_128(sgn: BID_UINT64, expon: i32, CQ: &BID_UINT128, rnd_ status = StatusFlags::BID_EXACT_STATUS; } }, - RoundingMode::BID_ROUNDING_DOWN | RoundingMode::BID_ROUNDING_TO_ZERO=> { + RoundingMode::Downward | RoundingMode::TowardZero=> { if (Qh1.w[1] == 0) && (Qh1.w[0] == 0) && (Ql.w[1] < BID_RECIPROCALS10_128[ed2 as usize].w[1] || (Ql.w[1] == BID_RECIPROCALS10_128[ed2 as usize].w[1] @@ -1081,9 +1081,9 @@ pub (crate) fn bid_get_BID128(sgn: BID_UINT64, expon: i32, coeff: &BID_UINT128, } // OF __set_status_flags (pfpsc, StatusFlags::BID_OVERFLOW_EXCEPTION | StatusFlags::BID_INEXACT_EXCEPTION); - if rnd_mode == RoundingMode::BID_ROUNDING_TO_ZERO - || (sgn != 0 && rnd_mode == RoundingMode::BID_ROUNDING_UP) - || (sgn == 0 && rnd_mode == RoundingMode::BID_ROUNDING_DOWN) { + if rnd_mode == RoundingMode::TowardZero + || (sgn != 0 && rnd_mode == RoundingMode::Upward) + || (sgn == 0 && rnd_mode == RoundingMode::Downward) { pres.w[1] = sgn | LARGEST_BID128_HIGH; pres.w[0] = LARGEST_BID128_LOW; } else { diff --git a/src/d128.rs b/src/d128.rs index 6a5760b..0efa348 100644 --- a/src/d128.rs +++ b/src/d128.rs @@ -7,10 +7,10 @@ /* IntelĀ® Decimal Floating-Point Math Library - Copyright (c) 2018, Intel Corp. */ /* -------------------------------------------------------------------------------------------------- */ -//! A 128-bit decimal floating point type (IEEE Standard 754-2008 compliant). - #![allow(non_camel_case_types)] +//! A 128-bit decimal floating point type (IEEE Standard 754-2008 compliant). + use std::cmp::Ordering; use std::fmt::{Debug, Display, Formatter, LowerExp, UpperExp}; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign}; @@ -43,7 +43,7 @@ use crate::bid128_quantexp::bid128_quantexp; use crate::bid128_quantize::bid128_quantize; use crate::bid128_quantum::bid128_quantum; use crate::bid128_rem::bid128_rem; -use crate::bid128_round_integral::{bid128_round_integral_exact, bid128_round_integral_nearest_away, bid128_round_integral_nearest_even, bid128_round_integral_negative, bid128_round_integral_positive, bid128_round_integral_zero}; +use crate::bid128_round_integral::*; use crate::bid128_scalbln::bid128_scalbln; use crate::bid128_scalbn::bid128_scalbn; use crate::bid128_sqrt::bid128_sqrt; @@ -96,35 +96,35 @@ pub enum ClassTypes { #[derive(Copy, Clone, Debug, PartialEq)] pub enum RoundingMode { /// Rounding towards nearest representable value. - BID_ROUNDING_TO_NEAREST = 0x00000, + NearestEven = 0x00000, /// Rounding towards negative infinity. - BID_ROUNDING_DOWN = 0x00001, + Downward = 0x00001, /// Rounding towards positive infinity. - BID_ROUNDING_UP = 0x00002, + Upward = 0x00002, /// Rounding towards zero. - BID_ROUNDING_TO_ZERO = 0x00003, + TowardZero = 0x00003, /// Rounding towards the nearest value, breaks ties by rounding away from zero. - BID_ROUNDING_TIES_AWAY = 0x00004 + NearestAway = 0x00004 } impl From for RoundingMode { fn from(value: u32) -> Self { match value { - 0x00000 => RoundingMode::BID_ROUNDING_TO_NEAREST, - 0x00001 => RoundingMode::BID_ROUNDING_DOWN, - 0x00002 => RoundingMode::BID_ROUNDING_UP, - 0x00003 => RoundingMode::BID_ROUNDING_TO_ZERO, - 0x00004 => RoundingMode::BID_ROUNDING_TIES_AWAY, + 0x00000 => RoundingMode::NearestEven, + 0x00001 => RoundingMode::Downward, + 0x00002 => RoundingMode::Upward, + 0x00003 => RoundingMode::TowardZero, + 0x00004 => RoundingMode::NearestAway, _ => panic!("Unknown rounding mode") } } } -pub const DEFAULT_ROUNDING_MODE: RoundingMode = RoundingMode::BID_ROUNDING_TO_NEAREST; +pub const DEFAULT_ROUNDING_MODE: RoundingMode = RoundingMode::NearestEven; /// Status flags. pub struct StatusFlags;