The R Project SVN R

Rev

Rev 8431 | Rev 42302 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8431 Rev 24177
Line 1... Line 1...
1
/*
1
/*
2
 *  Mathlib : A C Library of Special Functions
2
 *  Mathlib : A C Library of Special Functions
3
 *  Copyright (C) 1998 Ross Ihaka
3
 *  Copyright (C) 1998 Ross Ihaka
4
 *  Copyright (C) 2000 The R Development Core Team
4
 *  Copyright (C) 2000	    The R Development Core Team
-
 
5
 *  Copyright (C) 2003	    The R Foundation
5
 *
6
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  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
 *  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
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *  (at your option) any later version.
Line 34... Line 35...
34
{
35
{
35
#ifdef IEEE_754
36
#ifdef IEEE_754
36
    if (ISNAN(x) || ISNAN(mu) || ISNAN(sigma))
37
    if (ISNAN(x) || ISNAN(mu) || ISNAN(sigma))
37
	return x + mu + sigma;
38
	return x + mu + sigma;
38
#endif
39
#endif
-
 
40
    if(!R_FINITE(sigma)) return R_D__0;
-
 
41
    if(!R_FINITE(x) && mu == x) return ML_NAN;/* x-mu is NaN */
-
 
42
    if (sigma <= 0) {
39
    if (sigma <= 0) ML_ERR_return_NAN;
43
	if (sigma < 0) ML_ERR_return_NAN;
-
 
44
	/* sigma == 0 */
-
 
45
	return (x == mu) ? ML_POSINF : R_D__0;
40
 
46
    }
41
    x = (x - mu) / sigma;
47
    x = (x - mu) / sigma;
42
 
48
 
-
 
49
    if(!R_FINITE(x)) return R_D__0;
43
    return (give_log ?
50
    return (give_log ?
44
	    -(M_LN_SQRT_2PI  +	0.5 * x * x + log(sigma)) :
51
	    -(M_LN_SQRT_2PI  +	0.5 * x * x + log(sigma)) :
45
	    M_1_SQRT_2PI * exp(-0.5 * x * x)  /	  sigma);
52
	    M_1_SQRT_2PI * exp(-0.5 * x * x)  /	  sigma);
46
    /* M_1_SQRT_2PI = 1 / sqrt(2 * pi) */
53
    /* M_1_SQRT_2PI = 1 / sqrt(2 * pi) */
47
}
54
}