@@ -77,22 +77,25 @@ contract Pot is DSNote {
77
77
uint256 constant ONE = 10 ** 27 ;
78
78
function rpow (uint x , uint n , uint base ) internal pure returns (uint z ) {
79
79
assembly {
80
- switch x case 0 { switch n case 0 {z := base} default {z := 0 } }
80
+ switch n case 0 { z := base }
81
81
default {
82
- switch mod (n, 2 ) case 0 { z := base } default { z := x }
83
- let half := div (base, 2 ) // for rounding.
84
- for { n := div (n, 2 ) } n { n := div (n,2 ) } {
85
- let xx := mul (x, x)
86
- if iszero (eq (div (xx, x), x)) { revert (0 ,0 ) }
87
- let xxRound := add (xx, half)
88
- if lt (xxRound, xx) { revert (0 ,0 ) }
89
- x := div (xxRound, base)
90
- if mod (n,2 ) {
91
- let zx := mul (z, x)
92
- if and (iszero (iszero (x)), iszero (eq (div (zx, x), z))) { revert (0 ,0 ) }
93
- let zxRound := add (zx, half)
94
- if lt (zxRound, zx) { revert (0 ,0 ) }
95
- z := div (zxRound, base)
82
+ switch x case 0 { z := 0 }
83
+ default {
84
+ switch mod (n, 2 ) case 0 { z := base } default { z := x }
85
+ let half := div (base, 2 ) // for rounding.
86
+ for { n := div (n, 2 ) } n { n := div (n,2 ) } {
87
+ let xx := mul (x, x)
88
+ if iszero (eq (div (xx, x), x)) { revert (0 ,0 ) }
89
+ let xxRound := add (xx, half)
90
+ if lt (xxRound, xx) { revert (0 ,0 ) }
91
+ x := div (xxRound, base)
92
+ if mod (n,2 ) {
93
+ let zx := mul (z, x)
94
+ if and (iszero (iszero (x)), iszero (eq (div (zx, x), z))) { revert (0 ,0 ) }
95
+ let zxRound := add (zx, half)
96
+ if lt (zxRound, zx) { revert (0 ,0 ) }
97
+ z := div (zxRound, base)
98
+ }
96
99
}
97
100
}
98
101
}
0 commit comments