The R Project SVN R

Rev

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

Rev 42302 Rev 44737
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-2001 The R Development Core Team
4
 *  Copyright (C) 2000-2008 The R Development Core Team
5
 *
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
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
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
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
9
 *  (at your option) any later version.
Line 28... Line 28...
28
 
28
 
29
#include "nmath.h"
29
#include "nmath.h"
30
 
30
 
31
double rt(double df)
31
double rt(double df)
32
{
32
{
33
    double num;
-
 
34
    if (ISNAN(df) || df <= 0.0)	ML_ERR_return_NAN;
33
    if (ISNAN(df) || df <= 0.0)	ML_ERR_return_NAN;
35
 
34
 
36
    if(!R_FINITE(df))
35
    if(!R_FINITE(df))
37
	return norm_rand();
36
	return norm_rand();
38
    else {
37
    else {
39
/* Some compilers (including MW6) evaluated this from right to left
38
/* Some compilers (including MW6) evaluated this from right to left
40
	return norm_rand() / sqrt(rchisq(df) / df); */
39
	return norm_rand() / sqrt(rchisq(df) / df); */
41
	num = norm_rand();
40
	double num = norm_rand();
42
	return num / sqrt(rchisq(df) / df);
41
	return num / sqrt(rchisq(df) / df);
43
    }
42
    }
44
}
43
}