File tree Expand file tree Collapse file tree 3 files changed +7
-7
lines changed
Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 1717{
1818 pub fn new ( precision : u32 ) -> Self {
1919 let low = B :: ZERO ;
20- let high = B :: ONE << precision;
20+ let high = ( B :: ONE << precision) - B :: ONE ;
2121
2222 Self {
2323 precision,
Original file line number Diff line number Diff line change @@ -209,13 +209,13 @@ where
209209 fn normalise ( & mut self ) -> io:: Result < ( ) > {
210210 while self . state . high < self . state . half ( ) || self . state . low >= self . state . half ( ) {
211211 if self . state . high < self . state . half ( ) {
212- self . state . high <<= 1 ;
212+ self . state . high = ( self . state . high << 1 ) + B :: ONE ;
213213 self . state . low <<= 1 ;
214214 self . x <<= 1 ;
215215 } else {
216216 // self.low >= self.half()
217217 self . state . low = ( self . state . low - self . state . half ( ) ) << 1 ;
218- self . state . high = ( self . state . high - self . state . half ( ) ) << 1 ;
218+ self . state . high = ( ( self . state . high - self . state . half ( ) ) << 1 ) + B :: ONE ;
219219 self . x = ( self . x - self . state . half ( ) ) << 1 ;
220220 }
221221
@@ -228,7 +228,7 @@ where
228228 && self . state . high < ( self . state . three_quarter ( ) )
229229 {
230230 self . state . low = ( self . state . low - self . state . quarter ( ) ) << 1 ;
231- self . state . high = ( self . state . high - self . state . quarter ( ) ) << 1 ;
231+ self . state . high = ( ( self . state . high - self . state . quarter ( ) ) << 1 ) + B :: ONE ;
232232 self . x = ( self . x - self . state . quarter ( ) ) << 1 ;
233233
234234 if self . input . next_bit ( ) ? == Some ( true ) {
Original file line number Diff line number Diff line change @@ -201,12 +201,12 @@ where
201201 while self . state . high < self . state . half ( ) || self . state . low >= self . state . half ( ) {
202202 if self . state . high < self . state . half ( ) {
203203 self . emit ( false ) ?;
204- self . state . high <<= 1 ;
204+ self . state . high = ( self . state . high << 1 ) + B :: ONE ;
205205 self . state . low <<= 1 ;
206206 } else {
207207 self . emit ( true ) ?;
208208 self . state . low = ( self . state . low - self . state . half ( ) ) << 1 ;
209- self . state . high = ( self . state . high - self . state . half ( ) ) << 1 ;
209+ self . state . high = ( ( self . state . high - self . state . half ( ) ) << 1 ) + B :: ONE ;
210210 }
211211 }
212212
@@ -215,7 +215,7 @@ where
215215 {
216216 self . pending += 1 ;
217217 self . state . low = ( self . state . low - self . state . quarter ( ) ) << 1 ;
218- self . state . high = ( self . state . high - self . state . quarter ( ) ) << 1 ;
218+ self . state . high = ( ( self . state . high - self . state . quarter ( ) ) << 1 ) + B :: ONE ;
219219 }
220220
221221 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments