2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Matt Borland
2025-09-10 10:28:45 +02:00
22 changed files with 360 additions and 288 deletions

View File

@@ -24,7 +24,7 @@ namespace boost{ namespace math{
catmull_rom(std::initializer_list<Point> l, bool closed = false, typename Point::value_type alpha = (typename Point::value_type) 1/ (typename Point::value_type) 2);
Real operator()(Real s) const;
Point operator()(Real s) const;
Real max_parameter() const;

View File

@@ -310,11 +310,17 @@ calculated using NTL::RR at 1000-bit precision.
template <class T1, class T2, class ``__Policy``>
``__sf_result`` hypot(T1 x, T2 y, const ``__Policy``&);
template <class T1, class T2, class T3>
``__sf_result`` hypot(T1 x, T2 y, T3 z);
template <class T1, class T2, class T3, class ``__Policy``>
``__sf_result`` hypot(T1 x, T2 y, T3 z, const ``__Policy``&);
__effects computes [equation hypot]
in such a way as to avoid undue underflow and overflow.
The return type of this function is computed using the __arg_promotion_rules
when T1 and T2 are of different types.
when T1 and T2 (and or T3) are of different types.
[optional_policy]
@@ -328,6 +334,11 @@ The function is even and symmetric in /x/ and /y/, so first take assume
Then if ['x * [epsilon] >= y] we can simply return /x/.
In the 3-arg case the approach is to scale by the largest argument, and then calculate
const auto a = max(max(x, y), z);
return a == 0 ? 0 : a * sqrt(x/a * x/a + y/a * y/a + z/a * z/a);
Otherwise the result is given by:
[equation hypot2]

View File

@@ -112,11 +112,15 @@ namespace boost
last_term = term;
}
last_term = 0;
T betaf_lim = betaf * tools::epsilon<T>() * 4;
for(auto i = k + 1; ; ++i)
{
poisf *= l2 / i;
xtermf *= (x * (a + b + i - 2)) / (a + i - 1);
betaf -= xtermf;
if (betaf < betaf_lim)
break; // nothing but garbage bits in betaf!!
T term = poisf * betaf;
sum += term;

View File

@@ -100,11 +100,15 @@ namespace boost
++count;
}
last_term = 0;
T betaf_lim = betaf * tools::epsilon<T>() * 4;
for(auto i = k + 1; ; ++i)
{
poisf *= d2 / (i + 0.5f);
xtermf *= (x * (v / 2 + i - 1)) / (i);
betaf -= xtermf;
if (betaf < betaf_lim)
break; // Nothing but garbage left in betaf now!!
T term = poisf * betaf;
sum += term;
if((fabs(last_term) >= fabs(term)) && (fabs(term/sum) < errtol))

View File

@@ -389,7 +389,7 @@ jso(const Func cost_function, jso_parameters<ArgumentContainer> &jso_params,
throw std::logic_error(oss.str());
}
for (size_t i = 0; i < weights.size(); ++i) {
weights[i] = delta_f[i] / delta_sum;
weights[i] = static_cast<DimensionlessReal>(delta_f[i] / delta_sum);
}
M_CR[k] = detail::weighted_lehmer_mean(S_CR, weights);

View File

@@ -942,7 +942,7 @@ template <typename P>
class is_policy_imp
{
public:
static constexpr bool value = (sizeof(::boost::math::policies::detail::test_is_policy(static_cast<P*>(nullptr))) == sizeof(char));
static constexpr bool value = (sizeof(detail::test_is_policy(static_cast<boost::math::remove_reference_t<boost::math::remove_cv_t<P>>*>(nullptr))) == sizeof(char));
};
}
@@ -955,6 +955,9 @@ public:
using type = boost::math::integral_constant<bool, value>;
};
template <typename T>
BOOST_MATH_INLINE_CONSTEXPR bool is_policy_v = is_policy<T>::value;
//
// Helper traits class for distribution error handling:
//

View File

@@ -270,7 +270,7 @@ template<> struct fp_traits_non_native<double, double_precision>
// long double (64 bits) -------------------------------------------------------
#if defined(BOOST_NO_INT64_T) || defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)\
|| defined(BOOST_BORLANDC) || defined(__CODEGEAR__)
|| defined(BOOST_BORLANDC) || defined(__CODEGEAR__) || (defined(__APPLE__) && defined(__aarch64__)) || defined(_MSC_VER)
template<> struct fp_traits_non_native<long double, double_precision>
{
@@ -297,31 +297,9 @@ private:
static constexpr int offset_ = BOOST_MATH_ENDIAN_BIG_BYTE ? 0 : 4;
};
//..............................................................................
#else
template<> struct fp_traits_non_native<long double, double_precision>
{
typedef ieee_copy_all_bits_tag method;
static const uint64_t sign = static_cast<uint64_t>(0x80000000u) << 32;
static const uint64_t exponent = static_cast<uint64_t>(0x7ff00000) << 32;
static const uint64_t flag = 0;
static const uint64_t significand
= (static_cast<uint64_t>(0x000fffff) << 32) + static_cast<uint64_t>(0xffffffffu);
typedef uint64_t bits;
static void get_bits(long double x, uint64_t& a) { std::memcpy(&a, &x, 8); }
static void set_bits(long double& x, uint64_t a) { std::memcpy(&x, &a, 8); }
};
#endif
// long double (>64 bits), x86 and x64 -----------------------------------------
#if defined(__i386) || defined(__i386__) || defined(_M_IX86) \
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86) \
|| defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) \
|| defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)

View File

