Skip to content

Commit

Permalink
· Rounding mode names changed
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosga committed Mar 6, 2024
1 parent 56323a8 commit 94fd39c
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 250 deletions.
226 changes: 113 additions & 113 deletions src/bid128_add.rs

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/bid128_div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand 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);
Expand All @@ -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
Expand Down Expand 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);
Expand All @@ -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
Expand Down
104 changes: 52 additions & 52 deletions src/bid128_fma.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/bid128_llrint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
8 changes: 4 additions & 4 deletions src/bid128_lrint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bid128_modf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/bid128_nearbyint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ 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;
res.w[0] = 0x0000000000000000u64;
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 {
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions src/bid128_quantize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions src/bid128_round_integral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/bid128_sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/bid128_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/bid64_to_bid128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand Down
Loading

0 comments on commit 94fd39c

Please sign in to comment.