/src/r-source/src/nmath/dcauchy.c
Line | Count | Source |
1 | | /* |
2 | | * Mathlib : A C Library of Special Functions |
3 | | * Copyright (C) 1998 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 | | * DESCRIPTION |
21 | | * |
22 | | * The density of the Cauchy distribution. |
23 | | */ |
24 | | |
25 | | #include "nmath.h" |
26 | | #include "dpq.h" |
27 | | |
28 | | double dcauchy(double x, double location, double scale, int give_log) |
29 | 0 | { |
30 | 0 | double y; |
31 | 0 | #ifdef IEEE_754 |
32 | | /* NaNs propagated correctly */ |
33 | 0 | if (ISNAN(x) || ISNAN(location) || ISNAN(scale)) |
34 | 0 | return x + location + scale; |
35 | 0 | #endif |
36 | 0 | if (scale <= 0) ML_WARN_return_NAN; |
37 | |
|
38 | 0 | y = (x - location) / scale; |
39 | 0 | return give_log ? |
40 | 0 | - log(M_PI * scale * (1. + y * y)) : |
41 | 0 | 1. / (M_PI * scale * (1. + y * y)); |
42 | 0 | } |