@@ -30,103 +30,131 @@ static constexpr std::size_t noof_wm1zs = 64;
static constexpr lookup_t halves[noof_halves] =
{ // Common to Lambert W0 and W-1 (and exactly representable).
0.5L, 0.25L, 0.125L, 0.0625L, 0.03125L, 0.015625L, 0.0078125L, 0.00390625L, 0.001953125L, 0.0009765625L, 0.00048828125L, 0.000244140625L
static_cast<lookup_t>(0.5L), static_cast<lookup_t>(0.25L), static_cast<lookup_t>(0.125L), static_cast<lookup_t>(0.0625L),
static_cast<lookup_t>(0.03125L), static_cast<lookup_t>(0.015625L), static_cast<lookup_t>(0.0078125L), static_cast<lookup_t>(0.00390625L),
static_cast<lookup_t>(0.001953125L), static_cast<lookup_t>(0.0009765625L), static_cast<lookup_t>(0.00048828125L), static_cast<lookup_t>(0.000244140625L)
}; // halves, 0.5, 0.25, ... 0.000244140625, common to W0 and W-1.
static constexpr lookup_t sqrtw0s[noof_sqrts] =
{ // For Lambert W0 only.
0.6065306597126334242631173765403218567L, 0.77880078307140486866846070009071995L, 0.882496902584595403104717592968701829L, 0.9394130628134757862473572557999761753L, 0.9692332344763440819139583751755278177L, 0.9844964370054084060204319075254540376L, 0.9922179382602435121227899136829802692L, 0.996101369470117490071323985506950379L, 0.9980487811074754727142805899944244847L, 0.9990239141819756622368328253791383317L, 0.9995118379398893653889967919448497792L, 0.9997558891748972165136242351259789505L
static_cast<lookup_t>(0.6065306597126334242631173765403218567L), static_cast<lookup_t>(0.7788007830714048686684607000907199500L),
static_cast<lookup_t>(0.8824969025845954031047175929687018290L), static_cast<lookup_t>(0.9394130628134757862473572557999761753L),
static_cast<lookup_t>(0.9692332344763440819139583751755278177L), static_cast<lookup_t>(0.9844964370054084060204319075254540376L),
static_cast<lookup_t>(0.9922179382602435121227899136829802692L), static_cast<lookup_t>(0.9961013694701174900713239855069503790L),
static_cast<lookup_t>(0.9980487811074754727142805899944244847L), static_cast<lookup_t>(0.9990239141819756622368328253791383317L),
static_cast<lookup_t>(0.9995118379398893653889967919448497792L), static_cast<lookup_t>(0.9997558891748972165136242351259789505L)
}; // sqrtw0s
static constexpr lookup_t sqrtwm1s[noof_sqrts] =
{ // For Lambert W-1 only.
1.648721270700128146848650787814163572L, 1.284025416687741484073420568062436458L, 1.133148453066826316829007227811793873L, 1.064494458917859429563390594642889673L, 1.031743407499102670938747815281507144L, 1.015747708586685747458535072082351749L, 1.007843097206447977693453559760123579L, 1.003913889338347573443609603903460282L, 1.001955033591002812046518898047477216L, 1.000977039492416535242845292611606506L, 1.000488400478694473126173623807163354L, 1.000244170429747854937005233924135774L
static_cast<lookup_t>(1.648721270700128146848650787814163572L), static_cast<lookup_t>(1.284025416687741484073420568062436458L),
static_cast<lookup_t>(1.133148453066826316829007227811793873L), static_cast<lookup_t>(1.064494458917859429563390594642889673L),
static_cast<lookup_t>(1.031743407499102670938747815281507144L), static_cast<lookup_t>(1.015747708586685747458535072082351749L),
static_cast<lookup_t>(1.007843097206447977693453559760123579L), static_cast<lookup_t>(1.003913889338347573443609603903460282L),
static_cast<lookup_t>(1.001955033591002812046518898047477216L), static_cast<lookup_t>(1.000977039492416535242845292611606506L),
static_cast<lookup_t>(1.000488400478694473126173623807163354L), static_cast<lookup_t>(1.000244170429747854937005233924135774L)
}; // sqrtwm1s
static constexpr lookup_t w0es[noof_w0zs] =
{ // Fukushima e powers array e[0] = 2.718, 1., e[2] = e^-1 = 0.135, e[3] = e^-2 = 0.133 ... e[64] = 4.3596100000630809736231248158884615452e-28.
2.7182818284590452353602874713526624978e+00L,
1.0000000000000000000000000000000000000e+00L, 3.6787944117144232159552377016146086745e-01L, 1.3533528323661269189399949497248440341e-01L, 4.9787068367863942979342415650061776632e-02L,
1.8315638888734180293718021273241242212e-02L, 6.7379469990854670966360484231484242488e-03L, 2.4787521766663584230451674308166678915e-03L, 9.1188196555451620800313608440928262647e-04L,
3.3546262790251183882138912578086101931e-04L, 1.2340980408667954949763669073003382607e-04L, 4.5399929762484851535591515560550610238e-05L, 1.6701700790245659312635517360580879078e-05L,
6.1442123533282097586823081788055323112e-06L, 2.2603294069810543257852772905386894694e-06L, 8.3152871910356788406398514256526229461e-07L, 3.0590232050182578837147949770228963937e-07L,
1.1253517471925911451377517906012719164e-07L, 4.1399377187851666596510277189552806229e-08L, 1.5229979744712628436136629233517431862e-08L, 5.6027964375372675400129828162064630798e-09L,
2.0611536224385578279659403801558209764e-09L, 7.5825604279119067279417432412681264430e-10L, 2.7894680928689248077189130306442932077e-10L, 1.0261879631701890303927527840612497760e-10L,
3.7751345442790977516449695475234067792e-11L, 1.3887943864964020594661763746086856910e-11L, 5.1090890280633247198744001934792157666e-12L, 1.8795288165390832947582704184221926212e-12L,
6.9144001069402030094125846587414092712e-13L, 2.5436656473769229103033856148576816666e-13L, 9.3576229688401746049158322233787067450e-14L, 3.4424771084699764583923893328515572846e-14L,
1.2664165549094175723120904155965096382e-14L, 4.6588861451033973641842455436101684114e-15L, 1.7139084315420129663027203425760492412e-15L, 6.3051167601469893856390211922465427614e-16L,
2.3195228302435693883122636097380800411e-16L, 8.5330476257440657942780498229412441658e-17L, 3.1391327920480296287089646522319196491e-17L, 1.1548224173015785986262442063323868655e-17L,
4.2483542552915889953292347828586580179e-18L, 1.5628821893349887680908829951058341550e-18L, 5.7495222642935598066643808805734234249e-19L, 2.1151310375910804866314010070226514702e-19L,
7.7811322411337965157133167292798981918e-20L, 2.8625185805493936444701216291839372068e-20L, 1.0530617357553812378763324449428108806e-20L, 3.8739976286871871129314774972691278293e-21L,
1.4251640827409351062853210280340602263e-21L, 5.2428856633634639371718053028323436716e-22L, 1.9287498479639177830173428165270125748e-22L, 7.0954741622847041389832693878080734877e-23L,
2.6102790696677048047026953153318648093e-23L, 9.6026800545086760302307696700074909076e-24L, 3.5326285722008070297353928101772088374e-24L, 1.2995814250075030736007134060714855303e-24L,
4.7808928838854690812771770423179628939e-25L, 1.7587922024243116489558751288034363178e-25L, 6.4702349256454603261540395529264893765e-26L, 2.3802664086944006058943245888024963309e-26L,
8.7565107626965203384887328007391660366e-27L, 3.2213402859925160890012477758489437534e-27L, 1.1850648642339810062850307390972809891e-27L, 4.3596100000630809736231248158884596428e-28L,
static_cast<lookup_t>(2.7182818284590452353602874713526624978e+00L),
static_cast<lookup_t>(1.0000000000000000000000000000000000000e+00L), static_cast<lookup_t>(3.6787944117144232159552377016146086745e-01L),
static_cast<lookup_t>(1.3533528323661269189399949497248440341e-01L), static_cast<lookup_t>(4.9787068367863942979342415650061776632e-02L),
static_cast<lookup_t>(1.8315638888734180293718021273241242212e-02L), static_cast<lookup_t>(6.7379469990854670966360484231484242488e-03L),
static_cast<lookup_t>(2.4787521766663584230451674308166678915e-03L), static_cast<lookup_t>(9.1188196555451620800313608440928262647e-04L),
static_cast<lookup_t>(3.3546262790251183882138912578086101931e-04L), static_cast<lookup_t>(1.2340980408667954949763669073003382607e-04L),
static_cast<lookup_t>(4.5399929762484851535591515560550610238e-05L), static_cast<lookup_t>(1.6701700790245659312635517360580879078e-05L),
static_cast<lookup_t>(6.1442123533282097586823081788055323112e-06L), static_cast<lookup_t>(2.2603294069810543257852772905386894694e-06L),
static_cast<lookup_t>(8.3152871910356788406398514256526229461e-07L), static_cast<lookup_t>(3.0590232050182578837147949770228963937e-07L),
static_cast<lookup_t>(1.1253517471925911451377517906012719164e-07L), static_cast<lookup_t>(4.1399377187851666596510277189552806229e-08L),
static_cast<lookup_t>(1.5229979744712628436136629233517431862e-08L), static_cast<lookup_t>(5.6027964375372675400129828162064630798e-09L),
static_cast<lookup_t>(2.0611536224385578279659403801558209764e-09L), static_cast<lookup_t>(7.5825604279119067279417432412681264430e-10L),
static_cast<lookup_t>(2.7894680928689248077189130306442932077e-10L), static_cast<lookup_t>(1.0261879631701890303927527840612497760e-10L),
static_cast<lookup_t>(3.7751345442790977516449695475234067792e-11L), static_cast<lookup_t>(1.3887943864964020594661763746086856910e-11L),
static_cast<lookup_t>(5.1090890280633247198744001934792157666e-12L), static_cast<lookup_t>(1.8795288165390832947582704184221926212e-12L),
static_cast<lookup_t>(6.9144001069402030094125846587414092712e-13L), static_cast<lookup_t>(2.5436656473769229103033856148576816666e-13L),
static_cast<lookup_t>(9.3576229688401746049158322233787067450e-14L), static_cast<lookup_t>(3.4424771084699764583923893328515572846e-14L),
static_cast<lookup_t>(1.2664165549094175723120904155965096382e-14L), static_cast<lookup_t>(4.6588861451033973641842455436101684114e-15L),
static_cast<lookup_t>(1.7139084315420129663027203425760492412e-15L), static_cast<lookup_t>(6.3051167601469893856390211922465427614e-16L),
static_cast<lookup_t>(2.3195228302435693883122636097380800411e-16L), static_cast<lookup_t>(8.5330476257440657942780498229412441658e-17L),
static_cast<lookup_t>(3.1391327920480296287089646522319196491e-17L), static_cast<lookup_t>(1.1548224173015785986262442063323868655e-17L),
static_cast<lookup_t>(4.2483542552915889953292347828586580179e-18L), static_cast<lookup_t>(1.5628821893349887680908829951058341550e-18L),
static_cast<lookup_t>(5.7495222642935598066643808805734234249e-19L), static_cast<lookup_t>(2.1151310375910804866314010070226514702e-19L),
static_cast<lookup_t>(7.7811322411337965157133167292798981918e-20L), static_cast<lookup_t>(2.8625185805493936444701216291839372068e-20L),
static_cast<lookup_t>(1.0530617357553812378763324449428108806e-20L), static_cast<lookup_t>(3.8739976286871871129314774972691278293e-21L),
static_cast<lookup_t>(1.4251640827409351062853210280340602263e-21L), static_cast<lookup_t>(5.2428856633634639371718053028323436716e-22L),
static_cast<lookup_t>(1.9287498479639177830173428165270125748e-22L), static_cast<lookup_t>(7.0954741622847041389832693878080734877e-23L),
static_cast<lookup_t>(2.6102790696677048047026953153318648093e-23L), static_cast<lookup_t>(9.6026800545086760302307696700074909076e-24L),
static_cast<lookup_t>(3.5326285722008070297353928101772088374e-24L), static_cast<lookup_t>(1.2995814250075030736007134060714855303e-24L),
static_cast<lookup_t>(4.7808928838854690812771770423179628939e-25L), static_cast<lookup_t>(1.7587922024243116489558751288034363178e-25L),
static_cast<lookup_t>(6.4702349256454603261540395529264893765e-26L), static_cast<lookup_t>(2.3802664086944006058943245888024963309e-26L),
static_cast<lookup_t>(8.7565107626965203384887328007391660366e-27L), static_cast<lookup_t>(3.2213402859925160890012477758489437534e-27L),
static_cast<lookup_t>(1.1850648642339810062850307390972809891e-27L), static_cast<lookup_t>(4.3596100000630809736231248158884596428e-28L),
}; // w0es
static constexpr lookup_t w0zs[noof_w0zs] =
{ // z values for W[0], W[1], W[2] ... W[64] (Fukushima array Fk).
0.0000000000000000000000000000000000000e+00L,
2.7182818284590452353602874713526624978e+00L, 1.4778112197861300454460854921150015626e+01L, 6.0256610769563003222785588963745153691e+01L, 2.1839260013257695631244104481144351361e+02L,
7.4206579551288301710557790020276139812e+02L, 2.4205727609564107356503230832603296776e+03L, 7.6764321089992101948460416680168500271e+03L, 2.3847663896333826197948736795623109390e+04L,
7.2927755348178456069389970204894839685e+04L, 2.2026465794806716516957900645284244366e+05L, 6.5861555886717600300859134371483559776e+05L, 1.9530574970280470496960624587818413980e+06L,
5.7513740961159665432393360873381476632e+06L, 1.6836459978306874888489314790750032292e+07L, 4.9035260587081659589527825691375819733e+07L, 1.4217776832812596218820837985250320561e+08L,
4.1063419681078006965118239806655900596e+08L, 1.1818794444719492004981570586630806042e+09L, 3.3911637183005579560532906419857313738e+09L, 9.7033039081958055593821366108308111737e+09L,
2.7695130424147508641409976558651358487e+10L, 7.8868082614895014356985518811525255163e+10L, 2.2413047926372475980079655175092843139e+11L, 6.3573893111624333505933989166748517618e+11L,
1.8001224834346468131040337866531539479e+12L, 5.0889698451498078710141863447784789126e+12L, 1.4365302496248562650461177217211790925e+13L, 4.0495197800161304862957327843914007993e+13L,
1.1400869461717722015726999684446230289e+14L, 3.2059423744573386440971405952224204950e+14L, 9.0051433962267018216365614546207459567e+14L, 2.5268147258457822451512967243234631750e+15L,
7.0832381329352301326018261305316090522e+15L, 1.9837699245933465967698692976753294646e+16L, 5.5510470830970075484537561902113104381e+16L, 1.5520433569614702817608320254284931407e+17L,
4.3360826779369661842459877227403719730e+17L, 1.2105254067703227363724895246493485480e+18L, 3.3771426165357561311906703760513324357e+18L, 9.4154106734807994163159964299613921804e+18L,
2.6233583234732252918129199544138403574e+19L, 7.3049547543861043990576614751671879498e+19L, 2.0329709713386190214340167519800405595e+20L, 5.6547040503180956413560918381429636734e+20L,
1.5720421975868292906615658755032744790e+21L, 4.3682149334771264822761478593874428627e+21L, 1.2132170565093316762294432610117848880e+22L, 3.3680332378068632345542636794533635462e+22L,
9.3459982052259884835729892206738573922e+22L, 2.5923527642935362320437266614667426924e+23L, 7.1876803203773878618909930893087860822e+23L, 1.9921241603726199616378561653688236827e+24L,
5.5192924995054165325072406547517121131e+24L, 1.5286067837683347062387143159276002521e+25L, 4.2321318958281094260005100745711666956e+25L, 1.1713293177672778461879598480402173158e+26L,
3.2408603996214813669049988277609543829e+26L, 8.9641258264226027960478448084812796397e+26L, 2.4787141382364034104243901241243054434e+27L, 6.8520443388941057019777430988685937812e+27L,
1.8936217407781711443114787060753312270e+28L, 5.2317811346197017832254642778313331353e+28L, 1.4450833904658542238325922893692265683e+29L, 3.9904954117194348050619127737142206367e+29L
static_cast<lookup_t>(0.0000000000000000000000000000000000000e+00L),
static_cast<lookup_t>(2.7182818284590452353602874713526624978e+00L), static_cast<lookup_t>(1.4778112197861300454460854921150015626e+01L), static_cast<lookup_t>(6.0256610769563003222785588963745153691e+01L), static_cast<lookup_t>(2.1839260013257695631244104481144351361e+02L),
static_cast<lookup_t>(7.4206579551288301710557790020276139812e+02L), static_cast<lookup_t>(2.4205727609564107356503230832603296776e+03L), static_cast<lookup_t>(7.6764321089992101948460416680168500271e+03L), static_cast<lookup_t>(2.3847663896333826197948736795623109390e+04L),
static_cast<lookup_t>(7.2927755348178456069389970204894839685e+04L), static_cast<lookup_t>(2.2026465794806716516957900645284244366e+05L), static_cast<lookup_t>(6.5861555886717600300859134371483559776e+05L), static_cast<lookup_t>(1.9530574970280470496960624587818413980e+06L),
static_cast<lookup_t>(5.7513740961159665432393360873381476632e+06L), static_cast<lookup_t>(1.6836459978306874888489314790750032292e+07L), static_cast<lookup_t>(4.9035260587081659589527825691375819733e+07L), static_cast<lookup_t>(1.4217776832812596218820837985250320561e+08L),
static_cast<lookup_t>(4.1063419681078006965118239806655900596e+08L), static_cast<lookup_t>(1.1818794444719492004981570586630806042e+09L), static_cast<lookup_t>(3.3911637183005579560532906419857313738e+09L), static_cast<lookup_t>(9.7033039081958055593821366108308111737e+09L),
static_cast<lookup_t>(2.7695130424147508641409976558651358487e+10L), static_cast<lookup_t>(7.8868082614895014356985518811525255163e+10L), static_cast<lookup_t>(2.2413047926372475980079655175092843139e+11L), static_cast<lookup_t>(6.3573893111624333505933989166748517618e+11L),
static_cast<lookup_t>(1.8001224834346468131040337866531539479e+12L), static_cast<lookup_t>(5.0889698451498078710141863447784789126e+12L), static_cast<lookup_t>(1.4365302496248562650461177217211790925e+13L), static_cast<lookup_t>(4.0495197800161304862957327843914007993e+13L),
static_cast<lookup_t>(1.1400869461717722015726999684446230289e+14L), static_cast<lookup_t>(3.2059423744573386440971405952224204950e+14L), static_cast<lookup_t>(9.0051433962267018216365614546207459567e+14L), static_cast<lookup_t>(2.5268147258457822451512967243234631750e+15L),
static_cast<lookup_t>(7.0832381329352301326018261305316090522e+15L), static_cast<lookup_t>(1.9837699245933465967698692976753294646e+16L), static_cast<lookup_t>(5.5510470830970075484537561902113104381e+16L), static_cast<lookup_t>(1.5520433569614702817608320254284931407e+17L),
static_cast<lookup_t>(4.3360826779369661842459877227403719730e+17L), static_cast<lookup_t>(1.2105254067703227363724895246493485480e+18L), static_cast<lookup_t>(3.3771426165357561311906703760513324357e+18L), static_cast<lookup_t>(9.4154106734807994163159964299613921804e+18L),
static_cast<lookup_t>(2.6233583234732252918129199544138403574e+19L), static_cast<lookup_t>(7.3049547543861043990576614751671879498e+19L), static_cast<lookup_t>(2.0329709713386190214340167519800405595e+20L), static_cast<lookup_t>(5.6547040503180956413560918381429636734e+20L),
static_cast<lookup_t>(1.5720421975868292906615658755032744790e+21L), static_cast<lookup_t>(4.3682149334771264822761478593874428627e+21L), static_cast<lookup_t>(1.2132170565093316762294432610117848880e+22L), static_cast<lookup_t>(3.3680332378068632345542636794533635462e+22L),
static_cast<lookup_t>(9.3459982052259884835729892206738573922e+22L), static_cast<lookup_t>(2.5923527642935362320437266614667426924e+23L), static_cast<lookup_t>(7.1876803203773878618909930893087860822e+23L), static_cast<lookup_t>(1.9921241603726199616378561653688236827e+24L),
static_cast<lookup_t>(5.5192924995054165325072406547517121131e+24L), static_cast<lookup_t>(1.5286067837683347062387143159276002521e+25L), static_cast<lookup_t>(4.2321318958281094260005100745711666956e+25L), static_cast<lookup_t>(1.1713293177672778461879598480402173158e+26L),
static_cast<lookup_t>(3.2408603996214813669049988277609543829e+26L), static_cast<lookup_t>(8.9641258264226027960478448084812796397e+26L), static_cast<lookup_t>(2.4787141382364034104243901241243054434e+27L), static_cast<lookup_t>(6.8520443388941057019777430988685937812e+27L),
static_cast<lookup_t>(1.8936217407781711443114787060753312270e+28L), static_cast<lookup_t>(5.2317811346197017832254642778313331353e+28L), static_cast<lookup_t>(1.4450833904658542238325922893692265683e+29L), static_cast<lookup_t>(3.9904954117194348050619127737142206367e+29L)
}; // w0zs
static constexpr lookup_t wm1es[noof_wm1es] =
{ // Fukushima e array e[0] = e^1 = 2.718, e[1] = e^2 = 7.39 ... e[64] = 4.60718e+28.
2.7182818284590452353602874713526624978e+00L,
7.3890560989306502272304274605750078132e+00L, 2.0085536923187667740928529654581717897e+01L, 5.4598150033144239078110261202860878403e+01L, 1.4841315910257660342111558004055227962e+02L,
4.0342879349273512260838718054338827961e+02L, 1.0966331584284585992637202382881214324e+03L, 2.9809579870417282747435920994528886738e+03L, 8.1030839275753840077099966894327599650e+03L,
2.2026465794806716516957900645284244366e+04L, 5.9874141715197818455326485792257781614e+04L, 1.6275479141900392080800520489848678317e+05L, 4.4241339200892050332610277594908828178e+05L,
1.2026042841647767777492367707678594494e+06L, 3.2690173724721106393018550460917213155e+06L, 8.8861105205078726367630237407814503508e+06L, 2.4154952753575298214775435180385823880e+07L,
6.5659969137330511138786503259060033569e+07L, 1.7848230096318726084491003378872270388e+08L, 4.8516519540979027796910683054154055868e+08L, 1.3188157344832146972099988837453027851e+09L,
3.5849128461315915616811599459784206892e+09L, 9.7448034462489026000346326848229752776e+09L, 2.6489122129843472294139162152811882341e+10L, 7.2004899337385872524161351466126157915e+10L,
1.9572960942883876426977639787609534279e+11L, 5.3204824060179861668374730434117744166e+11L, 1.4462570642914751736770474229969288569e+12L, 3.9313342971440420743886205808435276858e+12L,
1.0686474581524462146990468650741401650e+13L, 2.9048849665247425231085682111679825667e+13L, 7.8962960182680695160978022635108224220e+13L, 2.1464357978591606462429776153126088037e+14L,
5.8346174252745488140290273461039101900e+14L, 1.5860134523134307281296446257746601252e+15L, 4.3112315471151952271134222928569253908e+15L, 1.1719142372802611308772939791190194522e+16L,
3.1855931757113756220328671701298646000e+16L, 8.6593400423993746953606932719264934250e+16L, 2.3538526683701998540789991074903480451e+17L, 6.3984349353005494922266340351557081888e+17L,
1.7392749415205010473946813036112352261e+18L, 4.7278394682293465614744575627442803708e+18L, 1.2851600114359308275809299632143099258e+19L, 3.4934271057485095348034797233406099533e+19L,
9.4961194206024488745133649117118323102e+19L, 2.5813128861900673962328580021527338043e+20L, 7.0167359120976317386547159988611740546e+20L, 1.9073465724950996905250998409538484474e+21L,
5.1847055285870724640874533229334853848e+21L, 1.4093490824269387964492143312370168789e+22L, 3.8310080007165768493035695487861993899e+22L, 1.0413759433029087797183472933493796440e+23L,
2.8307533032746939004420635480140745409e+23L, 7.6947852651420171381827455901293939921e+23L, 2.0916594960129961539070711572146737782e+24L, 5.6857199993359322226403488206332533034e+24L,
1.5455389355901039303530766911174620068e+25L, 4.2012104037905142549565934307191617684e+25L, 1.1420073898156842836629571831447656302e+26L, 3.1042979357019199087073421411071003721e+26L,
8.4383566687414544890733294803731179601e+26L, 2.2937831594696098790993528402686136005e+27L, 6.2351490808116168829092387089284697448e+27L
static_cast<lookup_t>(2.7182818284590452353602874713526624978e+00L),
static_cast<lookup_t>(7.3890560989306502272304274605750078132e+00L), static_cast<lookup_t>(2.0085536923187667740928529654581717897e+01L), static_cast<lookup_t>(5.4598150033144239078110261202860878403e+01L), static_cast<lookup_t>(1.4841315910257660342111558004055227962e+02L),
static_cast<lookup_t>(4.0342879349273512260838718054338827961e+02L), static_cast<lookup_t>(1.0966331584284585992637202382881214324e+03L), static_cast<lookup_t>(2.9809579870417282747435920994528886738e+03L), static_cast<lookup_t>(8.1030839275753840077099966894327599650e+03L),
static_cast<lookup_t>(2.2026465794806716516957900645284244366e+04L), static_cast<lookup_t>(5.9874141715197818455326485792257781614e+04L), static_cast<lookup_t>(1.6275479141900392080800520489848678317e+05L), static_cast<lookup_t>(4.4241339200892050332610277594908828178e+05L),
static_cast<lookup_t>(1.2026042841647767777492367707678594494e+06L), static_cast<lookup_t>(3.2690173724721106393018550460917213155e+06L), static_cast<lookup_t>(8.8861105205078726367630237407814503508e+06L), static_cast<lookup_t>(2.4154952753575298214775435180385823880e+07L),
static_cast<lookup_t>(6.5659969137330511138786503259060033569e+07L), static_cast<lookup_t>(1.7848230096318726084491003378872270388e+08L), static_cast<lookup_t>(4.8516519540979027796910683054154055868e+08L), static_cast<lookup_t>(1.3188157344832146972099988837453027851e+09L),
static_cast<lookup_t>(3.5849128461315915616811599459784206892e+09L), static_cast<lookup_t>(9.7448034462489026000346326848229752776e+09L), static_cast<lookup_t>(2.6489122129843472294139162152811882341e+10L), static_cast<lookup_t>(7.2004899337385872524161351466126157915e+10L),
static_cast<lookup_t>(1.9572960942883876426977639787609534279e+11L), static_cast<lookup_t>(5.3204824060179861668374730434117744166e+11L), static_cast<lookup_t>(1.4462570642914751736770474229969288569e+12L), static_cast<lookup_t>(3.9313342971440420743886205808435276858e+12L),
static_cast<lookup_t>(1.0686474581524462146990468650741401650e+13L), static_cast<lookup_t>(2.9048849665247425231085682111679825667e+13L), static_cast<lookup_t>(7.8962960182680695160978022635108224220e+13L), static_cast<lookup_t>(2.1464357978591606462429776153126088037e+14L),
static_cast<lookup_t>(5.8346174252745488140290273461039101900e+14L), static_cast<lookup_t>(1.5860134523134307281296446257746601252e+15L), static_cast<lookup_t>(4.3112315471151952271134222928569253908e+15L), static_cast<lookup_t>(1.1719142372802611308772939791190194522e+16L),
static_cast<lookup_t>(3.1855931757113756220328671701298646000e+16L), static_cast<lookup_t>(8.6593400423993746953606932719264934250e+16L), static_cast<lookup_t>(2.3538526683701998540789991074903480451e+17L), static_cast<lookup_t>(6.3984349353005494922266340351557081888e+17L),
static_cast<lookup_t>(1.7392749415205010473946813036112352261e+18L), static_cast<lookup_t>(4.7278394682293465614744575627442803708e+18L), static_cast<lookup_t>(1.2851600114359308275809299632143099258e+19L), static_cast<lookup_t>(3.4934271057485095348034797233406099533e+19L),
static_cast<lookup_t>(9.4961194206024488745133649117118323102e+19L), static_cast<lookup_t>(2.5813128861900673962328580021527338043e+20L), static_cast<lookup_t>(7.0167359120976317386547159988611740546e+20L), static_cast<lookup_t>(1.9073465724950996905250998409538484474e+21L),
static_cast<lookup_t>(5.1847055285870724640874533229334853848e+21L), static_cast<lookup_t>(1.4093490824269387964492143312370168789e+22L), static_cast<lookup_t>(3.8310080007165768493035695487861993899e+22L), static_cast<lookup_t>(1.0413759433029087797183472933493796440e+23L),
static_cast<lookup_t>(2.8307533032746939004420635480140745409e+23L), static_cast<lookup_t>(7.6947852651420171381827455901293939921e+23L), static_cast<lookup_t>(2.0916594960129961539070711572146737782e+24L), static_cast<lookup_t>(5.6857199993359322226403488206332533034e+24L),
static_cast<lookup_t>(1.5455389355901039303530766911174620068e+25L), static_cast<lookup_t>(4.2012104037905142549565934307191617684e+25L), static_cast<lookup_t>(1.1420073898156842836629571831447656302e+26L), static_cast<lookup_t>(3.1042979357019199087073421411071003721e+26L),
static_cast<lookup_t>(8.4383566687414544890733294803731179601e+26L), static_cast<lookup_t>(2.2937831594696098790993528402686136005e+27L), static_cast<lookup_t>(6.2351490808116168829092387089284697448e+27L)
}; // wm1es
static constexpr lookup_t wm1zs[noof_wm1zs] =
{ // Fukushima G array of z values for integral K, (Fukushima Gk) g[0] (k = -1) = 1 ... g[64] = -1.0264389699511303e-26.
-3.6787944117144232159552377016146086745e-01L,
-2.7067056647322538378799898994496880682e-01L, -1.4936120510359182893802724695018532990e-01L, -7.3262555554936721174872085092964968848e-02L, -3.3689734995427335483180242115742121244e-02L,
-1.4872513059998150538271004584900007349e-02L, -6.3831737588816134560219525908649783853e-03L, -2.6837010232200947105711130062468881545e-03L, -1.1106882367801159454787302165703044346e-03L,
-4.5399929762484851535591515560550610238e-04L, -1.8371870869270225243899069096638966986e-04L, -7.3730548239938517104187698145666387735e-05L, -2.9384282290753706235208604777002963102e-05L,
-1.1641402067449950376895791995913672125e-05L, -4.5885348075273868255721924655343445906e-06L, -1.8005627955081458322204028649620350662e-06L, -7.0378941219347833214067471222239770590e-07L,
-2.7413963540482731185045932620331377352e-07L, -1.0645313231320808326024667350792279852e-07L, -4.1223072448771156559318807603116419528e-08L, -1.5923376898615004128677660806663065530e-08L,
-6.1368298043116345769816086674174450569e-09L, -2.3602323152914347699033314033408744848e-09L, -9.0603229062698346039479269140561762700e-10L, -3.4719859662410051486654409365217142276e-10L,
-1.3283631472964644271673440503045960993e-10L, -5.0747278046555248958473301297399200773e-11L, -1.9360320299432568426355237044475945959e-11L, -7.3766303773930764398798182830872768331e-12L,
-2.8072868906520523814747496670136120235e-12L, -1.0671679036256927021016406931839827582e-12L, -4.0525329757101362313986893299088308423e-13L, -1.5374324278841211301808010293913555758e-13L,
-5.8272886672428440854292491647585674200e-14L, -2.2067908660514462849736574172862899665e-14L, -8.3502821888768497979241489950570881481e-15L, -3.1572276215253043438828784344882603413e-15L,
-1.1928704609782512589094065678481294667e-15L, -4.5038074274761565346423524046963087756e-16L, -1.6993417021166355981316939131434632072e-16L, -6.4078169762734539491726202799339200356e-17L,
-2.4147993510032951187990399698408378385e-17L, -9.0950634616416460925150243301974013218e-18L, -3.4236981860988704669138593608831552044e-18L, -1.2881333612472271400115547331327717431e-18L,
-4.8440839844747536942311292467369300505e-19L, -1.8207788854829779430777944237164900798e-19L, -6.8407875971564885101695409345634890862e-20L, -2.5690139750480973292141845983878483991e-20L,
-9.6437492398195889150867140826350628738e-21L, -3.6186918227651991108814673877821174787e-21L, -1.3573451162272064984454015639725697008e-21L, -5.0894204288895982960223079251039701810e-22L,
-1.9076194289884357960571121174956927722e-22L, -7.1476978375412669048039237333931704166e-23L, -2.6773000149758626855152191436980592206e-23L, -1.0025115553818576399048488234179587012e-23L,
-3.7527362568743669891693429406973638384e-24L, -1.4043571811296963574776515073934728352e-24L, -5.2539064576179122030932396804434996219e-25L, -1.9650175744554348142907611432678556896e-25L,
-7.3474021582506822389671905824031421322e-26L, -2.7465543000397410133825686340097295749e-26L, -1.0264389699511282259046957018510946438e-26L
static_cast<lookup_t>(-3.6787944117144232159552377016146086745e-01L),
static_cast<lookup_t>(-2.7067056647322538378799898994496880682e-01L), static_cast<lookup_t>(-1.4936120510359182893802724695018532990e-01L), static_cast<lookup_t>(-7.3262555554936721174872085092964968848e-02L), static_cast<lookup_t>(-3.3689734995427335483180242115742121244e-02L),
static_cast<lookup_t>(-1.4872513059998150538271004584900007349e-02L), static_cast<lookup_t>(-6.3831737588816134560219525908649783853e-03L), static_cast<lookup_t>(-2.6837010232200947105711130062468881545e-03L), static_cast<lookup_t>(-1.1106882367801159454787302165703044346e-03L),
static_cast<lookup_t>(-4.5399929762484851535591515560550610238e-04L), static_cast<lookup_t>(-1.8371870869270225243899069096638966986e-04L), static_cast<lookup_t>(-7.3730548239938517104187698145666387735e-05L), static_cast<lookup_t>(-2.9384282290753706235208604777002963102e-05L),
static_cast<lookup_t>(-1.1641402067449950376895791995913672125e-05L), static_cast<lookup_t>(-4.5885348075273868255721924655343445906e-06L), static_cast<lookup_t>(-1.8005627955081458322204028649620350662e-06L), static_cast<lookup_t>(-7.0378941219347833214067471222239770590e-07L),
static_cast<lookup_t>(-2.7413963540482731185045932620331377352e-07L), static_cast<lookup_t>(-1.0645313231320808326024667350792279852e-07L), static_cast<lookup_t>(-4.1223072448771156559318807603116419528e-08L), static_cast<lookup_t>(-1.5923376898615004128677660806663065530e-08L),
static_cast<lookup_t>(-6.1368298043116345769816086674174450569e-09L), static_cast<lookup_t>(-2.3602323152914347699033314033408744848e-09L), static_cast<lookup_t>(-9.0603229062698346039479269140561762700e-10L), static_cast<lookup_t>(-3.4719859662410051486654409365217142276e-10L),
static_cast<lookup_t>(-1.3283631472964644271673440503045960993e-10L), static_cast<lookup_t>(-5.0747278046555248958473301297399200773e-11L), static_cast<lookup_t>(-1.9360320299432568426355237044475945959e-11L), static_cast<lookup_t>(-7.3766303773930764398798182830872768331e-12L),
static_cast<lookup_t>(-2.8072868906520523814747496670136120235e-12L), static_cast<lookup_t>(-1.0671679036256927021016406931839827582e-12L), static_cast<lookup_t>(-4.0525329757101362313986893299088308423e-13L), static_cast<lookup_t>(-1.5374324278841211301808010293913555758e-13L),
static_cast<lookup_t>(-5.8272886672428440854292491647585674200e-14L), static_cast<lookup_t>(-2.2067908660514462849736574172862899665e-14L), static_cast<lookup_t>(-8.3502821888768497979241489950570881481e-15L), static_cast<lookup_t>(-3.1572276215253043438828784344882603413e-15L),
static_cast<lookup_t>(-1.1928704609782512589094065678481294667e-15L), static_cast<lookup_t>(-4.5038074274761565346423524046963087756e-16L), static_cast<lookup_t>(-1.6993417021166355981316939131434632072e-16L), static_cast<lookup_t>(-6.4078169762734539491726202799339200356e-17L),
static_cast<lookup_t>(-2.4147993510032951187990399698408378385e-17L), static_cast<lookup_t>(-9.0950634616416460925150243301974013218e-18L), static_cast<lookup_t>(-3.4236981860988704669138593608831552044e-18L), static_cast<lookup_t>(-1.2881333612472271400115547331327717431e-18L),
static_cast<lookup_t>(-4.8440839844747536942311292467369300505e-19L), static_cast<lookup_t>(-1.8207788854829779430777944237164900798e-19L), static_cast<lookup_t>(-6.8407875971564885101695409345634890862e-20L), static_cast<lookup_t>(-2.5690139750480973292141845983878483991e-20L),
static_cast<lookup_t>(-9.6437492398195889150867140826350628738e-21L), static_cast<lookup_t>(-3.6186918227651991108814673877821174787e-21L), static_cast<lookup_t>(-1.3573451162272064984454015639725697008e-21L), static_cast<lookup_t>(-5.0894204288895982960223079251039701810e-22L),
static_cast<lookup_t>(-1.9076194289884357960571121174956927722e-22L), static_cast<lookup_t>(-7.1476978375412669048039237333931704166e-23L), static_cast<lookup_t>(-2.6773000149758626855152191436980592206e-23L), static_cast<lookup_t>(-1.0025115553818576399048488234179587012e-23L),
static_cast<lookup_t>(-3.7527362568743669891693429406973638384e-24L), static_cast<lookup_t>(-1.4043571811296963574776515073934728352e-24L), static_cast<lookup_t>(-5.2539064576179122030932396804434996219e-25L), static_cast<lookup_t>(-1.9650175744554348142907611432678556896e-25L),
static_cast<lookup_t>(-7.3474021582506822389671905824031421322e-26L), static_cast<lookup_t>(-2.7465543000397410133825686340097295749e-26L), static_cast<lookup_t>(-1.0264389699511282259046957018510946438e-26L)
}; // wm1zs
} // namespace lambert_w_lookup
} // namespace detail

