I love the E39. It's an incredible design. If I buy one though it's gonna be an M5. I think the M52 was only offered until 1999 when they phased out the E36. If its a 2000 it might have the M54. Don't quote me in that because my 5 Series knowledge isn't as extensive. I have heard but cannot confirm at this time that some of the V8 engines had numerous issues. The 3 Litre ones from what I understand.
The E39 weighs over 700lbs more then my E36 with the same engine. Therefore if your looking for performance then go for a 540 at the minimum. It's the same in that the 328i is the closest to the M3 that the 540 is the closest to the M5. However they only made around 20,000 M5's per year.