so, as an example calculation:
say difficulty is 1,000,000
last 2016 blocks took exactly 1 week.
does that mean next difficulty is 2,000,000 ...or is it an order of magnitude thing, like next diff 10,000,000?
(sorry, i don't really know how the total network hash rate might affect things like that)
It will be 2,000,000 .
Also, difficulty cannot change more than four-fold in a single retarget (that is, cannot become more than 4 times higher or lower at once).
The code that calculates the new difficulty is in main.cpp file, function GetNextWorkRequired.
Code on Github