View File

@@ -153,7 +153,19 @@ T erf_imp(T z, bool invert, const Policy& pol, const Tag& t)
if ((boost::math::isnan)(z))
return policies::raise_domain_error("boost::math::erf<%1%>(%1%)", "Expected a finite argument but got %1%", z, pol);
if(z < 0)
if (fabs(z) < tools::root_epsilon<T>())
{
// Series[Erf[x], {x, 0, 4}]
// Series[Erfc[x], {x, 0, 4}]
const T term2 { z * 2 / constants::root_pi<T>() };
return invert ? 1 - term2 : term2;
}
const bool signbit_result = ((boost::math::signbit)(z) != 0);
if (signbit_result)
{
if(!invert)
return -erf_imp(T(-z), invert, pol, t);
@@ -172,32 +184,32 @@ T erf_imp(T z, bool invert, const Policy& pol, const Tag& t)
}
else
{
T x = z * z;
const T z_sq { z * z };
if(z < 1.3f)
{
// Compute P:
// This is actually good for z p to 2 or so, but the cutoff given seems
// to be the best compromise. Performance wise, this is way quicker than anything else...
// to be the best compromise. Regarding performance, this is way quicker than anything else...
result = erf_series_near_zero_sum(z, pol);
}
else if(x > 1 / tools::epsilon<T>())
else if(z_sq > 1 / tools::epsilon<T>())
{
// http://functions.wolfram.com/06.27.06.0006.02
invert = !invert;
result = exp(-x) / (constants::root_pi<T>() * z);
result = exp(-z_sq) / (constants::root_pi<T>() * z);
}
else
{
// Compute Q:
invert = !invert;
result = z * exp(-x);
result = z * exp(-z_sq);
result /= boost::math::constants::root_pi<T>();
result *= upper_gamma_fraction(T(0.5f), x, policies::get_epsilon<T, Policy>());
result *= upper_gamma_fraction(T(0.5f), z_sq, policies::get_epsilon<T, Policy>());
}
}
if(invert)
result = 1 - result;
return result;
return ((!invert) ? result : 1 - result);
}
// LCOV_EXCL_STOP

