/src/r-source/src/nmath/dlogis.c
Line | Count | Source |
1 | | /* |
2 | | * R : A Computer Language for Statistical Data Analysis |
3 | | * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka |
4 | | * Copyright (C) 2000 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 | | * https://www.R-project.org/Licenses/ |
19 | | */ |
20 | | |
21 | | #include "nmath.h" |
22 | | #include "dpq.h" |
23 | | |
24 | | double dlogis(double x, double location, double scale, int give_log) |
25 | 198 | { |
26 | 198 | double e, f; |
27 | 198 | #ifdef IEEE_754 |
28 | 198 | if (ISNAN(x) || ISNAN(location) || ISNAN(scale)) |
29 | 0 | return x + location + scale; |
30 | 198 | #endif |
31 | 198 | if (scale <= 0.0) |
32 | 132 | ML_WARN_return_NAN; |
33 | | |
34 | 132 | x = fabs((x - location) / scale); |
35 | 132 | e = exp(-x); |
36 | 132 | f = 1.0 + e; |
37 | 132 | return give_log ? -(x + log(scale * f * f)) : e / (scale * f * f); |
38 | 198 | } |