c - R语言源码——C代码中的 `NOMORE_FOR_THREADS`是什么

标签 c r gamma-function

我正在查看函数 gamma() 的 R 源代码,它指向 this C source file .

代码片段如下:

#ifdef NOMORE_FOR_THREADS
    static int ngam = 0;
    static double xmin = 0, xmax = 0., xsml = 0., dxrel = 0.;

    /* Initialize machine dependent constants, the first time gamma() is called.
    FIXME for threads ! */
    if (ngam == 0) {
    ngam = chebyshev_init(gamcs, 42, DBL_EPSILON/20);/*was .1*d1mach(3)*/
    gammalims(&xmin, &xmax);/*-> ./gammalims.c */
    xsml = exp(fmax2(log(DBL_MIN), -log(DBL_MAX)) + 0.01);
    /*   = exp(.01)*DBL_MIN = 2.247e-308 for IEEE */
    dxrel = sqrt(DBL_EPSILON);/*was sqrt(d1mach(4)) */
    }
#else
/* For IEEE double precision DBL_EPSILON = 2^-52 = 2.220446049250313e-16 :
 * (xmin, xmax) are non-trivial, see ./gammalims.c
 * xsml = exp(.01)*DBL_MIN
 * dxrel = sqrt(DBL_EPSILON) = 2 ^ -26
*/
# define ngam 22
# define xmin -170.5674972726612
# define xmax  171.61447887182298
# define xsml 2.2474362225598545e-308
# define dxrel 1.490116119384765696e-8
#endif

现在我明白这段代码正在初始化变量值,如 ngamxsmldxrel 等。但我不知道了解什么是 NOMORE_FOR_THREADS

我找不到它的定义位置,所以我很困惑它什么时候进入 #ifdef 子句,或者只是进入 #else 子句并定义符合 IEEE 标准的变量。

如果有人能阐明什么是 NOMORE_FOR_THREADS 或定义它的位置,那将非常有帮助。

感谢您的帮助。

最佳答案

看起来 #ifdef 是在修订版 13433 中添加的:

> svn log -vr13433
------------------------------------------------------------------------
r13433 | maechler | 2001-04-10 10:05:54 -0500 (Tue, 10 Apr 2001) | 2 lines
Changed paths:
   M /trunk/src/nmath/beta.c
   M /trunk/src/nmath/gamma.c
   M /trunk/src/nmath/lgamma.c
   M /trunk/src/nmath/lgammacor.c

globals now #ifdef NOMORE_FOR_THREADS

------------------------------------------------------------------------

这是与之前版本的不同之处:

> svn diff -r13432:13433 src/nmath/gamma.c
Index: src/nmath/gamma.c
===================================================================
--- src/nmath/gamma.c   (revision 13432)
+++ src/nmath/gamma.c   (revision 13433)
@@ -1,7 +1,7 @@
 /*
  *  Mathlib : A C Library of Special Functions
  *  Copyright (C) 1998 Ross Ihaka
- *  Copyright (C) 2000 The R Development Core Team
+ *  Copyright (C) 2000-2001 The R Development Core Team
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@

 double gammafn(double x)
 {
-    static /* const */ double gamcs[42] = {
+    const double gamcs[42] = {
    +.8571195590989331421920062399942e-2,
    +.4415381324841006757191315771652e-2,
    +.5685043681599363378632664588789e-1,
@@ -89,6 +89,7 @@
     double y;
     double sinpiy, value;

+#ifdef NOMORE_FOR_THREADS
     static int ngam = 0;
     static double xmin = 0, xmax = 0., xsml = 0., dxrel = 0.;

@@ -101,6 +102,18 @@
    /*   = exp(.01)*DBL_MIN = 2.247e-308 for IEEE */
    dxrel = sqrt(1/DBL_EPSILON);/*was (1/d1mach(4)) */
     }
+#else
+/* For IEEE double precision DBL_EPSILON = 2^-52 = 2.220446049250313e-16 :
+ * (xmin, xmax) are non-trivial, see ./gammalims.c 
+ * xsml = exp(.01)*DBL_MIN 
+ * dxrel = sqrt(1/DBL_EPSILON) = 2 ^ 26
+*/
+# define ngam 22
+# define xmin -170.5674972726612
+# define xmax  171.61447887182298
+# define xsml 2.2474362225598545e-308
+# define dxrel 67108864.
+#endif

     if(ISNAN(x)) return x;

我没有看到 NOMORE_FOR_THREADS 在该修订版的源代码中的任何地方、添加它后的接下来的几百个修订版或当前修订版中定义。它有可能(虽然看起来不太可能)可以在某些系统头文件中定义。它似乎更有可能通过命令行参数指定。

关于c - R语言源码——C代码中的 `NOMORE_FOR_THREADS`是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33489361/

相关文章:

c - 如何在C中获取主板类型?

c - PIC18F452 的 PORTB 不工作

找不到-lCommunication collect2 : error: ld returned 1 exit status

r - 在 ggplot2 中对齐/设置边距/图形区域的宽度

c - C语言中的软件中断?

r - 在 R 中解码 URL 字符串向量

威 bool 分布的更新函数

python - scipy.special.gammaln 的精度

c++ - 任意精度 Gamma 函数

ggplot 中的数据重新排序