-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle error in hint
UINT256_MUL_DIV_MOD
when divides by zero (#1367)
* fix bug * Add test * Add some checks to div_mod_floors of BigUints * Update Changelog * Remove unnecesarry zero check * Remove unnecesarry zero check * Remove unnecesary import
- Loading branch information
Showing
4 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
struct MyStruct0 { | ||
low: felt, | ||
high: felt, | ||
} | ||
func main() { | ||
let a = MyStruct0(low=0, high=0); | ||
let b = MyStruct0(low=0, high=0); | ||
let div = MyStruct0(low=0, high=0); | ||
hint_func(a, b, div); | ||
return(); | ||
} | ||
func hint_func(a: MyStruct0, b: MyStruct0, div: MyStruct0) -> (MyStruct0, MyStruct0, MyStruct0) { | ||
alloc_locals; | ||
local quotient_low: MyStruct0; | ||
local quotient_high: MyStruct0; | ||
local remainder: MyStruct0; | ||
%{ | ||
a = (ids.a.high << 128) + ids.a.low | ||
b = (ids.b.high << 128) + ids.b.low | ||
div = (ids.div.high << 128) + ids.div.low | ||
quotient, remainder = divmod(a * b, div) | ||
|
||
ids.quotient_low.low = quotient & ((1 << 128) - 1) | ||
ids.quotient_low.high = (quotient >> 128) & ((1 << 128) - 1) | ||
ids.quotient_high.low = (quotient >> 256) & ((1 << 128) - 1) | ||
ids.quotient_high.high = quotient >> 384 | ||
ids.remainder.low = remainder & ((1 << 128) - 1) | ||
ids.remainder.high = remainder >> 128 | ||
%} | ||
return(quotient_low, quotient_high, remainder); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters