File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ macro_rules! native_fixed {
55
55
Self :: from_val( self . val + v. val)
56
56
}
57
57
58
+ pub fn checked_div( & self , v: Self ) -> Self {
59
+ cvlr_assume!( v. val > 0u64 . into( ) ) ;
60
+ Self :: from_val( self . val * Self :: BASE / v. val)
61
+ }
62
+
58
63
pub fn saturating_sub( & self , v: Self ) -> Self {
59
64
let val = if self . val <= v. val {
60
65
0u64 . into( )
@@ -93,11 +98,26 @@ macro_rules! native_fixed {
93
98
pub fn floor( & self ) -> Self {
94
99
self . to_floor( ) . into( )
95
100
}
101
+
102
+ pub fn to_ceil( & self ) -> NativeInt {
103
+ let floor = self . to_floor( ) ;
104
+ let rem = * self - Self :: new( floor) ;
105
+
106
+ if rem. val > 0u64 . into( ) {
107
+ floor + 1
108
+ } else {
109
+ floor
110
+ }
111
+ }
112
+
113
+ pub fn ceil( & self ) -> Self {
114
+ self . to_ceil( ) . into( )
115
+ }
96
116
}
97
117
98
118
impl <const F : u32 > cvlr_nondet:: Nondet for $NativeFixed<F > {
99
119
fn nondet( ) -> Self {
100
- Self :: new ( nondet( ) )
120
+ Self :: from_val ( nondet( ) )
101
121
}
102
122
}
103
123
@@ -147,6 +167,14 @@ macro_rules! native_fixed {
147
167
}
148
168
}
149
169
170
+ impl <const F : u32 > core:: ops:: Div <$NativeFixed<F >> for $NativeFixed<F > {
171
+ type Output = Self ;
172
+
173
+ fn div( self , v: Self ) -> Self :: Output {
174
+ self . checked_div( v)
175
+ }
176
+ }
177
+
150
178
impl <const F : u32 , T : Into <NativeInt >> core:: ops:: Div <T > for $NativeFixed<F > {
151
179
type Output = Self ;
152
180
You can’t perform that action at this time.
0 commit comments