View File

@@ -16,6 +16,8 @@
#include <boost/math/tools/type_traits.hpp>
#include <boost/math/policies/error_handling.hpp>
#include <boost/math/special_functions/math_fwd.hpp>
#include <boost/math/tools/utility.hpp>
#include <boost/math/tools/numeric_limits.hpp>
namespace boost{ namespace math{ namespace detail{
@@ -53,6 +55,48 @@ BOOST_MATH_GPU_ENABLED T hypot_imp(T x, T y, const Policy& pol)
return x * sqrt(1 + rat*rat);
} // template <class T> T hypot(T x, T y)
template <class T, class Policy>
BOOST_MATH_GPU_ENABLED T hypot_imp(T x, T y, T z, const Policy& pol)
{
BOOST_MATH_STD_USING
x = fabs(x);
y = fabs(y);
z = fabs(z);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127)
#endif
// special case, see C99 Annex F:
BOOST_MATH_IF_CONSTEXPR (boost::math::numeric_limits<T>::has_infinity)
{
if(((x == boost::math::numeric_limits<T>::infinity())
|| (y == boost::math::numeric_limits<T>::infinity())
|| (z == boost::math::numeric_limits<T>::infinity())))
return policies::raise_overflow_error<T>("boost::math::hypot<%1%>(%1%,%1%,%1%)", nullptr, pol);
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
const T a {(max)((max)(x, y), z)};
if (a == T(0))
{
return a;
}
const T x_div_a {x / a};
const T y_div_a {y / a};
const T z_div_a {z / a};
return a * sqrt(x_div_a * x_div_a
+ y_div_a * y_div_a
+ z_div_a * z_div_a);
}
}
template <class T1, class T2>
@@ -64,7 +108,7 @@ BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type
static_cast<result_type>(x), static_cast<result_type>(y), policies::policy<>());
}
template <class T1, class T2, class Policy>
template <class T1, class T2, class Policy, boost::math::enable_if_t<policies::is_policy_v<Policy>, bool>>
BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type
hypot(T1 x, T2 y, const Policy& pol)
{
@@ -73,6 +117,28 @@ BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type
static_cast<result_type>(x), static_cast<result_type>(y), pol);
}
template <class T1, class T2, class T3, boost::math::enable_if_t<!policies::is_policy_v<T3>, bool>>
BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T1, T2, T3>
hypot(T1 x, T2 y, T3 z)
{
using result_type = tools::promote_args_t<T1, T2, T3>;
return detail::hypot_imp(static_cast<result_type>(x),
static_cast<result_type>(y),
static_cast<result_type>(z),
policies::policy<>());
}
template <class T1, class T2, class T3, class Policy>
BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T1, T2, T3>
hypot(T1 x, T2 y, T3 z, const Policy& pol)
{
using result_type = tools::promote_args_t<T1, T2, T3>;
return detail::hypot_imp(static_cast<result_type>(x),
static_cast<result_type>(y),
static_cast<result_type>(z),
pol);
}
} // namespace math
} // namespace boost

