mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-15 16:42:12 -05:00
79 lines
47 KiB
C++
79 lines
47 KiB
C++
|
// Copyright John Maddock 2014
|
||
|
// 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_MATH_OVERFLOW_ERROR_POLICY ignore_error
|
||
|
|
||
|
#include <boost/math/concepts/real_concept.hpp>
|
||
|
#include <boost/math/special_functions/math_fwd.hpp>
|
||
|
#define BOOST_TEST_MAIN
|
||
|
#include <boost/test/unit_test.hpp>
|
||
|
#include <boost/test/floating_point_comparison.hpp>
|
||
|
#include <boost/math/tools/stats.hpp>
|
||
|
#include <boost/math/tools/test.hpp>
|
||
|
#include <boost/math/constants/constants.hpp>
|
||
|
#include <boost/type_traits/is_floating_point.hpp>
|
||
|
#include <boost/array.hpp>
|
||
|
#include "functor.hpp"
|
||
|
|
||
|
#include "handle_test_result.hpp"
|
||
|
#include "table_type.hpp"
|
||
|
|
||
|
#ifndef SC_
|
||
|
#ifndef BOOST_FLOAT128_C
|
||
|
#define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
|
||
|
#else
|
||
|
#define SC_(x) static_cast<typename table_type<T>::type>(BOOST_FLOAT128_C(x))
|
||
|
#endif
|
||
|
#endif
|
||
|
|
||
|
template <class Real, class T>
|
||
|
void do_test_trigamma(const T& data, const char* type_name, const char* test_name)
|
||
|
{
|
||
|
#if !(defined(ERROR_REPORTING_MODE) && !defined(TRIGAMMA_RATIO_FUNCTION_TO_TEST))
|
||
|
typedef Real value_type;
|
||
|
|
||
|
typedef value_type(*pg)(value_type);
|
||
|
#ifdef TRIGAMMA_RATIO_FUNCTION_TO_TEST
|
||
|
pg funcp = TRIGAMMA_RATIO_FUNCTION_TO_TEST;
|
||
|
#elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
|
||
|
pg funcp = boost::math::trigamma<value_type>;
|
||
|
#else
|
||
|
pg funcp = boost::math::trigamma;
|
||
|
#endif
|
||
|
|
||
|
boost::math::tools::test_result<value_type> result;
|
||
|
|
||
|
std::cout << "Testing " << test_name << " with type " << type_name
|
||
|
<< "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
|
||
|
|
||
|
//
|
||
|
// test trigamma against data:
|
||
|
//
|
||
|
result = boost::math::tools::test_hetero<Real>(
|
||
|
data,
|
||
|
bind_func<Real>(funcp, 0),
|
||
|
extract_result<Real>(1));
|
||
|
handle_test_result(result, data[result.worst()], result.worst(), type_name, "trigamma", test_name);
|
||
|
std::cout << std::endl;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
template <class T>
|
||
|
void test_trigamma(T, const char* name)
|
||
|
{
|
||
|
typedef typename table_type<T>::type value_type;
|
||
|
|
||
|
boost::array<boost::array<value_type, 3>, 659> data =
|
||
|
{ {
|
||
|
{ SC_(1.0), SC_(1.6449340668482264364724151666460252) }, { SC_(2.0), SC_(0.64493406684822643647241516664602519) }, { SC_(3.0), SC_(0.39493406684822643647241516664602519) }, { SC_(4.0), SC_(0.28382295573711532536130405553491408) }, { SC_(5.0), SC_(0.22132295573711532536130405553491408) }, { SC_(6.0), SC_(0.18132295573711532536130405553491408) }, { SC_(7.0), SC_(0.15354517795933754758352627775713630) }, { SC_(8.0), SC_(0.13313701469403142513454668592040161) }, { SC_(9.0), SC_(0.11751201469403142513454668592040161) }, { SC_(10.0), SC_(0.10516633568168574612220100690805593) }, { SC_(11.0), SC_(0.095166335681685746122201006908055927) }, { SC_(12.0), SC_(0.086901872871768390750300180461774936) }, { SC_(13.0), SC_(0.079957428427323946305855736017330491) }, { SC_(14.0), SC_(0.074040268664010336838400114715555343) }, { SC_(15.0), SC_(0.068938227847683806226155216756371670) }, { SC_(16.0), SC_(0.064493783403239361781710772311927225) }, { SC_(17.0), SC_(0.060587533403239361781710772311927225) }, { SC_(18.0), SC_(0.057127325790782614376866481654487779) }, { SC_(19.0), SC_(0.054040906037696194623780061901401359) }, { SC_(20.0), SC_(0.051270822935203119831536294588381969) }, { SC_(21.0), SC_(0.048770822935203119831536294588381969) }, { SC_(22.0), SC_(0.046503249239057995114983006606522558) }, { SC_(23.0), SC_(0.044437133536578656272007799994952310) }, { SC_(24.0), SC_(0.042546774368336690298472828350339834) }, { SC_(25.0), SC_(0.040810663257225579187361717239228723) }, { SC_(26.0), SC_(0.039210663257225579187361717239228723) }, { SC_(27.0), SC_(0.037731373316397176820497811913784936) }, { SC_(28.0), SC_(0.036359631203914323596903847579079860) }, { SC_(29.0), SC_(0.035084120999832690943842623089283942) }, { SC_(30.0), SC_(0.033895060357739944213759388844337450) }, { SC_(31.0), SC_(0.032783949246628833102648277733226339) }, { SC_(32.0), SC_(0.031743366520302090126581680438741427) }, { SC_(33.0), SC_(0.030766804020302090126581680438741427) }, { SC_(34.0), SC_(0.029848530374755717307481588611376873) }, { SC_(35.0), SC_(0.028983478471641530456270515947017011) }, { SC_(36.0), SC_(0.028167151941029285558311332273547623) }, { SC_(37.0), SC_(0.027395547002757680620039727335276018) }, { SC_(38.0), SC_(0.026665086812838031240930888766977990) }, { SC_(39.0), SC_(0.025972566037214762542869946938723143) }, { SC_(40.0), SC_(0.025315103841291028157597100127414793) }, { SC_(41.0), SC_(0.024690103841291028157597100127414793) }, { SC_(42.0), SC_(0.024095219843670564148078956165487369) }, { SC_(43.0), SC_(0.023528326419634282968940634170022516) }, { SC_(44.0), SC_(0.022987493536995018501661023569698017) }, { SC_(45.0), SC_(0.022470964611375183790917221916805455) }, { SC_(46.0), SC_(0.021977137450881356630423394756311627) }, { SC_(47.0), SC_(0.021504547658820865137039651845158508) }, { SC_(48.0), SC_(0.021051854132338293837809230840178880) }, { SC_(49.0), SC_(0.020617826354560516060031453062401102) }, { SC_(50.0), SC_(0.020201333226697125805970645065733047) }, { SC_(51.0), SC_(0.019801333226697125805970645065733047) }, { SC_(52.0), SC_(0.019416865714201931649876834992684219) }, { SC_(53.0), SC_(0.019047043228994831058160858661323273) }, { SC_(54.0), SC_(0.018691044652989135080944767525687815) }, { SC_(55.0), SC_(0.018348109124868421775046276442011546) }, { SC_(56.0), SC_(0.018017530612471727560170243384160307) }, { SC_(57.0), SC_(0.017698653061451319396904937261711327) }, { SC_(58.0), SC_(0.017390866050063199975544518671375839) }, { SC_(59.0), SC_(0.017093600889540013293023710110139216) }, { SC_(60.0), SC_(0.016806327117635388185296045645904801) }, { SC_(61.0), SC_(0.016528549339857610407518267868127023) }, { SC_(62.0), SC_(0.016259804378825629757155462170733849) }, { SC_(63.0), SC_(0.015999658697243944013138812847112621) }, { SC_(64.0), SC_(0.015747706064338930155744003071350465) }, { SC_(65.0), SC_(0.015503565439338930155744003071350465) }, { SC_(66.0), SC_(0.015266879048806385777045778219279459) }, { SC_(67.0), SC_(0.015037310637419792572270755262438320) }, { SC_(68.0), SC_(0.014814543874220861852734110129892096) }, { SC_(69.0), SC_(0.0145982808
|
||
|
{ SC_(0.25000000000000000000000000000000000), SC_(17.197329154507110739271319119335224)}, { SC_(0.12500000000000000000000000000000000), SC_(65.388133444988034473142999334395961) }, { SC_(0.062500000000000000000000000000000000), SC_(257.50642004291541426394984152786018) }, { SC_(0.031250000000000000000000000000000000), SC_(1025.5728544782377088851896549789956) }, { SC_(0.015625000000000000000000000000000000), SC_(4097.6081469812325471140472931934309) }, { SC_(0.0078125000000000000000000000000000000), SC_(16385.626348148031663597978251925972) }, { SC_(0.0039062500000000000000000000000000000), SC_(65537.635592296074077546680509110271) }, { SC_(0.0019531250000000000000000000000000000), SC_(262145.64025088744769438583827382756) }, { SC_(0.00097656250000000000000000000000000000), SC_(1.0485776425893921526170408061678298e6) }, { SC_(0.00048828125000000000000000000000000000), SC_(4.1943056437609568090690403869475364e6) }, { SC_(0.00024414062500000000000000000000000000), SC_(1.6777217644347318475117100572465400e7) }, { SC_(0.00012207031250000000000000000000000000), SC_(6.7108865644640644300678883695523690e7) }, { SC_(0.000061035156250000000000000000000000000), SC_(2.6843545764478734348137667988052034e8) }, { SC_(0.000030517578125000000000000000000000000), SC_(1.0737418256448607021411790006489757e9) }, { SC_(0.000015258789062500000000000000000000000), SC_(4.2949672976448973837387528780800407e9) }, { SC_(7.6293945312500000000000000000000000e-6), SC_(1.7179869185644915725104496671656842e10) }, { SC_(3.8146972656250000000000000000000000e-6), SC_(6.8719476737644924895929112616949761e10) }, { SC_(1.9073486328125000000000000000000000e-6), SC_(2.7487790694564492948137685720609220e11) }, { SC_(9.5367431640625000000000000000000000e-7), SC_(1.0995116277776449317741095887303350e12) }, { SC_(4.7683715820312500000000000000000000e-7), SC_(4.3980465111056449329204781693093178e12) }, { SC_(2.3841857910156250000000000000000000e-7), SC_(1.7592186044417644933493663013304205e13) }, { SC_(1.1920928955078125000000000000000000e-7), SC_(7.0368744177665644933780255573728145e13) }, { SC_(5.9604644775390625000000000000000000e-8), SC_(2.8147497671065764493392355188854676e14) }, { SC_(2.9802322387695312500000000000000000e-8), SC_(1.1258999068426256449339952000546077e15) }, { SC_(1.4901161193847656250000000000000000e-8), SC_(4.5035996273704976449340310241398011e15) }, { SC_(7.4505805969238281250000000000000000e-9), SC_(1.8014398509481985644934048936182939e16) }, { SC_(3.7252902984619140625000000000000000e-9), SC_(7.2057594037927937644934057892204642e16) }, { SC_(1.8626451492309570312500000000000000e-9), SC_(2.8823037615171174564493406237021553e17) }, { SC_(9.3132257461547851562500000000000000e-10), SC_(1.1529215046068469776449340646092210e18) }, { SC_(4.6566128730773925781250000000000000e-10), SC_(4.6116860184273879056449340657287237e18) }, { SC_(2.3283064365386962890625000000000000e-10), SC_(1.8446744073709551617644934066288475e19) }, { SC_(1.1641532182693481445312500000000000e-10), SC_(7.3786976294838206465644934066568351e19) }, { SC_(5.8207660913467407226562500000000000e-11), SC_(2.9514790517935282585764493406670829e20) }, { SC_(2.9103830456733703613281250000000000e-11), SC_(1.1805916207174113034256449340667783e21) }, { SC_(1.4551915228366851806640625000000000e-11), SC_(4.7223664828696452136976449340668132e21) }, { SC_(7.2759576141834259033203125000000000e-12), SC_(1.8889465931478580854785644934066831e22) }, { SC_(3.6379788070917129516601562500000000e-12), SC_(7.5557863725914323419137644934066839e22) }, { SC_(1.8189894035458564758300781250000000e-12), SC_(3.0223145490365729367654564493406684e23) }, { SC_(9.0949470177292823791503906250000000e-13), SC_(1.2089258196146291747061776449340668e24) }, { SC_(4.5474735088646411895751953125000000e-13), SC_(4.8357032784585166988247056449340668e24) }, { SC_(2.2737367544323205947875976562500000e-13), SC_(1.9342813113834066795298817644934067e25) }, { SC_(1.1368683772161602973937988281250000e-13), SC_(7.7371252455336267181195265644934067e25) }, { SC_(5.6843418860808014869689941406250000e-14), SC_(3.09485009821345068
|
||
|
{ SC_(-0.5000000000), SC_(8.9348022005446793094172454999380756) }, { SC_(-1.500000000), SC_(9.3792466449891237538616899443825200) }, { SC_(-2.500000000), SC_(9.5392466449891237538616899443825200) }, { SC_(-3.500000000), SC_(9.6208792980503482436576083117294588) }, { SC_(-4.500000000), SC_(9.6702620140997309597069910277788415) }, { SC_(-5.500000000), SC_(9.7033198653394003811945943335639655) }, { SC_(-6.500000000), SC_(9.7269885043926548190644168187710661) }, { SC_(-7.500000000), SC_(9.7447662821704325968421945965488438) }, { SC_(-8.500000000), SC_(9.7586071126202595864615717591786016) }, { SC_(-9.500000000), SC_(9.7696874450302318856305468284306792) }, { SC_(-10.50000000), SC_(9.7787577398148123844967599803581168) }, { SC_(-11.50000000), SC_(9.7863191764877802483908998669365667) }, { SC_(-12.50000000), SC_(9.7927191764877802483908998669365667) }, { SC_(-13.50000000), SC_(9.7982061449377116612852757242753870) }, { SC_(-14.50000000), SC_(9.8029623875060826482056086612551730) }, { SC_(-15.50000000), SC_(9.8071247184113896201098750504331127) }, { SC_(-16.50000000), SC_(9.8107978129935751113862754177425709) }, { SC_(-17.50000000), SC_(9.8140631191160240909781121524364484) }, { SC_(-18.50000000), SC_(9.8169849598757026884945475067096405) }, { SC_(-19.50000000), SC_(9.8196148086593976260356388939548739) },
|
||
|
{ SC_(-0.99902343750000000000000000000000000), SC_(1.0485786445453819054093666757806164e6) }, { SC_(-1.9990234375000000000000000000000000), SC_(1.0485788947897014608301106052600290e6) }, { SC_(-2.9990234375000000000000000000000000), SC_(1.0485790059731858715118158380121717e6) }, { SC_(-3.9990234375000000000000000000000000), SC_(1.0485790685037146291468005792240191e6) }, { SC_(-4.9990234375000000000000000000000000), SC_(1.0485791085193442079759033312640482e6) }, { SC_(-5.9990234375000000000000000000000000), SC_(1.0485791363061664391826604906353499e6) }, { SC_(-6.9990234375000000000000000000000000), SC_(1.0485791567200251382893770121774963e6) }, { SC_(-7.9990234375000000000000000000000000), SC_(1.0485791723488405341606371612842196e6) }, { SC_(-8.9990234375000000000000000000000000), SC_(1.0485791846971991664479297252200281e6) }, { SC_(-9.9990234375000000000000000000000000), SC_(1.0485791946991525775874820980861239e6) }, { SC_(-10.999023437500000000000000000000000), SC_(1.0485792029650829946601990955306663e6) }, { SC_(-11.999023437500000000000000000000000), SC_(1.0485792099106578577646272234105154e6) }, { SC_(-12.999023437500000000000000000000000), SC_(1.0485792158287067176193079741367670e6) }, { SC_(-13.999023437500000000000000000000000), SC_(1.0485792209314593886753540118883170e6) }, { SC_(-14.999023437500000000000000000000000), SC_(1.0485792253764825933424418561922499e6) }, { SC_(-15.999023437500000000000000000000000), SC_(1.0485792292832094741599436510420027e6) }, { SC_(-16.999023437500000000000000000000000), SC_(1.0485792327438146631093348182751076e6) }, { SC_(-17.999023437500000000000000000000000), SC_(1.0485792358305693414284737055180265e6) }, { SC_(-18.999023437500000000000000000000000), SC_(1.0485792386009372194851110066962854e6) }, { SC_(-19.999023437500000000000000000000000), SC_(1.0485792411011813779926686635901794e6) },
|
||
|
{ SC_(-1.0009765625000000000000000000000000), SC_(1.0485786453346669585098368000725210e6)}, { SC_(-2.0009765625000000000000000000000000), SC_(1.0485788950907050310998538089289880e6) }, { SC_(-3.0009765625000000000000000000000000), SC_(1.0485790061295134851948027406034007e6) }, { SC_(-4.0009765625000000000000000000000000), SC_(1.0485790685990070793038292171104670e6) }, { SC_(-5.0009765625000000000000000000000000), SC_(1.0485791085833866557487460417106589e6) }, { SC_(-6.0009765625000000000000000000000000), SC_(1.0485791363521243952566116253382220e6) }, { SC_(-7.0009765625000000000000000000000000), SC_(1.0485791567545946099550113256489222e6) }, { SC_(-8.0009765625000000000000000000000000), SC_(1.0485791723757806110676477942302156e6) }, { SC_(-9.0009765625000000000000000000000000), SC_(1.0485791847187808756018779739003157e6) }, { SC_(-10.000976562500000000000000000000000), SC_(1.0485791947168280366669245397313590e6) }, { SC_(-11.000976562500000000000000000000000), SC_(1.0485792029798236302523575048817360e6) }, { SC_(-12.000976562500000000000000000000000), SC_(1.0485792099231379319842508274674963e6) }, { SC_(-13.000976562500000000000000000000000), SC_(1.0485792158394087991015231685011609e6) }, { SC_(-14.000976562500000000000000000000000), SC_(1.0485792209407379096480891892744762e6) }, { SC_(-15.000976562500000000000000000000000), SC_(1.0485792253846037068979581619480639e6) }, { SC_(-16.000976562500000000000000000000000), SC_(1.0485792292903769133919482794005111e6) }, { SC_(-17.000976562500000000000000000000000), SC_(1.0485792327501870178663179616292787e6) }, { SC_(-18.000976562500000000000000000000000), SC_(1.0485792358362719002281530732844340e6) }, { SC_(-19.000976562500000000000000000000000), SC_(1.0485792386060702710649859237414384e6) }, { SC_(-20.000976562500000000000000000000000), SC_(1.0485792411058261483202152741904670e6) },
|
||
|
} };
|
||
|
do_test_trigamma<T>(data, name, "Mathematica Data");
|
||
|
}
|
||
|
|