1 /*
2 * Mathlib : A C Library of Special Functions
3 * Copyright (C) 1998 Ross Ihaka
4 * Copyright (C) 2000-2002 The R Core Team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, a copy is available at
18 * http://www.r-project.org/Licenses/
19 *
20 * DESCRIPTION
21 *
22 * The distribution function of the Weibull distribution.
23 */
24
25 #include "nmath.h"
26 #include "dpq.h"
27
pweibull(double x,double shape,double scale,int lower_tail,int log_p)28 double pweibull(double x, double shape, double scale, int lower_tail, int log_p)
29 {
30 #ifdef IEEE_754
31 if (ISNAN(x) || ISNAN(shape) || ISNAN(scale))
32 return x + shape + scale;
33 #endif
34 if(shape <= 0 || scale <= 0) ML_ERR_return_NAN;
35
36 if (x <= 0)
37 return R_DT_0;
38 x = -pow(x / scale, shape);
39 if (lower_tail)
40 return (log_p
41 /* log(1 - exp(x)) for x < 0 : */
42 ? R_Log1_Exp(x) : -expm1(x));
43 /* else: !lower_tail */
44 return R_D_exp(x);
45 }
46