18_use_stdlib_sqrt.patch 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. diff --git a/modules/fdlibm/src/e_acos.cpp b/modules/fdlibm/src/e_acos.cpp
  2. --- a/modules/fdlibm/src/e_acos.cpp
  3. +++ b/modules/fdlibm/src/e_acos.cpp
  4. @@ -33,16 +33,17 @@
  5. *
  6. * Special cases:
  7. * if x is NaN, return x itself;
  8. * if |x|>1, return NaN with invalid signal.
  9. *
  10. * Function needed: sqrt
  11. */
  12. +#include <cmath>
  13. #include <float.h>
  14. #include "math_private.h"
  15. static const double
  16. one= 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
  17. pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
  18. pio2_hi = 1.57079632679489655800e+00; /* 0x3FF921FB, 0x54442D18 */
  19. @@ -82,23 +83,23 @@ double
  20. p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
  21. q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
  22. r = p/q;
  23. return pio2_hi - (x - (pio2_lo-x*r));
  24. } else if (hx<0) { /* x < -0.5 */
  25. z = (one+x)*0.5;
  26. p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
  27. q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
  28. - s = sqrt(z);
  29. + s = std::sqrt(z);
  30. r = p/q;
  31. w = r*s-pio2_lo;
  32. return pi - 2.0*(s+w);
  33. } else { /* x > 0.5 */
  34. z = (one-x)*0.5;
  35. - s = sqrt(z);
  36. + s = std::sqrt(z);
  37. df = s;
  38. SET_LOW_WORD(df,0);
  39. c = (z-df*df)/(s+df);
  40. p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
  41. q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
  42. r = p/q;
  43. w = r*s+c;
  44. return 2.0*(df+w);
  45. diff --git a/modules/fdlibm/src/e_acosh.cpp b/modules/fdlibm/src/e_acosh.cpp
  46. --- a/modules/fdlibm/src/e_acosh.cpp
  47. +++ b/modules/fdlibm/src/e_acosh.cpp
  48. @@ -24,16 +24,17 @@
  49. * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
  50. * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
  51. *
  52. * Special cases:
  53. * acosh(x) is NaN with signal if x<1.
  54. * acosh(NaN) is NaN without signal.
  55. */
  56. +#include <cmath>
  57. #include <float.h>
  58. #include "math_private.h"
  59. static const double
  60. one = 1.0,
  61. ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
  62. @@ -50,14 +51,14 @@ double
  63. if(hx >=0x7ff00000) { /* x is inf of NaN */
  64. return x+x;
  65. } else
  66. return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
  67. } else if(((hx-0x3ff00000)|lx)==0) {
  68. return 0.0; /* acosh(1) = 0 */
  69. } else if (hx > 0x40000000) { /* 2**28 > x > 2 */
  70. t=x*x;
  71. - return __ieee754_log(2.0*x-one/(x+sqrt(t-one)));
  72. + return __ieee754_log(2.0*x-one/(x+std::sqrt(t-one)));
  73. } else { /* 1<x<2 */
  74. t = x-one;
  75. - return log1p(t+sqrt(2.0*t+t*t));
  76. + return log1p(t+std::sqrt(2.0*t+t*t));
  77. }
  78. }
  79. diff --git a/modules/fdlibm/src/e_asin.cpp b/modules/fdlibm/src/e_asin.cpp
  80. --- a/modules/fdlibm/src/e_asin.cpp
  81. +++ b/modules/fdlibm/src/e_asin.cpp
  82. @@ -39,16 +39,17 @@
  83. * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
  84. *
  85. * Special cases:
  86. * if x is NaN, return x itself;
  87. * if |x|>1, return NaN with invalid signal.
  88. *
  89. */
  90. +#include <cmath>
  91. #include <float.h>
  92. #include "math_private.h"
  93. static const double
  94. one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
  95. huge = 1.000e+300,
  96. pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
  97. @@ -90,17 +91,17 @@ double
  98. w = p/q;
  99. return x+x*w;
  100. }
  101. /* 1> |x|>= 0.5 */
  102. w = one-fabs(x);
  103. t = w*0.5;
  104. p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
  105. q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
  106. - s = sqrt(t);
  107. + s = std::sqrt(t);
  108. if(ix>=0x3FEF3333) { /* if |x| > 0.975 */
  109. w = p/q;
  110. t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
  111. } else {
  112. w = s;
  113. SET_LOW_WORD(w,0);
  114. c = (t-w*w)/(s+w);
  115. r = p/q;
  116. diff --git a/modules/fdlibm/src/e_hypot.cpp b/modules/fdlibm/src/e_hypot.cpp
  117. --- a/modules/fdlibm/src/e_hypot.cpp
  118. +++ b/modules/fdlibm/src/e_hypot.cpp
  119. @@ -41,16 +41,17 @@
  120. * hypot(x,y) is INF if x or y is +INF or -INF; else
  121. * hypot(x,y) is NAN if x or y is NAN.
  122. *
  123. * Accuracy:
  124. * hypot(x,y) returns sqrt(x^2+y^2) with error less
  125. * than 1 ulps (units in the last place)
  126. */
  127. +#include <cmath>
  128. #include <float.h>
  129. #include "math_private.h"
  130. double
  131. __ieee754_hypot(double x, double y)
  132. {
  133. double a,b,t1,t2,y1,y2,w;
  134. @@ -100,26 +101,26 @@ double
  135. }
  136. }
  137. /* medium size a and b */
  138. w = a-b;
  139. if (w>b) {
  140. t1 = 0;
  141. SET_HIGH_WORD(t1,ha);
  142. t2 = a-t1;
  143. - w = sqrt(t1*t1-(b*(-b)-t2*(a+t1)));
  144. + w = std::sqrt(t1*t1-(b*(-b)-t2*(a+t1)));
  145. } else {
  146. a = a+a;
  147. y1 = 0;
  148. SET_HIGH_WORD(y1,hb);
  149. y2 = b - y1;
  150. t1 = 0;
  151. SET_HIGH_WORD(t1,ha+0x00100000);
  152. t2 = a - t1;
  153. - w = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
  154. + w = std::sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
  155. }
  156. if(k!=0) {
  157. u_int32_t high;
  158. t1 = 1.0;
  159. GET_HIGH_WORD(high,t1);
  160. SET_HIGH_WORD(t1,high+(k<<20));
  161. return t1*w;
  162. } else return w;
  163. diff --git a/modules/fdlibm/src/e_pow.cpp b/modules/fdlibm/src/e_pow.cpp
  164. --- a/modules/fdlibm/src/e_pow.cpp
  165. +++ b/modules/fdlibm/src/e_pow.cpp
  166. @@ -52,16 +52,18 @@
  167. *
  168. * Constants :
  169. * The hexadecimal values are the intended ones for the following
  170. * constants. The decimal values may be used, provided that the
  171. * compiler will convert from decimal to binary accurately enough
  172. * to produce the hexadecimal values shown.
  173. */
  174. +#include <cmath>
  175. +
  176. #include <float.h>
  177. #include "math_private.h"
  178. static const double
  179. bp[] = {1.0, 1.5,},
  180. dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
  181. dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
  182. zero = 0.0,
  183. @@ -151,17 +153,17 @@ double
  184. return (hy<0)?-y: zero;
  185. }
  186. if(iy==0x3ff00000) { /* y is +-1 */
  187. if(hy<0) return one/x; else return x;
  188. }
  189. if(hy==0x40000000) return x*x; /* y is 2 */
  190. if(hy==0x3fe00000) { /* y is 0.5 */
  191. if(hx>=0) /* x >= +0 */
  192. - return sqrt(x);
  193. + return std::sqrt(x);
  194. }
  195. }
  196. ax = fabs(x);
  197. /* special value of x */
  198. if(lx==0) {
  199. if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
  200. z = ax; /*x is +-0,+-inf,+-1*/
  201. diff --git a/modules/fdlibm/src/s_asinh.cpp b/modules/fdlibm/src/s_asinh.cpp
  202. --- a/modules/fdlibm/src/s_asinh.cpp
  203. +++ b/modules/fdlibm/src/s_asinh.cpp
  204. @@ -19,16 +19,17 @@
  205. * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
  206. * we have
  207. * asinh(x) := x if 1+x*x=1,
  208. * := sign(x)*(log(x)+ln2)) for large |x|, else
  209. * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
  210. * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
  211. */
  212. +#include <cmath>
  213. #include <float.h>
  214. #include "math_private.h"
  215. static const double
  216. one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
  217. ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
  218. huge= 1.00000000000000000000e+300;
  219. @@ -43,15 +44,15 @@ asinh(double x)
  220. if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */
  221. if(ix< 0x3e300000) { /* |x|<2**-28 */
  222. if(huge+x>one) return x; /* return x inexact except 0 */
  223. }
  224. if(ix>0x41b00000) { /* |x| > 2**28 */
  225. w = __ieee754_log(fabs(x))+ln2;
  226. } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
  227. t = fabs(x);
  228. - w = __ieee754_log(2.0*t+one/(__ieee754_sqrt(x*x+one)+t));
  229. + w = __ieee754_log(2.0*t+one/(std::sqrt(x*x+one)+t));
  230. } else { /* 2.0 > |x| > 2**-28 */
  231. t = x*x;
  232. - w =log1p(fabs(x)+t/(one+__ieee754_sqrt(one+t)));
  233. + w =log1p(fabs(x)+t/(one+std::sqrt(one+t)));
  234. }
  235. if(hx>0) return w; else return -w;
  236. }