1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/* actuar: Actuarial Functions and Heavy Tailed Distributions
*
* Functions to calculate raw and limited moments for the Uniform
* distribution. See ../R/UniformSupp.R for details.
*
* AUTHORS: Christophe Dutang and Vincent Goulet <vincent.goulet@act.ulaval.ca>
*/
#include <R.h>
#include <Rmath.h>
#include "locale.h"
#include "dpq.h"
double munif(double order, double min, double max, int give_log)
{
#ifdef IEEE_754
if (ISNAN(order) || ISNAN(min) || ISNAN(max))
return order + min + max;
#endif
if (!R_FINITE(min) ||
!R_FINITE(max) ||
min >= max)
return R_NaN;
if (order == -1.0)
return (log(fabs(max)) - log(fabs(min))) / (max - min);
double tmp = order + 1;
return (R_pow(max, tmp) - R_pow(min, tmp)) / ((max - min) * tmp);
}
double levunif(double limit, double min, double max, double order, int give_log)
{
#ifdef IEEE_754
if (ISNAN(limit) || ISNAN(min) || ISNAN(max) || ISNAN(order))
return limit + min + max + order;
#endif
if (!R_FINITE(min) ||
!R_FINITE(max) ||
min >= max)
return R_NaN;
if (limit <= min)
return R_pow(limit, order);
if (limit >= max)
return munif(order, min, max, give_log);
if (order == -1.0)
return (log(fabs(limit)) - log(fabs(min))) / (max - min) +
(max - limit) / (limit * (max - min));
double tmp = order + 1;
return (R_pow(limit, tmp) - R_pow(min, tmp)) / ((max - min) * tmp) +
R_pow(limit, order) * (max - limit) / (max - min);
}
double mgfunif(double t, double min, double max, int give_log)
{
#ifdef IEEE_754
if (ISNAN(t) || ISNAN(min) || ISNAN(max))
return t + min + max;
#endif
if (!R_FINITE(min) ||
!R_FINITE(max) ||
min >= max)
return R_NaN;
if (t == 0.0)
return ACT_D__1;
double tmp1, tmp2;
tmp1 = exp(t * max) - exp(t * min);
tmp2 = t * (max - min);
return ACT_D_exp(log(tmp1) - log(tmp2));
}
|