The R Project SVN R

Rev

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

Rev 69128 Rev 69237
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-12 The R Core Team
4
 *  Copyright (C) 2000-15 The R Core Team
5
 *  Copyright (C) 2004-8 The R Foundation
5
 *  Copyright (C) 2004-15 The R Foundation
6
 *
6
 *
7
 *  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
8
 *  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
9
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
10
 *  (at your option) any later version.
Line 36... Line 36...
36
 
36
 
37
#ifdef IEEE_754
37
#ifdef IEEE_754
38
    if (ISNAN(x) || ISNAN(df) || ISNAN(ncp))
38
    if (ISNAN(x) || ISNAN(df) || ISNAN(ncp))
39
	return x + df + ncp;
39
	return x + df + ncp;
40
#endif
40
#endif
41
    if (ncp < 0 || df <= 0) ML_ERR_return_NAN;
-
 
42
 
41
 
43
    if (!R_FINITE(df) || !R_FINITE(ncp))
42
    if (!R_FINITE(df) || !R_FINITE(ncp) || ncp < 0 || df < 0)
44
	ML_ERR_return_NAN;
43
    	ML_ERR_return_NAN;
45
 
44
 
46
    if(x < 0) return R_D__0;
45
    if(x < 0) return R_D__0;
47
    if(x == 0 && df < 2.)
46
    if(x == 0 && df < 2.)
48
	return ML_POSINF;
47
	return ML_POSINF;
49
    if(ncp == 0)
48
    if(ncp == 0)
50
	return dchisq(x, df, give_log);
49
	return (df > 0) ? dchisq(x, df, give_log) : R_D__0;
51
    if(x == ML_POSINF) return R_D__0;
50
    if(x == ML_POSINF) return R_D__0;
52
 
51
 
53
    ncp2 = 0.5 * ncp;
52
    ncp2 = 0.5 * ncp;
54
 
53
 
55
    /* find max element of sum */
54
    /* find max element of sum */