  Many experimental quantities show a power-law distribution $p(x)\propto
x^{-\alpha}$. In astrophysics, examples are: size distribution of dust grains
or luminosity function of galaxies. Such distributions are characterized by the
exponent $\alpha$ and by the extremes $x_\text{min}$ $x_\text{max}$ where the
distribution extends. There are no mathematical tools that derive the three
unknowns at the same time. In general, one estimates a set of $\alpha$
corresponding to different guesses of $x_\text{min}$ $x_\text{max}$. Then, the
best set of values describing the observed data is selected a posteriori. In
this paper, we present a tool that finds contextually the three parameters
based on simple assumptions on how the observed values $x_i$ populate the
unknown range between $x_\text{min}$ and $x_\text{max}$ for a given $\alpha$.
Our tool, freely downloadable, finds the best values through a non-linear
least-squares fit. We compare our technique with the maximum likelihood
estimators for power-law distributions, both truncated and not. Through
simulated data, we show for each method the reliability of the computed
parameters as a function of the number $N$ of data in the sample. We then apply
our method to observed data to derive: i) the slope of the core mass function
in the Perseus star-forming region, finding two power-law distributions:
$\alpha=2.576$ between $1.06\,M_{\sun}$ and $3.35\,M_{\sun}$, $\alpha=3.39$
between $3.48\,M_{\sun}$ and $33.4\,M_{\sun}$; ii) the slope of the
$\gamma$-ray spectrum of the blazar J0011.4+0057, extracted from the Fermi-LAT
archive. For the latter case, we derive $\alpha=2.89$ between 1,484~MeV and
28.7~GeV; then we derive the time-resolved slopes using subsets 200 photons
each.
