Skip to content

Commit

Permalink
· Clippy warning review
Browse files Browse the repository at this point in the history
· Formatting
  • Loading branch information
carlosga committed Mar 31, 2024
1 parent 6f31b02 commit 201fd64
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 114 deletions.
14 changes: 7 additions & 7 deletions src/bid128_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,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::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) {
} 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;
Expand Down Expand Up @@ -1053,9 +1053,9 @@ pub (crate) fn bid128_add(x: &BID_UINT128, y: &BID_UINT128, rnd_mode: RoundingMo
x_exp -= EXP_P1; // no underflow, because n1 >> n2
}
} 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) {
|| (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;
Expand Down
77 changes: 41 additions & 36 deletions src/bid128_fma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1709,12 +1709,11 @@ pub (crate) fn bid128_ext_fma(
is_midpoint_gt_even,
e4, &mut res, pfpsf);
// if e4 = EXP_MIN_UNBIASED && significand < 10^33 => result is tiny (for RD, RZ)
if e4 == EXP_MIN_UNBIASED {
if (res.w[1] & MASK_COEFF) < 0x0000314dc6448d93u64
|| ((res.w[1] & MASK_COEFF) == 0x0000314dc6448d93u64
&& res.w[0] < 0x38c15b0a00000000u64) {
is_tiny = true;
}
if e4 == EXP_MIN_UNBIASED
&& ((res.w[1] & MASK_COEFF) < 0x0000314dc6448d93u64
|| ((res.w[1] & MASK_COEFF) == 0x0000314dc6448d93u64
&& res.w[0] < 0x38c15b0a00000000u64)) {
is_tiny = true;
}
}

Expand Down Expand Up @@ -2165,26 +2164,24 @@ pub (crate) fn bid128_ext_fma(
} else { // > 1/2 ulp
gt_half_ulp = true;
}
} else {
if C4.w[3] < BID_MIDPOINT256[(q4 - 59) as usize].w[3]
|| (C4.w[3] == BID_MIDPOINT256[(q4 - 59) as usize].w[3]
&& C4.w[2] < BID_MIDPOINT256[(q4 - 59) as usize].w[2])
|| (C4.w[3] == BID_MIDPOINT256[(q4 - 59) as usize].w[3]
&& C4.w[2] == BID_MIDPOINT256[(q4 - 59) as usize].w[2]
&& C4.w[1] < BID_MIDPOINT256[(q4 - 59) as usize].w[1])
|| (C4.w[3] == BID_MIDPOINT256[(q4 - 59) as usize].w[3]
&& C4.w[2] == BID_MIDPOINT256[(q4 - 59) as usize].w[2]
&& C4.w[1] == BID_MIDPOINT256[(q4 - 59) as usize].w[1]
&& C4.w[0] < BID_MIDPOINT256[(q4 - 59) as usize].w[0]) { // < 1/2 ulp
lt_half_ulp = true;
} else if C4.w[3] == BID_MIDPOINT256[(q4 - 59) as usize].w[3]
&& C4.w[2] == BID_MIDPOINT256[(q4 - 59) as usize].w[2]
&& C4.w[1] == BID_MIDPOINT256[(q4 - 59) as usize].w[1]
&& C4.w[0] == BID_MIDPOINT256[(q4 - 59) as usize].w[0] { // = 1/2 ulp
eq_half_ulp = true;
} else { // > 1/2 ulp
gt_half_ulp = true;
}
} else if C4.w[3] < BID_MIDPOINT256[(q4 - 59) as usize].w[3]
|| (C4.w[3] == BID_MIDPOINT256[(q4 - 59) as usize].w[3]
&& C4.w[2] < BID_MIDPOINT256[(q4 - 59) as usize].w[2])
|| (C4.w[3] == BID_MIDPOINT256[(q4 - 59) as usize].w[3]
&& C4.w[2] == BID_MIDPOINT256[(q4 - 59) as usize].w[2]
&& C4.w[1] < BID_MIDPOINT256[(q4 - 59) as usize].w[1])
|| (C4.w[3] == BID_MIDPOINT256[(q4 - 59) as usize].w[3]
&& C4.w[2] == BID_MIDPOINT256[(q4 - 59) as usize].w[2]
&& C4.w[1] == BID_MIDPOINT256[(q4 - 59) as usize].w[1]
&& C4.w[0] < BID_MIDPOINT256[(q4 - 59) as usize].w[0]) { // < 1/2 ulp
lt_half_ulp = true;
} else if C4.w[3] == BID_MIDPOINT256[(q4 - 59) as usize].w[3]
&& C4.w[2] == BID_MIDPOINT256[(q4 - 59) as usize].w[2]
&& C4.w[1] == BID_MIDPOINT256[(q4 - 59) as usize].w[1]
&& C4.w[0] == BID_MIDPOINT256[(q4 - 59) as usize].w[0] { // = 1/2 ulp
eq_half_ulp = true;
} else { // > 1/2 ulp
gt_half_ulp = true;
}

if p_sign == z_sign {
Expand Down Expand Up @@ -2773,10 +2770,15 @@ pub (crate) fn bid128_ext_fma(
}
// adjust exponent
e3 += 1;
if !is_midpoint_lt_even && !is_midpoint_gt_even && !is_inexact_lt_midpoint && !is_inexact_gt_midpoint {
if is_midpoint_lt_even0 || is_midpoint_gt_even0 || is_inexact_lt_midpoint0 || is_inexact_gt_midpoint0 {
is_inexact_lt_midpoint = true;
}
if !is_midpoint_lt_even
&& !is_midpoint_gt_even
&& !is_inexact_lt_midpoint
&& !is_inexact_gt_midpoint
&& (is_midpoint_lt_even0
|| is_midpoint_gt_even0
|| is_inexact_lt_midpoint0
|| is_inexact_gt_midpoint0) {
is_inexact_lt_midpoint = true;
}
} else {
// this is the result rounded with unbounded exponent, unless a
Expand Down Expand Up @@ -3086,12 +3088,15 @@ pub (crate) fn bid128_ext_fma(
}
// adjust exponent
e3 += x0;
if !is_midpoint_lt_even && !is_midpoint_gt_even
&& !is_inexact_lt_midpoint && !is_inexact_gt_midpoint {
if is_midpoint_lt_even0 || is_midpoint_gt_even0
|| is_inexact_lt_midpoint0 || is_inexact_gt_midpoint0 {
is_inexact_lt_midpoint = true;
}
if !is_midpoint_lt_even
&& !is_midpoint_gt_even
&& !is_inexact_lt_midpoint
&& !is_inexact_gt_midpoint
&& (is_midpoint_lt_even0
|| is_midpoint_gt_even0
|| is_inexact_lt_midpoint0
|| is_inexact_gt_midpoint0) {
is_inexact_lt_midpoint = true;
}
},
_ => {
Expand Down
2 changes: 1 addition & 1 deletion src/bid128_logb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub (crate) fn bid128_logb(x: &BID_UINT128, pfpsf: &mut _IDEC_flags) -> BID_UINT
#[cfg(target_endian = "big")]
BID_SWAP128(&mut x);

if unpack_BID128_value(&mut sign_x, &mut exponent_x, &mut CX, &x) == 0 {
if unpack_BID128_value(&mut sign_x, &mut exponent_x, &mut CX, x) == 0 {
// test if x is NaN/Inf
#[cfg(target_endian = "big")]
BID_SWAP128(&mut x);
Expand Down
6 changes: 4 additions & 2 deletions src/bid128_noncomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ pub (crate) fn bid128_is_normal(x: &BID_UINT128) -> bool {
}
exp = (x_exp >> 49) as i32 - 6176;
// test for subnormal values of x
if exp + q <= -6143 { false } else { true }
// if exp + q <= -6143 { false } else { true }
exp + q > -6143
}

/// Return true if and only if x is subnormal
Expand Down Expand Up @@ -241,7 +242,8 @@ pub (crate) fn bid128_is_canonical(x: &BID_UINT128) -> bool {
|| (sig_x.w[1] == 0x0000314dc6448d93u64
&& sig_x.w[0] < 0x38c15b0a00000000u64)
} else if (x.w[1] & MASK_INF) == MASK_INF { // infinity
return if (x.w[1] & 0x03ffffffffffffffu64) != 0 || x.w[0] != 0 { false } else { true };
// return if (x.w[1] & 0x03ffffffffffffffu64) != 0 || x.w[0] != 0 { false } else { true };
return !((x.w[1] & 0x03ffffffffffffffu64) != 0 || x.w[0] != 0);
}
// not NaN or infinity; extract significand to ensure it is canonical
sig_x.w[1] = x.w[1] & 0x0001ffffffffffffu64;
Expand Down
87 changes: 42 additions & 45 deletions src/bid128_to_int64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,37 +938,36 @@ pub (crate) fn bid128_to_int64_floor(x: &BID_UINT128, pfpsf: &mut _IDEC_flags) -
// else // if (f* > T*) then
// the result is inexact
if ind - 1 <= 2 {
if fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
if (fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign != 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign != 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
} else if ind - 1 <= 21 { // if 3 <= ind <= 21
if fstar.w[2] != 0 || fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
if (fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign != 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign != 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
} else { // if 22 <= ind <= 33
if fstar.w[3] != 0 || fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
if (fstar.w[3] != 0
|| fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign != 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign != 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
}
Expand Down Expand Up @@ -1545,38 +1544,36 @@ pub (crate) fn bid128_to_int64_ceil(x: &BID_UINT128, pfpsf: &mut _IDEC_flags) ->
// else // if (f* > T*) then
// the result is inexact
if ind - 1 <= 2 {
if fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
if (fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
} else if ind - 1 <= 21 { // if 3 <= ind <= 21
if fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
if (fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
} else { // if 22 <= ind <= 33
if fstar.w[3] != 0 || fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
if (fstar.w[3] != 0
|| fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
}
Expand Down
40 changes: 19 additions & 21 deletions src/bid128_to_uint64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1649,38 +1649,36 @@ pub (crate) fn bid128_to_uint64_ceil(x: &BID_UINT128, pfpsf: &mut _IDEC_flags) -
// else // if (f* > T*) then
// the result is inexact
if ind - 1 <= 2 {
if fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
if (fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
} else if ind - 1 <= 21 { // if 3 <= ind <= 21
if fstar.w[2] != 0
if (fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar .w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar .w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
} else { // if 22 <= ind <= 33
if fstar.w[3] != 0 || fstar.w[2] != 0
if (fstar.w[3] != 0
|| fstar.w[2] != 0
|| fstar.w[1] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
|| (fstar.w[1] == BID_TEN2MK128TRUNC[(ind - 1) as usize].w[1]
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]) {
if x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
&& fstar.w[0] > BID_TEN2MK128TRUNC[(ind - 1) as usize].w[0]))
&& x_sign == 0 { // positive and inexact
Cstar.w[0] += 1;
if Cstar.w[0] == 0x0 {
Cstar.w[1] += 1;
}
} // else the result is exact
}
Expand Down
Loading

0 comments on commit 201fd64

Please sign in to comment.