/cephes/cprob.patch

https://github.com/ychaim/qml · Patch · 181 lines · 162 code · 19 blank · 0 comment · 0 complexity · ab959e8db512df6094e23518da409079 MD5 · raw file

  1. --- cprob/cprob.mak
  2. +++ cprob/cprob.mak
  3. @@ -1,14 +1,14 @@
  4. # Makefile for probability integrals.
  5. # Be sure to set the type of computer and endianness in mconf.h.
  6. -CC = gcc
  7. -CFLAGS = -O2 -Wall
  8. INCS = mconf.h
  9. OBJS = bdtr.o btdtr.o chdtr.o drand.o expx2.o fdtr.o gamma.o gdtr.o \
  10. -igam.o igami.o incbet.o incbi.o mtherr.o nbdtr.o ndtr.o ndtri.o pdtr.o \
  11. -stdtr.o unity.o polevl.o const.o
  12. +igam.o igami.o incbet.o incbi.o nbdtr.o ndtr.o ndtri.o pdtr.o \
  13. +stdtr.o unity.o polevl.o const.o kolmogorov.o
  14. libprob.a: $(OBJS) $(INCS)
  15. - ar rv libprob.a $(OBJS)
  16. - ranlib libprob.a
  17. + $(AR) rv libprob.a $(OBJS)
  18. + $(RANLIB) libprob.a
  19. +
  20. +include make.inc
  21. --- cprob/mconf.h
  22. +++ cprob/mconf.h
  23. @@ -127,7 +127,7 @@
  24. /* Intel IEEE, low order words come first:
  25. */
  26. -/* #define IBMPC 1 */
  27. +#define IBMPC 1
  28. /* Motorola IEEE, high order words come first
  29. * (Sun 680x0 workstation):
  30. @@ -140,7 +140,7 @@
  31. * roundoff problems in pow.c:
  32. * (Sun SPARCstation)
  33. */
  34. -#define UNK 1
  35. +/* #define UNK 1 */
  36. /* If you define UNK, then be sure to set BIGENDIAN properly. */
  37. #ifdef FLOAT_WORDS_BIGENDIAN
  38. @@ -186,14 +186,15 @@
  39. See atan.c and clog.c. */
  40. #define ANSIC 1
  41. -/* Get ANSI function prototypes, if you want them. */
  42. -#if 1
  43. -/* #ifdef __STDC__ */
  44. -#define ANSIPROT 1
  45. -int mtherr ( char *, int );
  46. -#else
  47. -int mtherr();
  48. +/* Return nan on all errors. */
  49. +#ifndef NO_MTHERR
  50. +extern double NAN; /* defined in const.c */
  51. +#define mtherr(name, code) do { return NAN; } while (0)
  52. #endif
  53. -/* Variable for error reporting. See mtherr.c. */
  54. -extern int merror;
  55. +/* Rename internal functions that conflict with starndard library names. */
  56. +#define expm1 cephes_expm1
  57. +#define log1p cephes_log1p
  58. +#define erf cephes_erf
  59. +#define erfc cephes_erfc
  60. +#define gamma cephes_gamma
  61. --- cprob/const.c
  62. +++ cprob/const.c
  63. @@ -59,6 +59,7 @@
  64. Copyright 1984, 1995 by Stephen L. Moshier
  65. */
  66. +#define NO_MTHERR
  67. #include "mconf.h"
  68. #ifdef UNK
  69. --- cprob/gamma.c
  70. +++ cprob/gamma.c
  71. @@ -266,8 +266,8 @@
  72. #define SQTPI *(double *)SQT
  73. #endif
  74. -int sgngam = 0;
  75. -extern int sgngam;
  76. +/* sgngam isn't used by other functions in Cephes,
  77. + and a global variable isn't thread-safe */
  78. extern double MAXLOG, MAXNUM, PI;
  79. #ifdef ANSIPROT
  80. extern double pow ( double, double );
  81. @@ -327,7 +327,7 @@
  82. double p, q, z;
  83. int i;
  84. -sgngam = 1;
  85. +int sgngam = 1;
  86. #ifdef NANS
  87. if( isnan(x) )
  88. return(x);
  89. @@ -339,7 +339,7 @@
  90. if( x == -INFINITY )
  91. return(NAN);
  92. #else
  93. -if( !isfinite(x) )
  94. +if( x == INFINITY || x == -INFINITY )
  95. return(x);
  96. #endif
  97. #endif
  98. @@ -580,14 +580,14 @@
  99. double p, q, u, w, z;
  100. int i;
  101. -sgngam = 1;
  102. +int sgngam = 1;
  103. #ifdef NANS
  104. if( isnan(x) )
  105. return(x);
  106. #endif
  107. #ifdef INFINITIES
  108. -if( !isfinite(x) )
  109. +if( x == INFINITY || x == -INFINITY )
  110. return(INFINITY);
  111. #endif
  112. --- cprob/igami.c
  113. +++ cprob/igami.c
  114. @@ -69,6 +69,9 @@
  115. double x0, x1, x, yl, yh, y, d, lgm, dithresh;
  116. int i, dir;
  117. +if( !(y0 > 0 && y0 < 1) )
  118. + return NAN;
  119. +
  120. /* bound the solution */
  121. x0 = MAXNUM;
  122. yl = 0;
  123. --- cprob/incbi.c
  124. +++ cprob/incbi.c
  125. @@ -134,7 +134,7 @@
  126. dir = 0;
  127. di = 0.5;
  128. -for( i=0; i<100; i++ )
  129. +for( i=0; i<500; i++ )
  130. {
  131. if( i != 0 )
  132. {
  133. @@ -220,7 +220,7 @@
  134. dir -= 1;
  135. }
  136. }
  137. -mtherr( "incbi", PLOSS );
  138. +/* mtherr( "incbi", PLOSS ); */
  139. if( x0 >= 1.0 )
  140. {
  141. x = 1.0 - MACHEP;
  142. --- cprob/kolmogorov.c
  143. +++ cprob/kolmogorov.c
  144. @@ -45,8 +45,8 @@
  145. int v, nn;
  146. double evn, omevn, p, t, c, lgamnp1;
  147. - if (n <= 0 || e < 0.0 || e > 1.0)
  148. - return (-1.0);
  149. + if (n <= 0 || !(e >= 0 && e <= 1))
  150. + return NAN;
  151. nn = floor ((double) n * (1.0 - e));
  152. p = 0.0;
  153. if (n < 1013)
  154. @@ -95,6 +95,9 @@
  155. {
  156. double p, t, r, sign, x;
  157. + if( y < .12 )
  158. + return 1;
  159. +
  160. x = -2.0 * y * y;
  161. sign = 1.0;
  162. p = 0.0;