Created
July 29, 2015 02:55
-
-
Save guilleiguaran/8d5fd1a38c18e0ea4558 to your computer and use it in GitHub Desktop.
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
int log(int x) | |
//@requires x >= 1; | |
//@ensures \result >= 0; | |
//@ensures (1 << \result) <= x; | |
{ int r = 0; | |
int y = x; | |
while (y > 1) | |
//@loop_invariant y >= 1 && r >= 0; | |
//@loop_invariant y * (1 << r) <= x; | |
{ | |
y = y / 2; | |
//@assert r < x; | |
r = r + 1; | |
} | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment