summaryrefslogtreecommitdiff
path: root/boost/math/special_functions/detail/bessel_y0.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/math/special_functions/detail/bessel_y0.hpp')
-rw-r--r--boost/math/special_functions/detail/bessel_y0.hpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/boost/math/special_functions/detail/bessel_y0.hpp b/boost/math/special_functions/detail/bessel_y0.hpp
index 289bda5f18..533ab7c8a0 100644
--- a/boost/math/special_functions/detail/bessel_y0.hpp
+++ b/boost/math/special_functions/detail/bessel_y0.hpp
@@ -197,11 +197,22 @@ T bessel_y0(T x, const Policy& pol)
{
T y = 8 / x;
T y2 = y * y;
- T z = x - 0.25f * pi<T>();
rc = evaluate_rational(PC, QC, y2);
rs = evaluate_rational(PS, QS, y2);
- factor = sqrt(2 / (x * pi<T>()));
- value = factor * (rc * sin(z) + y * rs * cos(z));
+ factor = constants::one_div_root_pi<T>() / sqrt(x);
+ //
+ // The following code is really just:
+ //
+ // T z = x - 0.25f * pi<T>();
+ // value = factor * (rc * sin(z) + y * rs * cos(z));
+ //
+ // But using the sin/cos addition formulae and constant values for
+ // sin/cos of PI/4 which then cancel part of the "factor" term as they're all
+ // 1 / sqrt(2):
+ //
+ T sx = sin(x);
+ T cx = cos(x);
+ value = factor * (rc * (sx - cx) + y * rs * (cx + sx));
}
return value;