solve overflow of left arithmetic shift
@@ -722,18 +722,12 @@ fn shr(&self, n1: Number, n2: Number) -> Result<Number, MachineStub> {
match (n1, n2) {
(Number::Fixnum(n1), Number::Fixnum(n2)) => {
- if let Ok(n2) = u32::try_from(n2) {
- if let Some(result) = n1.checked_shr(n2) {
- return Ok(Number::from(result));
- }
- }
-
let n1 = Integer::from(n1);
- let n2 = Integer::from(n2);
- match n2.to_u32() {
- Some(n2) => Ok(Number::from(n1 >> n2)),
- _ => Ok(Number::from(n1 >> u32::max_value())),
+ if let Ok(n2) = u32::try_from(n2) {
+ return Ok(Number::from(n1 >> n2));
+ } else {
+ return Ok(Number::from(n1 >> u32::max_value()));
}
}
(Number::Fixnum(n1), Number::Integer(n2)) => {
@@ -780,23 +774,12 @@ fn shl(&self, n1: Number, n2: Number) -> Result<Number, MachineStub> {
match (n1, n2) {
(Number::Fixnum(n1), Number::Fixnum(n2)) => {
- if let Ok(n2) = u32::try_from(n2) {
- if n2 < 63 {
- if let Some(result) = n1.checked_shl(n2) {
- return Ok(Number::from(result));
- }
- } else {
let n1 = Integer::from(n1);
- return Ok(Number::from(n1 << n2));
- }
- }
-
- let n1 = Integer::from(n1);
- let n2 = Integer::from(n2);
- match n2.to_u32() {
- Some(n2) => Ok(Number::from(n1 << n2)),
- _ => Ok(Number::from(n1 << u32::max_value())),
+ if let Ok(n2) = u32::try_from(n2) {
+ return Ok(Number::from(n1 << n2));
+ } else {
+ return Ok(Number::from(n1 << u32::max_value()));
}
}
(Number::Fixnum(n1), Number::Integer(n2)) => {
