mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-23 11:41:58 +00:00
division fix
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
target
|
||||
Cargo.lock
|
||||
.vscode
|
@ -613,7 +613,7 @@ impl Interpreter {
|
||||
.value_stack_mut()
|
||||
.pop_pair_as::<T>()
|
||||
.map(|(left, right)| (left.transmute_into(), right.transmute_into()))
|
||||
.map(|(left, right)| left.div(right))
|
||||
.map(|(left, right)| left.div(right))?
|
||||
.map(|v| v.transmute_into())
|
||||
.map(|v| context.value_stack_mut().push(v.into()))
|
||||
.map(|_| InstructionOutcome::RunNextInstruction)
|
||||
@ -625,7 +625,7 @@ impl Interpreter {
|
||||
.value_stack_mut()
|
||||
.pop_pair_as::<T>()
|
||||
.map(|(left, right)| (left.transmute_into(), right.transmute_into()))
|
||||
.map(|(left, right)| left.rem(right))
|
||||
.map(|(left, right)| left.rem(right))?
|
||||
.map(|v| v.transmute_into())
|
||||
.map(|v| context.value_stack_mut().push(v.into()))
|
||||
.map(|_| InstructionOutcome::RunNextInstruction)
|
||||
|
@ -68,7 +68,7 @@ pub trait ArithmeticOps<T> {
|
||||
/// Multiply two values.
|
||||
fn mul(self, other: T) -> T;
|
||||
/// Divide two values.
|
||||
fn div(self, other: T) -> T;
|
||||
fn div(self, other: T) -> Result<T, Error>;
|
||||
}
|
||||
|
||||
/// Integer value.
|
||||
@ -84,7 +84,7 @@ pub trait Integer<T>: ArithmeticOps<T> {
|
||||
/// Get right bit rotation result.
|
||||
fn rotr(self, other: T) -> T;
|
||||
/// Get division remainder.
|
||||
fn rem(self, other: T) -> T;
|
||||
fn rem(self, other: T) -> Result<T, Error>;
|
||||
}
|
||||
|
||||
/// Float-point value.
|
||||
@ -541,7 +541,10 @@ macro_rules! impl_integer_arithmetic_ops {
|
||||
fn add(self, other: $type) -> $type { self.wrapping_add(other) }
|
||||
fn sub(self, other: $type) -> $type { self.wrapping_sub(other) }
|
||||
fn mul(self, other: $type) -> $type { self.wrapping_mul(other) }
|
||||
fn div(self, other: $type) -> $type { self.wrapping_div(other) }
|
||||
fn div(self, other: $type) -> Result<$type, Error> {
|
||||
if other == 0 { Err(Error::Value("Division by zero".to_owned())) }
|
||||
else { Ok(self.wrapping_div(other)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -557,7 +560,7 @@ macro_rules! impl_float_arithmetic_ops {
|
||||
fn add(self, other: $type) -> $type { self + other }
|
||||
fn sub(self, other: $type) -> $type { self - other }
|
||||
fn mul(self, other: $type) -> $type { self * other }
|
||||
fn div(self, other: $type) -> $type { self / other }
|
||||
fn div(self, other: $type) -> Result<$type, Error> { Ok(self / other) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -573,7 +576,10 @@ macro_rules! impl_integer {
|
||||
fn count_ones(self) -> $type { self.count_ones() as $type }
|
||||
fn rotl(self, other: $type) -> $type { self.rotate_left(other as u32) }
|
||||
fn rotr(self, other: $type) -> $type { self.rotate_right(other as u32) }
|
||||
fn rem(self, other: $type) -> $type { self.wrapping_rem(other) }
|
||||
fn rem(self, other: $type) -> Result<$type, Error> {
|
||||
if other == 0 { Err(Error::Value("Division by zero".to_owned())) }
|
||||
else { Ok(self.wrapping_rem(other)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user