View File

@@ -636,10 +636,18 @@ namespace boost
BOOST_MATH_GPU_ENABLED tools::promote_args_t<T1, T2>
hypot(T1 x, T2 y);
template <class T1, class T2, class Policy>
template <class T1, class T2, class Policy, boost::math::enable_if_t<policies::is_policy_v<Policy>, bool> = true>
BOOST_MATH_GPU_ENABLED tools::promote_args_t<T1, T2>
hypot(T1 x, T2 y, const Policy&);
template <class T1, class T2, class T3, boost::math::enable_if_t<!policies::is_policy_v<T3>, bool> = true>
BOOST_MATH_GPU_ENABLED tools::promote_args_t<T1, T2, T3>
hypot(T1 x, T2 y, T3 z);
template <class T1, class T2, class T3, class Policy>
BOOST_MATH_GPU_ENABLED tools::promote_args_t<T1, T2, T3>
hypot(T1 x, T2 y, T3 z, const Policy& pol);
// cbrt - cube root.
template <class RT>
BOOST_MATH_GPU_ENABLED tools::promote_args_t<RT> cbrt(RT z);

View File

@@ -146,18 +146,6 @@ void test_beale() {
CHECK_ABSOLUTE_ERROR(Real(1)/Real(2), local_minima[1], Real(0.1));
}
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
void test_dimensioned_sphere() {
std::cout << "Testing CMA-ES on dimensioned sphere . . .\n";
using ArgType = std::vector<quantity<length>>;
auto params = cma_es_parameters<ArgType>();
params.lower_bounds.resize(4, -1.0*meter);
params.upper_bounds.resize(4, 1*meter);
std::mt19937_64 gen(56789);
auto local_minima = cma_es(dimensioned_sphere, params, gen);
}
#endif
int main() {
#if (defined(__clang__) || defined(_MSC_VER))
test_ackley<float>();
@@ -166,9 +154,6 @@ int main() {
test_rastrigin<double>();
test_three_hump_camel<float>();
test_beale<double>();
#endif
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
test_dimensioned_sphere();
#endif
test_sphere();
return boost::math::test::report_errors();

View File

@@ -369,6 +369,7 @@ void instantiate(RealType)
boost::math::jacobi_theta4m1(v1, v2);
boost::math::jacobi_theta4m1tau(v1, v2);
boost::math::hypot(v1, v2);
boost::math::hypot(v1, v2, v3);
boost::math::sinc_pi(v1);
boost::math::sinhc_pi(v1);
boost::math::asinh(v1);

View File

@@ -16,8 +16,11 @@
void compile_and_link_test()
{
check_result<float>(boost::math::hypot<float>(f, f));
check_result<float>(boost::math::hypot(f, f, f));
check_result<double>(boost::math::hypot<double>(d, d));
check_result<double>(boost::math::hypot<double>(d, d,d));
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
check_result<long double>(boost::math::hypot<long double>(l, l));
check_result<long double>(boost::math::hypot<long double>(l, l, l));
#endif
}

View File

@@ -188,19 +188,6 @@ void test_beale() {
CHECK_ABSOLUTE_ERROR(Real(1)/Real(2), local_minima[1], Real(2e-4));
}
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
void test_dimensioned_sphere() {
std::cout << "Testing differential evolution on dimensioned sphere . . .\n";
using ArgType = std::vector<quantity<length>>;
auto params = differential_evolution_parameters<ArgType>();
params.lower_bounds.resize(4, -1.0*meter);
params.upper_bounds.resize(4, 1*meter);
params.threads = 2;
std::mt19937_64 gen(56789);
auto local_minima = differential_evolution(dimensioned_sphere, params, gen);
}
#endif
int main() {
#if defined(__clang__) || defined(_MSC_VER)
@@ -210,9 +197,6 @@ int main() {
test_rastrigin<float>();
test_three_hump_camel<float>();
test_beale<double>();
#endif
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
test_dimensioned_sphere();
#endif
test_sphere();
test_parameter_checks();

36
test/git_issue_1308.cpp Normal file
View File

@@ -0,0 +1,36 @@
// Copyright John Maddock 2025.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_TEST_MAIN
#include <boost/math/distributions.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <iostream>
#include <boost/test/tools/floating_point_comparison.hpp>
#include <boost/test/unit_test.hpp>
typedef boost::math::policies::policy<
boost::math::policies::promote_double<false>
> SciPyPolicy;
using mp_t = boost::multiprecision::cpp_bin_float_quad;
BOOST_AUTO_TEST_CASE(test_main)
{
double v = 980.0;
double l = 38.0;
double x = 1.5;
// With policy
double y_policy = boost::math::cdf(
boost::math::non_central_t_distribution<double, SciPyPolicy>(v, l), x);
double reference = 1.1824454111413493e-291;
std::cout << std::setprecision(17);
std::cout << "With SciPyPolicy: cdf(noncentral_t; x=" << x << ", v=" << v << ", l=" << l << ") = " << y_policy << std::endl;
double tolerance = 1e-8; // precision is limited due to cancellation
BOOST_CHECK_CLOSE_FRACTION(y_policy, reference, tolerance);
}

View File

@@ -10,6 +10,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/test/tools/floating_point_comparison.hpp>
#include <boost/math/special_functions/math_fwd.hpp>
#include <boost/math/special_functions/hypot.hpp>
#include <cmath>
@@ -41,6 +42,22 @@ const float boundaries[] = {
std::sqrt((std::numeric_limits<float>::min)()) * 2,
};
void do_test_boundaries(float x, float y, float z)
{
float expected = static_cast<float>((boost::math::hypot)(
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
static_cast<long double>(x),
static_cast<long double>(y),
static_cast<long double>(z)));
#else
static_cast<double>(x),
static_cast<double>(y),
static_cast<double>(z));
#endif
float found = (boost::math::hypot)(x, y, z);
BOOST_CHECK_CLOSE(expected, found, tolerance);
}
void do_test_boundaries(float x, float y)
{
float expected = static_cast<float>((boost::math::hypot)(
@@ -55,12 +72,31 @@ void do_test_boundaries(float x, float y)
BOOST_CHECK_CLOSE(expected, found, tolerance);
}
void test_boundaries(float x, float y, float z)
{
do_test_boundaries(x, y, z);
do_test_boundaries(-x, y, z);
do_test_boundaries(x, -y, z);
do_test_boundaries(x, y, -z);
do_test_boundaries(-x, -y, z);
do_test_boundaries(-x, y, -z);
do_test_boundaries(x, -y, -z);
do_test_boundaries(-x, -y, -z);
}
void test_boundaries(float x, float y)
{
do_test_boundaries(x, y);
do_test_boundaries(-x, y);
do_test_boundaries(-x, -y);
do_test_boundaries(x, -y);
for(unsigned i = 0; i < sizeof(boundaries)/sizeof(float); ++i)
{
test_boundaries(x, y, boundaries[i]);
test_boundaries(x, y, boundaries[i] + std::numeric_limits<float>::epsilon()*boundaries[i]);
test_boundaries(x, y, boundaries[i] - std::numeric_limits<float>::epsilon()*boundaries[i]);
}
}
void test_boundaries(float x)
@@ -92,12 +128,26 @@ void test_spots()
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[i], zero), std::fabs(-boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[i], -zero), std::fabs(boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[i], -zero), std::fabs(-boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[i], zero, zero), std::fabs(boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[i], zero, zero), std::fabs(-boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[i], -zero, zero), std::fabs(boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[i], -zero, zero), std::fabs(-boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(zero, boundaries[i], zero), std::fabs(boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(zero, -boundaries[i], zero), std::fabs(-boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(zero, boundaries[i], -zero), std::fabs(boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(zero, -boundaries[i], -zero), std::fabs(-boundaries[i]));
for(unsigned j = 0; j < sizeof(boundaries)/sizeof(float); ++j)
{
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[i], boundaries[j]), boost::math::hypot(boundaries[j], boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[i], boundaries[j]), boost::math::hypot(boundaries[i], -boundaries[j]));
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[i], -boundaries[j]), boost::math::hypot(-boundaries[j], -boundaries[i]));
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[i], -boundaries[j]), boost::math::hypot(-boundaries[i], boundaries[j]));
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[i], boundaries[j], boundaries[j]), boost::math::hypot(boundaries[j], boundaries[i], boundaries[j]));
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[i], boundaries[j], boundaries[j]), boost::math::hypot(boundaries[i], boundaries[j], -boundaries[j]));
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[i], -boundaries[j], boundaries[j]), boost::math::hypot(-boundaries[j], -boundaries[i], boundaries[j]));
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[i], -boundaries[j], boundaries[j]), boost::math::hypot(-boundaries[i], boundaries[j], boundaries[j]));
}
}
if((std::numeric_limits<float>::has_infinity) && (std::numeric_limits<float>::has_quiet_NaN))
@@ -108,6 +158,16 @@ void test_spots()
BOOST_CHECK_EQUAL(boost::math::hypot(-inf, nan), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(nan, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(nan, -inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(inf, nan, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(-inf, nan, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(nan, inf, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(nan, -inf, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(nan, nan, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(-inf, nan, nan), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(nan, inf, nan), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(nan, -inf, nan), inf);
for(unsigned j = 0; j < sizeof(boundaries)/sizeof(float); ++j)
{
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[j], inf), inf);
@@ -118,6 +178,15 @@ void test_spots()
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[j], -inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(-inf, boundaries[j]), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(-inf, -boundaries[j]), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[j], inf, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[j], inf, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(inf, boundaries[j], inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(inf, -boundaries[j], inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(boundaries[j], -inf, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(-boundaries[j], -inf, inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(-inf, boundaries[j], inf), inf);
BOOST_CHECK_EQUAL(boost::math::hypot(-inf, -boundaries[j], inf), inf);
}
}
}

View File

@@ -56,14 +56,16 @@ template <class Real> void test_ackley() {
std::array<Real, 2> initial_guess{0, 0};
jso_params.initial_guess = &initial_guess;
local_minima = jso(ack, jso_params, gen);
CHECK_EQUAL(local_minima[0], Real(0));
CHECK_EQUAL(local_minima[1], Real(0));
using std::fabs;
CHECK_LE(fabs(local_minima[0]), 128 * boost::math::tools::epsilon<Real>());
CHECK_LE(fabs(local_minima[1]), 128 * boost::math::tools::epsilon<Real>());
}
template <class Real> void test_rosenbrock_saddle() {
std::cout << "Testing jSO on Rosenbrock saddle . . .\n";
using ArgType = std::array<Real, 2>;
auto jso_params = jso_parameters<ArgType>();
jso_parameters<ArgType> jso_params { };
jso_params.lower_bounds = {0.5, 0.5};
jso_params.upper_bounds = {2.048, 2.048};
std::mt19937_64 gen(234568);
@@ -143,31 +145,13 @@ void test_beale() {
CHECK_ABSOLUTE_ERROR(Real(1)/Real(2), local_minima[1], Real(2e-4));
}
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
void test_dimensioned_sphere() {
std::cout << "Testing jso on dimensioned sphere . . .\n";
using ArgType = std::vector<quantity<length>>;
auto params = jso_parameters<ArgType>();
params.lower_bounds.resize(4, -1.0*meter);
params.upper_bounds.resize(4, 1*meter);
params.threads = 2;
std::mt19937_64 gen(56789);
auto local_minima = jso(dimensioned_sphere, params, gen);
}
#endif
int main() {
#if defined(__clang__) || defined(_MSC_VER)
test_ackley<float>();
test_ackley<double>();
test_rosenbrock_saddle<double>();
test_rastrigin<double>();
test_three_hump_camel<float>();
test_beale<double>();
#endif
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
test_dimensioned_sphere();
#endif
test_sphere();
test_weighted_lehmer_mean();
return boost::math::test::report_errors();

View File

@@ -151,21 +151,6 @@ void test_beale() {
CHECK_ABSOLUTE_ERROR(Real(1)/Real(2), local_minima[1], Real(0.1));
}
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
void test_dimensioned_sphere() {
std::cout << "Testing random search on dimensioned sphere . . .\n";
using ArgType = std::vector<quantity<length>>;
auto rs_params = random_search_parameters<ArgType>();
rs_params.lower_bounds.resize(4, -1.0*meter);
rs_params.upper_bounds.resize(4, 1*meter);
rs_params.max_function_calls = 100000;
rs_params.threads = 2;
std::mt19937_64 gen(56789);
auto local_minima = random_search(dimensioned_sphere, rs_params, gen);
}
#endif
int main() {
#if defined(__clang__) || defined(_MSC_VER)
test_ackley<float>();
@@ -174,9 +159,6 @@ int main() {
test_rastrigin<double>();
test_three_hump_camel<float>();
test_beale<double>();
#endif
#if BOOST_MATH_TEST_UNITS_COMPATIBILITY
test_dimensioned_sphere();
#endif
test_sphere();
return boost::math::test::report_errors();

View File

@@ -265,80 +265,6 @@ void test_bessel(T, const char* name)
// Some special cases:
//
// Specific tests for Git-issue1292.
{
using local_ctrl_array_type = std::array<table_entry_type, std::size_t { UINT8_C(43) }>;
// Table[N[BesselJ[3, n/10], 40], {n, 9, 51, 1}]
static const local_ctrl_array_type ctrl_data =
{{
SC_(0.01443402847586617545767791623904539755731), SC_(0.01956335398266840591890532162175150825451), SC_(0.02569452861246328174726417617756888741432), SC_(0.03287433692499494270867882730165246683837),
SC_(0.04113582571991693187673486447516908751463), SC_(0.05049771328895129623567992727476043273558), SC_(0.06096395114113963064394955997646387979571), SC_(0.07252344333261900300034928368068248675877),
SC_(0.08514992694801526415321095754253909148633), SC_(0.09880201565861918291536618746528733463749), SC_(0.1134234066389601112649841240858617923591), SC_(0.1289432494744020510987933329692398352700),
SC_(0.1452766740542063665759023355570418120750), SC_(0.1623254728332874543121706910035271736854), SC_(0.1799789312775334540800304157279732327839), SC_(0.1981147987975668248498434552081155790183),
SC_(0.2166003910391135247666890035159637217168), SC_(0.2352938130489638091015220916013129483423), SC_(0.2540452915872273499615464996563039918262), SC_(0.2726986037216204380267188592437356599939),
SC_(0.2910925878291867784836313080855848616815), SC_(0.3090627222552516436182601949468331494291), SC_(0.3264427561473409695937042738575781129080), SC_(0.3430663764006682009386373318558777864023),
SC_(0.3587688942275418259451574456258027163924), SC_(0.3733889346000900583527754127339797472980), SC_(0.3867701117168813668578718121131100327218), SC_(0.3987626737105880326848194417650226836608),
SC_(0.4092251000454309977422936498249743734653), SC_(0.4180256354477855744864458808409348352597), SC_(0.4250437447674560017637404058105525727991), SC_(0.4301714738756219403581834788533355563393),
SC_(0.4333147025616927046073022200802734463060), SC_(0.4343942763872007823091130214493427347554), SC_(0.4333470055809823422144251313032973397899), SC_(0.4301265203055088083605755042771532591535),
SC_(0.4247039729774556002468140098011553543390), SC_(0.4170685797734672711167804755454067582755), SC_(0.4072279949807128989552790124633945783765), SC_(0.3952085134465309348696666123753181072022),
SC_(0.3810550980268886849843356923521907577982), SC_(0.3648312306136669944635769493587219791343), SC_(0.3466185870197064968846647990300282094299)
}};
const T tolerance { 128 * boost::math::tools::epsilon<T>() };
int n_val { 9 };
for(const T& ctrl: ctrl_data)
{
const T x_val { static_cast<T>(static_cast<T>(n_val) / 10) };
const T jn_val { boost::math::cyl_bessel_j(3, x_val) };
++n_val;
BOOST_CHECK_CLOSE_FRACTION(jn_val, ctrl, tolerance);
}
}
// More specific tests for Git-issue1292.
{
using local_ctrl_array_type = std::array<table_entry_type, std::size_t { UINT8_C(43) }>;
// Table[N[BesselJ[31 / 10, n/10], 40], {n, 9, 51, 1}]
static const local_ctrl_array_type ctrl_data =
{{
SC_(0.01175139795214295170487105485346781171863), SC_(0.01610092560641321584451701371378836908343), SC_(0.02135659148701787280713314897691402425560), SC_(0.02757316602094671775387912184375438913864),
SC_(0.03479372470942323424236519547108889796879), SC_(0.04304884612770317349181083608393216357649), SC_(0.05235595486839477302545989170267853515412), SC_(0.06271881444009116864560457340917173135492),
SC_(0.07412717428914531462554459978389560408816), SC_(0.08655657401374878955779092959288219537482), SC_(0.09996830657138141192006478769855556316995), SC_(0.1143095409011066041623799431143340837007),
SC_(0.1295136029333754366226206053365805922136), SC_(0.1455004124749064242445094865982308151833), SC_(0.1621770719619318324763655518038365467780), SC_(0.1794386015949089605595848208470049166853),
SC_(0.1971688139222575484595939469080319406355), SC_(0.2152413195483352761119610246805962611319), SC_(0.2335206543185642795903443565627832597552), SC_(0.2518635170977563283446184976264924077045),
SC_(0.2701201061202457234361463802484836927464), SC_(0.2881355408650536940851830262098172944660), SC_(0.3057513555072237123913927136839853900197), SC_(0.3228070492275195774383850177821175151772),
SC_(0.3391416780352496831991017115498371039332), SC_(0.3545954722799571667706920253581728149226), SC_(0.3690114637024459111815176585531943143085), SC_(0.3822371057078773326211699424651752096338),
SC_(0.3941258705356621024731438508712990073773), SC_(0.4045388071531719615179931506197074798366), SC_(0.4133460440118967760814988295083688541739), SC_(0.4204282212729730452147271372029342292548),
SC_(0.4256778377298582292448895379334671298297), SC_(0.4290004984236535775073755577697874033289), SC_(0.4303160498540635572666996674883665298558), SC_(0.4295595907277138677145484170304736319185),
SC_(0.4266823473457215250850626209433240464185), SC_(0.4216524040030023831246842156638018726147), SC_(0.4144552801406973126588418824207056743782), SC_(0.4050943474472003316564108983454900189419),
SC_(0.3935910816286283019261303507307813773886), SC_(0.3799851451515116989978414766085547417497), SC_(0.3643342988837623802358278078893847672838)
}};
const T tolerance { 128 * boost::math::tools::epsilon<T>() };
const T vu_val { static_cast<T>(static_cast<T>(31) / 10) };
int n_val { 9 };
for(const T& ctrl : ctrl_data)
{
const T x_val { static_cast<T>(static_cast<T>(n_val) / 10) };
const T jn_val { boost::math::cyl_bessel_j(vu_val, x_val) };
++n_val;
BOOST_CHECK_CLOSE_FRACTION(jn_val, ctrl, tolerance);
}
}
BOOST_CHECK_EQUAL(boost::math::sph_bessel(0, T(0)), T(1));
BOOST_CHECK_EQUAL(boost::math::sph_bessel(1, T(0)), T(0));
BOOST_CHECK_EQUAL(boost::math::sph_bessel(100000, T(0)), T(0));

View File

@@ -174,6 +174,20 @@ void test_erf(T, const char* name)
do_test_erfc_inv<T>(erfc_inv_big_data, name, "Inverse Erfc Function: extreme values");
}
BOOST_CHECK_EQUAL(boost::math::erf(T(0)), T(0));
BOOST_CHECK_EQUAL(boost::math::erfc(T(0)), T(1));
BOOST_CHECK(boost::math::erf(boost::math::tools::root_epsilon<T>() / 8) > T(0));
BOOST_CHECK(boost::math::erf(boost::math::tools::epsilon<T>() / 32) >= T(0));
BOOST_CHECK(boost::math::erfc(boost::math::tools::epsilon<T>() / 32) <= T(1));
const bool has_negative_zero { ((boost::math::signbit)(-T(0)) != 0) };
if(has_negative_zero)
{
BOOST_CHECK_EQUAL(boost::math::erf(-T(0)), -T(0));
}
BOOST_IF_CONSTEXPR(std::numeric_limits<T>::has_quiet_NaN)
{
BOOST_CHECK_THROW(boost::math::erf(std::numeric_limits<T>::quiet_NaN()), std::domain_error);

View File

@@ -6,37 +6,11 @@
*/
#ifndef TEST_FUNCTIONS_FOR_OPTIMIZATION_HPP
#define TEST_FUNCTIONS_FOR_OPTIMIZATION_HPP
#include <boost/math/constants/constants.hpp>
#include <array>
#include <vector>
#include <boost/math/constants/constants.hpp>
#if __has_include(<boost/units/systems/si/length.hpp>)
// This is the only system boost.units still works on.
// I imagine this will start to fail at some point,
// and we'll have to remove this test as well.
#if defined(__APPLE__)
#define BOOST_MATH_TEST_UNITS_COMPATIBILITY 1
#include <boost/units/systems/si/length.hpp>
#include <boost/units/systems/si/area.hpp>
#include <boost/units/cmath.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/io.hpp>
using namespace boost::units;
using namespace boost::units::si;
// This *should* return an area, but see: https://github.com/boostorg/units/issues/58
// This sadly prevents std::atomic<quantity<area>>.
// Nonetheless, we *do* get some information making the argument type dimensioned,
// even if it would be better to get the full information:
double dimensioned_sphere(std::vector<quantity<length>> const & v) {
quantity<area> r(0.0*meters*meters);
for (auto const & x : v) {
r += (x * x);
}
quantity<area> scale(1.0*meters*meters);
return static_cast<double>(r/scale);
}
#endif
#endif
// Taken from: https://en.wikipedia.org/wiki/Test_functions_for_optimization
template <typename Real> Real ackley(std::array<Real, 2> const &v) {
@@ -52,10 +26,10 @@ template <typename Real> Real ackley(std::array<Real, 2> const &v) {
return -20 * exp(arg1) - exp(arg2 / 2) + 20 + e<Real>();
}
template <typename Real> auto rosenbrock_saddle(std::array<Real, 2> const &v) {
auto x = v[0];
auto y = v[1];
return 100 * (x * x - y) * (x * x - y) + (1 - x) * (1 - x);
template <typename Real> auto rosenbrock_saddle(std::array<Real, 2> const &v) -> Real {
Real x { v[0] };
Real y { v[1] };
return static_cast<Real>(100 * (x * x - y) * (x * x - y) + (1 - x) * (1 - x));
}