Skip to content

Commit 529f3a7

Browse files
authored
Merge pull request #1246 from boostorg/develop
Merge for 1.88
2 parents 0b574c3 + a5c0625 commit 529f3a7

24 files changed

+106
-86
lines changed

doc/background/special_tut.qbk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Now we just need to write the test driver program, at it's most basic it looks s
373373
std::cout << "<note>The long double tests have been disabled on this platform "
374374
"either because the long double overloads of the usual math functions are "
375375
"not available at all, or because they are too inaccurate for these tests "
376-
"to pass.</note>" << std::cout;
376+
"to pass.</note>" << std::endl;
377377
#endif
378378
}
379379

doc/distributions/cauchy.qbk

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,23 @@ In the following table __x0 is the location parameter of the distribution,
105105

106106
[table
107107
[[Function][Implementation Notes]]
108-
[[pdf][Using the relation: ['pdf = 1 / ([pi] * [gamma] * (1 + ((x - __x0) / [gamma])[super 2]) ]]]
108+
[[pdf][Using the relation: ['pdf = 1 / ([pi] * [gamma] * (1 + ((x - __x0) / [gamma])[super 2])) ]]]
109109
[[cdf and its complement][
110110
The cdf is normally given by:
111111

112112
[expression p = 0.5 + atan(x)/[pi]]
113113

114114
But that suffers from cancellation error as x -> -[infin].
115-
So recall that for `x < 0`:
116115

117-
[expression atan(x) = -[pi]/2 - atan(1/x)]
116+
Instead, the mathematically equivalent expression based on the function atan2
117+
is used:
118118

119-
Substituting into the above we get:
119+
[expression p = atan2(1, -x)/[pi]]
120120

121-
[expression p = -atan(1/x) / [pi] ; x < 0]
121+
By symmetry, the complement is
122122

123-
So the procedure is to calculate the cdf for -fabs(x)
124-
using the above formula. Note that to factor in the location and scale
125-
parameters you must substitute (x - __x0) / [gamma] for x in the above.
123+
[expression q = atan2(1, x)/[pi]]
126124

127-
This procedure yields the smaller of /p/ and /q/, so the result
128-
may need subtracting from 1 depending on whether we want the complement
129-
or not, and whether /x/ is less than __x0 or not.
130125
]]
131126
[[quantile][The same procedure is used irrespective of whether we're starting
132127
from the probability or its complement. First the argument /p/ is

include/boost/math/ccmath/floor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ inline constexpr T floor_pos_impl(T arg) noexcept
3333

3434
T result = 1;
3535

36-
if(result < arg)
36+
if(result <= arg)
3737
{
3838
while(result < arg)
3939
{

include/boost/math/ccmath/isinf.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ constexpr bool isinf BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x) noexcept
2323
if constexpr (std::numeric_limits<T>::is_signed)
2424
{
2525
#if defined(__clang_major__) && __clang_major__ >= 6
26-
#pragma clang diagnostic push
27-
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
26+
# pragma clang diagnostic push
27+
# pragma clang diagnostic ignored "-Wtautological-constant-compare"
28+
# if defined(__has_warning)
29+
# if __has_warning("-Wnan-infinity-disabled")
30+
# pragma clang diagnostic ignored "-Wnan-infinity-disabled"
31+
# endif
32+
# endif
2833
#endif
2934
return x == std::numeric_limits<T>::infinity() || -x == std::numeric_limits<T>::infinity();
3035
#if defined(__clang_major__) && __clang_major__ >= 6

include/boost/math/distributions/cauchy.hpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,11 @@ BOOST_MATH_GPU_ENABLED RealType cdf_imp(const cauchy_distribution<RealType, Poli
4545
//
4646
// This calculates the cdf of the Cauchy distribution and/or its complement.
4747
//
48-
// The usual formula for the Cauchy cdf is:
48+
// This implementation uses the formula
4949
//
50-
// cdf = 0.5 + atan(x)/pi
50+
// cdf = atan2(1, -x)/pi
5151
//
52-
// But that suffers from cancellation error as x -> -INF.
53-
//
54-
// Recall that for x < 0:
55-
//
56-
// atan(x) = -pi/2 - atan(1/x)
57-
//
58-
// Substituting into the above we get:
59-
//
60-
// CDF = -atan(1/x)/pi ; x < 0
61-
//
62-
// So the procedure is to calculate the cdf for -fabs(x)
63-
// using the above formula, and then subtract from 1 when required
64-
// to get the result.
52+
// where x is the standardized (i.e. shifted and scaled) domain variable.
6553
//
6654
BOOST_MATH_STD_USING // for ADL of std functions
6755
constexpr auto function = "boost::math::cdf(cauchy<%1%>&, %1%)";
@@ -99,13 +87,8 @@ BOOST_MATH_GPU_ENABLED RealType cdf_imp(const cauchy_distribution<RealType, Poli
9987
{ // Catches x == NaN
10088
return result;
10189
}
102-
RealType mx = -fabs((x - location) / scale); // scale is > 0
103-
if(mx > -tools::epsilon<RealType>() / 8)
104-
{ // special case first: x extremely close to location.
105-
return static_cast<RealType>(0.5f);
106-
}
107-
result = -atan(1 / mx) / constants::pi<RealType>();
108-
return (((x > location) != complement) ? 1 - result : result);
90+
RealType x_std = static_cast<RealType>((complement) ? 1 : -1)*(x - location) / scale;
91+
return atan2(static_cast<RealType>(1), x_std) / constants::pi<RealType>();
10992
} // cdf
11093

11194
template <class RealType, class Policy>

include/boost/math/distributions/fwd.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#ifndef BOOST_MATH_DISTRIBUTIONS_FWD_HPP
1212
#define BOOST_MATH_DISTRIBUTIONS_FWD_HPP
1313

14-
// 33 distributions at Boost 1.9.1 after adding hyperexpon and arcsine
15-
1614
namespace boost{ namespace math{
1715

1816
template <class RealType, class Policy>

include/boost/math/distributions/skew_normal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Azzalini, A. (1985). "A class of distributions which includes the normal ones".
1414
// Scand. J. Statist. 12: 171-178.
1515

16-
#include <boost/math/distributions/fwd.hpp> // TODO add skew_normal distribution to fwd.hpp!
16+
#include <boost/math/distributions/fwd.hpp>
1717
#include <boost/math/special_functions/owens_t.hpp> // Owen's T function
1818
#include <boost/math/distributions/complement.hpp>
1919
#include <boost/math/distributions/normal.hpp>

include/boost/math/special_functions/bessel.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ BOOST_MATH_GPU_ENABLED inline T sph_bessel_j_small_z_series(unsigned v, T x, con
9696
}
9797

9898
template <class T, class Policy>
99-
BOOST_MATH_GPU_ENABLED T cyl_bessel_j_imp_final(T v, T x, const bessel_no_int_tag& t, const Policy& pol)
99+
BOOST_MATH_GPU_ENABLED T cyl_bessel_j_imp_final(T v, T x, const bessel_no_int_tag&, const Policy& pol)
100100
{
101101
BOOST_MATH_STD_USING
102102

@@ -264,7 +264,7 @@ BOOST_MATH_GPU_ENABLED T cyl_bessel_i_imp(T v, T x, const Policy& pol)
264264
}
265265

266266
template <class T, class Policy>
267-
BOOST_MATH_GPU_ENABLED inline T cyl_bessel_k_imp(T v, T x, const bessel_no_int_tag& /* t */, const Policy& pol)
267+
BOOST_MATH_GPU_ENABLED inline T cyl_bessel_k_imp(T v, T x, const bessel_no_int_tag&, const Policy& pol)
268268
{
269269
constexpr auto function = "boost::math::cyl_bessel_k<%1%>(%1%,%1%)";
270270
BOOST_MATH_STD_USING

include/boost/math/special_functions/detail/bessel_k0.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ BOOST_MATH_GPU_ENABLED T bessel_k0_imp(const T& x, const boost::math::integral_c
470470
BOOST_MATH_BIG_CONSTANT(T, 113, 8.370574966987293592457152146806662562e+03),
471471
BOOST_MATH_BIG_CONSTANT(T, 113, 4.871254714311063594080644835895740323e+01)
472472
};
473-
if(x < tools::log_max_value<T>())
473+
if(-x > tools::log_min_value<T>())
474474
return ((tools::evaluate_rational(P, Q, T(1 / x)) + Y) * exp(-x) / sqrt(x));
475475
else
476476
{

include/boost/math/special_functions/gamma.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ BOOST_MATH_GPU_ENABLED T sinpx(T z)
111111
// tgamma(z), with Lanczos support:
112112
//
113113
template <class T, class Policy, class Lanczos>
114-
BOOST_MATH_GPU_ENABLED T gamma_imp_final(T z, const Policy& pol, const Lanczos&)
114+
BOOST_MATH_GPU_ENABLED T gamma_imp_final(T z, const Policy& pol, const Lanczos& l)
115115
{
116116
BOOST_MATH_STD_USING
117+
118+
(void)l; // Suppresses unused variable warning when BOOST_MATH_INSTRUMENT is not defined
117119

118-
T result = 1;
120+
T result = 1;
119121

120122
#ifdef BOOST_MATH_INSTRUMENT
121123
static bool b = false;

0 commit comments

Comments
 (0)