  We present a precise determination of the apparent magnitude of the tip of
the red giant branch (TRGB) in the I (0.8 micron), J (1.25 micron), and K_S
(2.15 micron) bands from the luminosity function of a sample of data extracted
from the DENIS catalogue towards the Magellanic Clouds (Cioni et al. 2000).
  From the J and Ks magnitudes we derive bolometric magnitudes m_bol. We
present a new algorithm for the determination of the TRGB magnitude, which we
describe in detail and test extensively using Monte-Carlo simulations. We note
that any method that searches for a peak in the first derivative (used by most
authors) or the second derivative (used by us) of the observed luminosity
function does not yield an unbiased estimate for the actual magnitude of the
TRGB discontinuity. We stress the importance of correcting for this bias, which
is not generally done. We combine the results of our algorithm with theoretical
predictions to derive the distance modulus of the Magellanic Clouds. We obtain
m-M = 18.55 (0.04 formal, 0.08 systematic) for the Large Magellanic Cloud
(LMC), and m-M = 18.99 (0.03 formal, 0.08 systematic) for the Small Magellanic
Cloud (SMC). These are among the most accurate determinations of these
quantities currently available, which is a direct consequence of the large size
of our sample and the insensitivity of near infrared observations to dust
extinction.
