@@ -561,7 +561,8 @@ impl Expr {
561
561
}
562
562
563
563
#[ allow( clippy:: should_implement_trait) ]
564
- pub fn div ( left : Expr , right : Expr ) -> Self {
564
+ /// Encode Rust's unsigned division. This is the same as Viper's division.
565
+ pub fn unsigned_div ( left : Expr , right : Expr ) -> Self {
565
566
Expr :: BinOp (
566
567
BinaryOpKind :: Div ,
567
568
Box :: new ( left) ,
@@ -570,6 +571,22 @@ impl Expr {
570
571
)
571
572
}
572
573
574
+ #[ allow( clippy:: should_implement_trait) ]
575
+ /// Encode Rust's division. This is *not* Viper's division.
576
+ pub fn div ( left : Expr , right : Expr ) -> Self {
577
+ Expr :: ite (
578
+ Expr :: or (
579
+ Expr :: ge_cmp ( left. clone ( ) , 0 . into ( ) ) ,
580
+ Expr :: eq_cmp ( Expr :: modulo ( left. clone ( ) , right. clone ( ) ) , 0 . into ( ) ) ,
581
+ ) ,
582
+ // positive value or left % right == 0
583
+ Expr :: unsigned_div ( left. clone ( ) , right. clone ( ) ) ,
584
+ // negative value
585
+ Expr :: minus ( Expr :: unsigned_div ( Expr :: minus ( left) , right) ) ,
586
+ )
587
+ }
588
+
589
+ /// Encode Rust's unsigned reminder. This is the same as Viper's modulo.
573
590
pub fn modulo ( left : Expr , right : Expr ) -> Self {
574
591
Expr :: BinOp (
575
592
BinaryOpKind :: Mod ,
@@ -580,7 +597,7 @@ impl Expr {
580
597
}
581
598
582
599
#[ allow( clippy:: should_implement_trait) ]
583
- /// Encode Rust reminder. This is *not* Viper modulo.
600
+ /// Encode Rust's signed reminder. This is *not* Viper's modulo.
584
601
pub fn rem ( left : Expr , right : Expr ) -> Self {
585
602
let abs_right = Expr :: ite (
586
603
Expr :: ge_cmp ( right. clone ( ) , 0 . into ( ) ) ,
0 commit comments