1[section:high_precision Using Boost.Math with High-Precision Floating-Point Libraries] 2 3The special functions, distributions, constants and tools in this library 4can be used with a number of high-precision libraries, including: 5 6* __multiprecision 7* __e_float 8* __NTL 9* __GMP 10* __MPFR 11* __gcc_quad_type 12* Intel _Quad type 13 14The last four have some license restrictions; 15only __multiprecision when using the `cpp_float` backend 16can provide an unrestricted [@http://www.boost.org/LICENSE_1_0.txt Boost] license. 17 18At present, the price of a free license is slightly lower speed. 19 20Of course, the main cost of higher precision is very much decreased 21(usually at least hundred-fold) computation speed, and big increases in memory use. 22 23Some libraries offer true 24[@http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic arbitrary-precision arithmetic] 25where the precision is limited only by available memory and compute time, but most are used 26at some arbitrarily-fixed precision, say 100 decimal digits, like __multiprecision `cpp_dec_float_100`. 27 28__multiprecision can operate in both ways, but the most popular choice is likely to be about a hundred 29decimal digits, though examples of computing about a million digits have been demonstrated. 30 31[section:why_high_precision Why use a high-precision library rather than built-in floating-point types?] 32 33For nearly all applications, the built-in floating-point types, `double` 34(and `long double` if this offers higher precision than `double`) 35offer enough precision, typically a dozen decimal digits. 36 37Some reasons why one would want to use a higher precision: 38 39* A much more precise result (many more digits) is just a requirement. 40* The range of the computed value exceeds the range of the type: factorials are the textbook example. 41* Using `double` is (or may be) too inaccurate. 42* Using `long double` (or may be) is too inaccurate. 43* Using an extended-precision type implemented in software as 44[@http://en.wikipedia.org/wiki/Double-double_(arithmetic)#Double-double_arithmetic double-double] 45([@http://en.wikipedia.org/wiki/Darwin_(operating_system) Darwin]) is sometimes unpredictably inaccurate. 46* Loss of precision or inaccuracy caused by extreme arguments or 47[@http://en.wikipedia.org/wiki/Loss_of_significance cancellation errors]. 48* An accuracy as good as possible for a chosen built-in floating-point type is required. 49* As a reference value, for example, to determine the inaccuracy 50of a value computed with a built-in floating point type, 51(perhaps even using some quick'n'dirty algorithm). 52The accuracy of many functions and distributions in Boost.Math has been measured in this way 53from tables of very high precision (up to 1000 decimal digits). 54 55Many functions and distributions have differences from exact values 56that are only a few least significant bits - computation noise. 57Others, often those for which analytical solutions are not available, 58require approximations and iteration: 59these may lose several decimal digits of precision. 60 61Much larger loss of precision can occur for [@http://en.wikipedia.org/wiki/Boundary_case boundary] 62or [@http://en.wikipedia.org/wiki/Corner_case corner cases], 63often caused by [@http://en.wikipedia.org/wiki/Loss_of_significance cancellation errors]. 64 65(Some of the worst and most common examples of 66[@http://en.wikipedia.org/wiki/Loss_of_significance cancellation error or loss of significance] 67can be avoided by using __complements: see __why_complements). 68 69If you require a value which is as accurate as can be represented in the floating-point type, 70and is thus the 71[@https://en.wikipedia.org/wiki/Floating-point_arithmetic#Representable_numbers,_conversion_and_rounding closest representable value] 72correctly rounded to nearest, 73and has an error less than 1/2 a 74[@http://en.wikipedia.org/wiki/Least_significant_bit least significant bit] or 75[@http://en.wikipedia.org/wiki/Unit_in_the_last_place ulp] 76it may be useful to use a higher-precision type, 77for example, `cpp_dec_float_50`, to generate this value. 78Conversion of this value to a built-in floating-point type ('float', `double` or `long double`) 79will not cause any further loss of precision. 80A decimal digit string will also be 'read' precisely by the compiler 81into a built-in floating-point type to the nearest representable value. 82 83[note In contrast, reading a value from an `std::istream` into a built-in floating-point type 84is [*not guaranteed by the C++ Standard] to give the nearest representable value.] 85 86William Kahan coined the term 87[@http://en.wikipedia.org/wiki/Rounding#The_table-maker.27s_dilemma Table-Maker's Dilemma] 88for the problem of correctly rounding functions. 89Using a much higher precision (50 or 100 decimal digits) 90is a practical way of generating (almost always) correctly rounded values. 91 92[endsect] [/section:why_high_precision Why use a high-precision library rather than built-in floating-point types?] 93 94[section:use_multiprecision Using Boost.Multiprecision] 95 96[*All new projects are recommended to use __multiprecision.] 97 98[import ../../example/fft_sines_table.cpp] 99 100[fft_sines_table_example_1] 101[fft_sines_table_example_2] 102[fft_sines_table_example_3 103] 104 105The table output is: 106 107[fft_sines_table_example_output] 108 109[fft_sines_table_example_check] 110 111The full source of this example is at [@../../example/fft_sines_table.cpp fft_sines_table.cpp] 112 113[/TODO another example needed here] 114 115[/import ../../example/ibeta_mp_example.cpp] 116 117[/ibeta_mp_example_1] 118 119[/The program output is:] 120 121[/ibeta_mp_output_1] 122 123[endsect] [/section:use_multiprecision Using Boost.Multiprecision] 124 125[section:float128 Using with GCC's __float128 datatype] 126 127At present support for GCC's native `__float128` datatype is extremely limited: the numeric constants 128will all work with that type, and that's about it. If you want to use the distributions or special 129functions then you will need to provide your own wrapper header that: 130 131* Provides `std::numeric_limits<__float128>` support. 132* Provides overloads of the standard library math functions for type `__float128` 133and which forward to the libquadmath equivalents. 134 135Ultimately these facilities should be provided by GCC and `libstdc++`. 136 137[endsect] [/section:float128 Using with GCC's __float128 datatype] 138 139 140[section:use_mpfr Using With MPFR or GMP - High-Precision Floating-Point Library] 141 142The special functions and tools in this library can be used with 143[@http://www.mpfr.org MPFR] (an arbitrary precision number type based on the __GMP), 144either via the bindings in [@../../../../boost/math/bindings/mpfr.hpp boost/math/bindings/mpfr.hpp], 145or via [@../../../../boost/math/bindings/mpfr.hpp boost/math/bindings/mpreal.hpp]. 146 147[*New projects are recommended to use __multiprecision with GMP/MPFR backend instead.] 148 149In order to use these bindings you will need to have installed [@http://www.mpfr.org MPFR] 150plus its dependency the [@http://gmplib.org GMP library]. You will also need one of the 151two supported C++ wrappers for MPFR: 152[@http://math.berkeley.edu/~wilken/code/gmpfrxx/ gmpfrxx (or mpfr_class)], 153or [@http://www.holoborodko.com/pavel/mpfr/ mpfr-C++ (mpreal)]. 154 155Unfortunately neither `mpfr_class` nor `mpreal` quite satisfy our conceptual requirements, 156so there is a very thin set of additional interfaces and some helper traits defined in 157[@../../../../boost/math/bindings/mpfr.hpp boost/math/bindings/mpfr.hpp] and 158[@../../../../boost/math/bindings/mpreal.hpp boost/math/bindings/mpreal.hpp] 159that you should use in place of including 'gmpfrxx.h' or 'mpreal.h' directly. 160The classes `mpfr_class` or `mpreal` are 161then usable unchanged once this header is included, so for example `mpfr_class`'s 162performance-enhancing expression templates are preserved and fully supported by this library: 163 164 #include <boost/math/bindings/mpfr.hpp> 165 #include <boost/math/special_functions/gamma.hpp> 166 167 int main() 168 { 169 mpfr_class::set_dprec(500); // 500 bit precision 170 // 171 // Note that the argument to tgamma is 172 // an expression template - that's just fine here. 173 // 174 mpfr_class v = boost::math::tgamma(sqrt(mpfr_class(2))); 175 std::cout << std::setprecision(50) << v << std::endl; 176 } 177 178Alternatively use with `mpreal` would look like: 179 180 #include <boost/math/bindings/mpreal.hpp> 181 #include <boost/math/special_functions/gamma.hpp> 182 183 int main() 184 { 185 mpfr::mpreal::set_precision(500); // 500 bit precision 186 mpfr::mpreal v = boost::math::tgamma(sqrt(mpfr::mpreal(2))); 187 std::cout << std::setprecision(50) << v << std::endl; 188 } 189 190There is a concept checking test program for mpfr support 191[@../../../../libs/math/test/mpfr_concept_check.cpp here] and 192[@../../../../libs/math/test/mpreal_concept_check.cpp here]. 193 194[endsect] [/section:use_mpfr Using With MPFR / GMP - a High-Precision Floating-Point Library] 195 196[section:e_float Using e_float Library] 197 198__multiprecision was a development from the __e_float library by Christopher Kormanyos. 199 200e_float can still be used with Boost.Math library via the header: 201 202 <boost/math/bindings/e_float.hpp> 203 204And the type `boost::math::ef::e_float`: 205this type is a thin wrapper class around ::e_float which provides the necessary 206syntactic sugar to make everything "just work". 207 208There is also a concept checking test program for e_float support 209[@../../../../libs/math/test/e_float_concept_check.cpp here]. 210 211[*New projects are recommended to use __multiprecision with `cpp_float` backend instead.] 212 213[endsect] [/section:e_float Using e_float Library] 214 215[section:use_ntl Using NTL Library] 216 217[@http://shoup.net/ntl/doc/RR.txt NTL::RR] 218(an arbitrarily-fixed precision floating-point number type), 219can be used via the bindings in 220[@../../../../boost/math/bindings/rr.hpp boost/math/bindings/rr.hpp]. 221For details, see [@http://shoup.net/ntl/ NTL: A Library for doing Number Theory by 222Victor Shoup]. 223 224[*New projects are recommended to use __multiprecision instead.] 225 226Unfortunately `NTL::RR` doesn't quite satisfy our conceptual requirements, 227so there is a very thin wrapper class `boost::math::ntl::RR` defined in 228[@../../../../boost/math/bindings/rr.hpp boost/math/bindings/rr.hpp] that you 229should use in place of `NTL::RR`. The class is intended to be a drop-in 230replacement for the "real" NTL::RR that adds some syntactic sugar to keep 231this library happy, plus some of the standard library functions not implemented 232in NTL. 233 234For those functions that are based upon the __lanczos, the bindings 235defines a series of approximations with up to 61 terms and accuracy 236up to approximately 3e-113. This therefore sets the upper limit for accuracy 237to the majority of functions defined this library when used with `NTL::RR`. 238 239There is a concept checking test program for NTL support 240[@../../../../libs/math/test/ntl_concept_check.cpp here]. 241 242[endsect] [/section:use_ntl Using With NTL - a High-Precision Floating-Point Library] 243 244[section:using_test Using without expression templates for Boost.Test and others] 245 246As noted in the __multiprecision documentation, certain program constructs will not compile 247when using expression templates. One example that many users may encounter 248is Boost.Test (1.54 and earlier) when using macro BOOST_CHECK_CLOSE and BOOST_CHECK_CLOSE_FRACTION. 249 250If, for example, you wish to use any multiprecision type like `cpp_dec_float_50` 251in place of `double` to give more precision, 252you will need to override the default `boost::multiprecision::et_on` with 253`boost::multiprecision::et_off`. 254 255[import ../../example/test_cpp_float_close_fraction.cpp] 256 257[expression_template_1] 258 259A full example code is at [@../../example/test_cpp_float_close_fraction.cpp test_cpp_float_close_fraction.cpp] 260 261[endsect] [/section:using_test Using without expression templates for Boost.Test and others] 262[endsect] [/section:high_precision Using With High-Precision Floating-Point Libraries] 263 264[section:real_concepts Conceptual Requirements for Real Number Types] 265 266The functions and statistical distributions in this library can be used with 267any type ['RealType] that meets the conceptual requirements given below. All 268the built-in floating-point types like `double` will meet these requirements. 269(Built-in types are also called __fundamental_types). 270 271User-defined types that meet the conceptual requirements can also be used. 272For example, with [link math_toolkit.high_precision.use_ntl a thin wrapper class] 273one of the types provided with [@http://shoup.net/ntl/ NTL (RR)] can be used. 274But now that __multiprecision library is available, 275this has become the preferred real-number type, 276typically __cpp_dec_float or __cpp_bin_float. 277 278Submissions of binding to other extended precision types would also still be welcome. 279 280The guiding principal behind these requirements is that a ['RealType] 281behaves just like a built-in floating-point type. 282 283[h4 Basic Arithmetic Requirements] 284 285These requirements are common to all of the functions in this library. 286 287In the following table /r/ is an object of type `RealType`, /cr/ and 288/cr2/ are objects 289of type `const RealType`, and /ca/ is an object of type `const arithmetic-type` 290(arithmetic types include all the built in integers and floating point types). 291 292[table 293[[Expression][Result Type][Notes]] 294[[`RealType(cr)`][RealType] 295 [RealType is copy constructible.]] 296[[`RealType(ca)`][RealType] 297 [RealType is copy constructible from the arithmetic types.]] 298[[`r = cr`][RealType&][Assignment operator.]] 299[[`r = ca`][RealType&][Assignment operator from the arithmetic types.]] 300[[`r += cr`][RealType&][Adds cr to r.]] 301[[`r += ca`][RealType&][Adds ar to r.]] 302[[`r -= cr`][RealType&][Subtracts cr from r.]] 303[[`r -= ca`][RealType&][Subtracts ca from r.]] 304[[`r *= cr`][RealType&][Multiplies r by cr.]] 305[[`r *= ca`][RealType&][Multiplies r by ca.]] 306[[`r /= cr`][RealType&][Divides r by cr.]] 307[[`r /= ca`][RealType&][Divides r by ca.]] 308[[`-r`][RealType][Unary Negation.]] 309[[`+r`][RealType&][Identity Operation.]] 310[[`cr + cr2`][RealType][Binary Addition]] 311[[`cr + ca`][RealType][Binary Addition]] 312[[`ca + cr`][RealType][Binary Addition]] 313[[`cr - cr2`][RealType][Binary Subtraction]] 314[[`cr - ca`][RealType][Binary Subtraction]] 315[[`ca - cr`][RealType][Binary Subtraction]] 316[[`cr * cr2`][RealType][Binary Multiplication]] 317[[`cr * ca`][RealType][Binary Multiplication]] 318[[`ca * cr`][RealType][Binary Multiplication]] 319[[`cr / cr2`][RealType][Binary Subtraction]] 320[[`cr / ca`][RealType][Binary Subtraction]] 321[[`ca / cr`][RealType][Binary Subtraction]] 322[[`cr == cr2`][bool][Equality Comparison]] 323[[`cr == ca`][bool][Equality Comparison]] 324[[`ca == cr`][bool][Equality Comparison]] 325[[`cr != cr2`][bool][Inequality Comparison]] 326[[`cr != ca`][bool][Inequality Comparison]] 327[[`ca != cr`][bool][Inequality Comparison]] 328[[`cr <= cr2`][bool][Less than equal to.]] 329[[`cr <= ca`][bool][Less than equal to.]] 330[[`ca <= cr`][bool][Less than equal to.]] 331[[`cr >= cr2`][bool][Greater than equal to.]] 332[[`cr >= ca`][bool][Greater than equal to.]] 333[[`ca >= cr`][bool][Greater than equal to.]] 334[[`cr < cr2`][bool][Less than comparison.]] 335[[`cr < ca`][bool][Less than comparison.]] 336[[`ca < cr`][bool][Less than comparison.]] 337[[`cr > cr2`][bool][Greater than comparison.]] 338[[`cr > ca`][bool][Greater than comparison.]] 339[[`ca > cr`][bool][Greater than comparison.]] 340[[`boost::math::tools::digits<RealType>()`][int] 341 [The number of digits in the significand of RealType.]] 342[[`boost::math::tools::max_value<RealType>()`][RealType] 343 [The largest representable number by type RealType.]] 344[[`boost::math::tools::min_value<RealType>()`][RealType] 345 [The smallest representable number by type RealType.]] 346[[`boost::math::tools::log_max_value<RealType>()`][RealType] 347 [The natural logarithm of the largest representable number by type RealType.]] 348[[`boost::math::tools::log_min_value<RealType>()`][RealType] 349 [The natural logarithm of the smallest representable number by type RealType.]] 350[[`boost::math::tools::epsilon<RealType>()`][RealType] 351 [The machine epsilon of RealType.]] 352] 353 354Note that: 355 356# The functions `log_max_value` and `log_min_value` can be 357synthesised from the others, and so no explicit specialisation is required. 358# The function `epsilon` can be synthesised from the others, so no 359explicit specialisation is required provided the precision 360of RealType does not vary at runtime (see the header 361[@../../../../boost/math/bindings/rr.hpp boost/math/bindings/rr.hpp] 362for an example where the precision does vary at runtime). 363# The functions `digits`, `max_value` and `min_value`, all get synthesised 364automatically from `std::numeric_limits`. However, if `numeric_limits` 365is not specialised for type RealType, then you will get a compiler error 366when code tries to use these functions, /unless/ you explicitly specialise them. 367For example if the precision of RealType varies at runtime, then 368`numeric_limits` support may not be appropriate, see 369[@../../../../boost/math/bindings/rr.hpp boost/math/bindings/rr.hpp] for examples. 370 371[warning 372If `std::numeric_limits<>` is *not specialized* 373for type /RealType/ then the default float precision of 6 decimal digits 374will be used by other Boost programs including: 375 376Boost.Test: giving misleading error messages like 377 378['"difference between {9.79796} and {9.79796} exceeds 5.42101e-19%".] 379 380Boost.LexicalCast and Boost.Serialization when converting the number 381to a string, causing potentially serious loss of accuracy on output. 382 383Although it might seem obvious that RealType should require `std::numeric_limits` 384to be specialized, this is not sensible for 385`NTL::RR` and similar classes where the [*number of digits is a runtime parameter] 386(whereas for `numeric_limits` everything has to be fixed at compile time). 387] 388 389[h4 Standard Library Support Requirements] 390 391Many (though not all) of the functions in this library make calls 392to standard library functions, the following table summarises the 393requirements. Note that most of the functions in this library 394will only call a small subset of the functions listed here, so if in 395doubt whether a user-defined type has enough standard library 396support to be useable the best advise is to try it and see! 397 398In the following table /r/ is an object of type `RealType`, 399/cr1/ and /cr2/ are objects of type `const RealType`, and 400/i/ is an object of type `int`. 401 402[table 403[[Expression][Result Type]] 404[[`fabs(cr1)`][RealType]] 405[[`abs(cr1)`][RealType]] 406[[`ceil(cr1)`][RealType]] 407[[`floor(cr1)`][RealType]] 408[[`exp(cr1)`][RealType]] 409[[`pow(cr1, cr2)`][RealType]] 410[[`sqrt(cr1)`][RealType]] 411[[`log(cr1)`][RealType]] 412[[`frexp(cr1, &i)`][RealType]] 413[[`ldexp(cr1, i)`][RealType]] 414[[`cos(cr1)`][RealType]] 415[[`sin(cr1)`][RealType]] 416[[`asin(cr1)`][RealType]] 417[[`tan(cr1)`][RealType]] 418[[`atan(cr1)`][RealType]] 419[[`fmod(cr1)`][RealType]] 420[[`round(cr1)`][RealType]] 421[[`iround(cr1)`][int]] 422[[`trunc(cr1)`][RealType]] 423[[`itrunc(cr1)`][int]] 424] 425 426Note that the table above lists only those standard library functions known to 427be used (or likely to be used in the near future) by this library. 428The following functions: `acos`, `atan2`, `fmod`, `cosh`, `sinh`, `tanh`, `log10`, 429`lround`, `llround`, `ltrunc`, `lltrunc` and `modf` 430are not currently used, but may be if further special functions are added. 431 432Note that the `round`, `trunc` and `modf` functions are not part of the 433current C++ standard: they are part of the additions added to C99 which will 434likely be in the next C++ standard. There are Boost versions of these provided 435as a backup, and the functions are always called unqualified so that 436argument-dependent-lookup can take place. 437 438In addition, for efficient and accurate results, a __lanczos is highly desirable. 439You may be able to adapt an existing approximation from 440[@../../../../boost/math/special_functions/lanczos.hpp 441boost/math/special_functions/lanczos.hpp] or 442[@../../../../boost/math/bindings/detail/big_lanczos.hpp 443boost/math/bindings/detail/big_lanczos.hpp]: 444in the former case you will need change 445`static_cast`'s to `lexical_cast`'s, and the constants to /strings/ 446(in order to ensure the coefficients aren't truncated to `long double`) 447and then specialise `lanczos_traits` for type T. Otherwise you may have to hack 448[@../../tools/lanczos_generator.cpp 449libs/math/tools/lanczos_generator.cpp] to find a suitable 450approximation for your RealType. The code will still compile if you don't do 451this, but both accuracy and efficiency will be somewhat compromised in any 452function that makes use of the gamma\/beta\/erf family of functions. 453 454[endsect] [/section:real_concepts Conceptual Requirements for Real Number Types] 455 456[section:dist_concept Conceptual Requirements for Distribution Types] 457 458A ['DistributionType] is a type that implements the following conceptual 459requirements, and encapsulates a statistical distribution. 460 461Please note that this documentation should not be used as a substitute 462for the 463[link math_toolkit.dist_ref reference documentation], and 464[link math_toolkit.stat_tut tutorial] of the statistical 465distributions. 466 467In the following table, ['d] is an object of type `DistributionType`, 468['cd] is an object of type `const DistributionType` and ['cr] is an 469object of a type convertible to `RealType`. 470 471[table 472[[Expression][Result Type][Notes]] 473[[DistributionType::value_type][RealType] 474 [The real-number type /RealType/ upon which the distribution operates.]] 475[[DistributionType::policy_type][RealType] 476 [The __Policy to use when evaluating functions that depend on this distribution.]] 477[[d = cd][Distribution&][Distribution types are assignable.]] 478[[Distribution(cd)][Distribution][Distribution types are copy constructible.]] 479[[pdf(cd, cr)][RealType][Returns the PDF of the distribution.]] 480[[cdf(cd, cr)][RealType][Returns the CDF of the distribution.]] 481[[cdf(complement(cd, cr))][RealType] 482 [Returns the complement of the CDF of the distribution, 483 the same as: `1-cdf(cd, cr)`]] 484[[quantile(cd, cr)][RealType][Returns the quantile (or percentile) of the distribution.]] 485[[quantile(complement(cd, cr))][RealType] 486 [Returns the quantile (or percentile) of the distribution, starting from 487 the complement of the probability, the same as: `quantile(cd, 1-cr)`]] 488[[chf(cd, cr)][RealType][Returns the cumulative hazard function of the distribution.]] 489[[hazard(cd, cr)][RealType][Returns the hazard function of the distribution.]] 490[[kurtosis(cd)][RealType][Returns the kurtosis of the distribution.]] 491[[kurtosis_excess(cd)][RealType][Returns the kurtosis excess of the distribution.]] 492[[mean(cd)][RealType][Returns the mean of the distribution.]] 493[[mode(cd)][RealType][Returns the mode of the distribution.]] 494[[skewness(cd)][RealType][Returns the skewness of the distribution.]] 495[[standard_deviation(cd)][RealType][Returns the standard deviation of the distribution.]] 496[[variance(cd)][RealType][Returns the variance of the distribution.]] 497] 498 499[endsect] [/ section:dist_concept Conceptual Requirements for Distribution Types] 500 501[section:archetypes Conceptual Archetypes for Reals and Distributions] 502 503There are a few concept archetypes available: 504 505* Real concept for floating-point types. 506* Distribution concept for statistical distributions. 507 508[h5:real_concept Real concept] 509 510`std_real_concept` is an archetype for theReal types, 511including the built-in float, double, long double. 512 513``#include <boost/concepts/std_real_concept.hpp>`` 514 515 namespace boost{ 516 namespace math{ 517 namespace concepts 518 { 519 class std_real_concept; 520 } 521 }} // namespaces 522 523 524The main purpose in providing this type is to verify 525that standard library functions are found via a using declaration - 526bringing those functions into the current scope - 527and not just because they happen to be in global scope. 528 529In order to ensure that a call to say `pow` can be found 530either via argument dependent lookup, or failing that then 531in the std namespace: all calls to standard library functions 532are unqualified, with the std:: versions found via a `using` declaration 533to make them visible in the current scope. Unfortunately it's all 534to easy to forget the `using` declaration, and call the double version of 535the function that happens to be in the global scope by mistake. 536 537For example if the code calls ::pow rather than std::pow, 538the code will cleanly compile, but truncation of long doubles to 539double will cause a significant loss of precision. 540In contrast a template instantiated with std_real_concept will *only* 541compile if the all the standard library functions used have 542been brought into the current scope with a using declaration. 543 544[h6 Testing the real concept] 545 546There is a test program 547[@../../test/std_real_concept_check.cpp libs/math/test/std_real_concept_check.cpp] 548that instantiates every template in this library with type 549`std_real_concept` to verify its usage of standard library functions. 550 551``#include <boost/math/concepts/real_concept.hpp>`` 552 553 namespace boost{ 554 namespace math{ 555 namespace concepts{ 556 557 class real_concept; 558 559 }}} // namespaces 560 561`real_concept` is an archetype for 562[link math_toolkit.real_concepts user defined real types], 563it declares its standard library functions in its own 564namespace: these will only be found if they are called unqualified 565allowing argument dependent lookup to locate them. In addition 566this type is useable at runtime: 567this allows code that would not otherwise be exercised by the built-in 568floating point types to be tested. There is no std::numeric_limits<> 569support for this type, since numeric_limits is not a conceptual requirement 570for [link math_toolkit.real_concepts RealType]s. 571 572NTL RR is an example of a type meeting the requirements that this type 573models, but note that use of a thin wrapper class is required: refer to 574[link math_toolkit.high_precision.use_ntl "Using With NTL - a High-Precision Floating-Point Library"]. 575 576There is no specific test case for type `real_concept`, instead, since this 577type is usable at runtime, each individual test case as well as testing 578`float`, `double` and `long double`, also tests `real_concept`. 579 580[h6:distribution_concept Distribution Concept] 581 582Distribution Concept models statistical distributions. 583 584``#include <boost/math/concepts/distribution.hpp>`` 585 586 namespace boost{ 587 namespace math{ 588 namespace concepts 589 { 590 template <class RealType> 591 class distribution_archetype; 592 593 template <class Distribution> 594 struct DistributionConcept; 595 596 }}} // namespaces 597 598The class template `distribution_archetype` is a model of the 599[link math_toolkit.dist_concept Distribution concept]. 600 601The class template `DistributionConcept` is a 602[@../../../../libs/concept_check/index.html concept checking class] 603for distribution types. 604 605[h6 Testing the distribution concept] 606 607The test program 608[@../../test/compile_test/distribution_concept_check.cpp distribution_concept_check.cpp] 609is responsible for using `DistributionConcept` to verify that all the 610distributions in this library conform to the 611[link math_toolkit.dist_concept Distribution concept]. 612 613The class template `DistributionConcept` verifies the existence 614(but not proper function) of the non-member accessors 615required by the [link math_toolkit.dist_concept Distribution concept]. 616These are checked by calls like 617 618 v = pdf(dist, x); // (Result v is ignored). 619 620And in addition, those that accept two arguments do the right thing when the 621arguments are of different types (the result type is always the same as the 622distribution's value_type). (This is implemented by some additional 623forwarding-functions in derived_accessors.hpp, so that there is no need for 624any code changes. Likewise boilerplate versions of the 625hazard\/chf\/coefficient_of_variation functions are implemented in 626there too.) 627 628[endsect] [/section:archetypes Conceptual Archetypes for Reals and Distributions] 629[/ 630 Copyright 2006, 2010, 2012 John Maddock and Paul A. Bristow. 631 Distributed under the Boost Software License, Version 1.0. 632 (See accompanying file LICENSE_1_0.txt or copy at 633 http://www.boost.org/LICENSE_1_0.txt). 634] 635 636 637 638 639