diff --git a/.gitignore b/.gitignore index c4d01b6bc..353697756 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ reporting/*/third_party reporting/*/html inspect.html +/example/float128_examples.cpp diff --git a/doc/constants/constants.qbk b/doc/constants/constants.qbk index 466edb1fd..99db33659 100644 --- a/doc/constants/constants.qbk +++ b/doc/constants/constants.qbk @@ -1,5 +1,3 @@ - - [mathpart constants..Mathematical Constants] [section:constants_intro Introduction] diff --git a/doc/cstdfloat/cstdfloat.qbk b/doc/cstdfloat/cstdfloat.qbk index 1413a3aca..a5e0bb2b0 100644 --- a/doc/cstdfloat/cstdfloat.qbk +++ b/doc/cstdfloat/cstdfloat.qbk @@ -6,8 +6,9 @@ [import ../../example/cstdfloat_example.cpp] [import ../../example/normal_tables.cpp] +[import ../../example/quadmath_snprintf.c] -[section:overview Overview] +[section:specified_typedefs Overview] The header `` provides [*optional] standardized floating-point `typedef`s having [*specified widths]. @@ -25,11 +26,12 @@ The `typedef`s include `float16_t, float32_t, float64_t, float80_t, float128_t`, their corresponding least and fast types, and the corresponding maximum-width type. The `typedef`s are based on underlying built-in types -such as `float`, `double`, or `long double`, or based on other compiler-specific -non-standardized types such as `__float128`. +such as `float`, `double`, or `long double`, or the proposed __short_float, +or based on other compiler-specific non-standardized types such as `__float128`. The underlying types of these `typedef`s must conform with the corresponding specifications of binary16, binary32, binary64, -and binary128 in __IEEE754 floating-point format. +and binary128 in __IEEE754 floating-point format, and +`std::numeric_limits<>::is_iec559 == true`. The 128-bit floating-point type (of great interest in scientific and numeric programming) is not required in the Boost header, @@ -38,13 +40,13 @@ support for a 128-bit floating-point type is not mandated by either the C standard or the C++ standard. See [link math_toolkit.examples.je_lambda Jahnke-Emden-Lambda function example] -for an example using both a CMath function and a Boost.Math function +for an example using both a `` function and a Boost.Math function to evaluate a moderately interesting function, the [@http://mathworld.wolfram.com/LambdaFunction.html Jahnke-Emden-Lambda function] and [link math_toolkit.examples.normal_table normal distribution] -an example of a statistical distribution from Boost.Math +as an example of a statistical distribution from Boost.Math. -[endsect] [/section:overview Overview] +[endsect] [/section:specified_typedefs Overview] [section:rationale Rationale] @@ -53,7 +55,7 @@ defined in the 1989 C standard. The preprocessor is used to query certain preprocessor definitions in `` such as FLT_MAX, DBL_MAX, etc. Based on the results of these queries, an attempt is made to automatically detect the presence of built-in floating-point types having specified widths. -An unequivocal test regarding conformance with __IEEE754 (IEC599) based on +An unequivocal test requiring conformance with __IEEE754 (IEC599) based on [@ http://en.cppreference.com/w/cpp/types/numeric_limits/is_iec559 `std::numeric_limits<>::is_iec559`] is performed with `BOOST_STATIC_ASSERT`. @@ -62,7 +64,7 @@ supports an 80-bit floating-point `typedef` if it can be detected, and a 128-bit floating-point `typedef` if it can be detected, provided that the underlying types conform with [@http://en.wikipedia.org/wiki/Extended_precision IEEE-754 precision extension] -(if`std::numeric_limits<>::is_iec559` is true for this type). +(provided `std::numeric_limits<>::is_iec559 == true` for this type). The header `` makes the standardized floating-point `typedef`s safely available in `namespace boost` without placing any names @@ -109,7 +111,8 @@ standard library functions where a non-standard type (i.e. other than width types. If generic code (for example in another Boost.Math header) calls a standard library function, then the correct overload will only be found if these overloads are defined prior to the point of use. -See implementation for more details. +See [link math_toolkit.float128.overloading overloading template functions with float128_t] +and the implementation of `cstdfloat.hpp` for more details. For this reason, making `#include ` the [*first include] is usually best. @@ -137,37 +140,41 @@ and the corresponding maximum-width type. The definition (or not) of a [link math_toolkit.macros floating-point constant macro] -is the way to test if a specific width is available on a platform. +is a way to test if a [*specific width floating-point] is available on a platform. #if defined(BOOST_FLOAT16_C) - // Can use boost::float16_t. + // Can use boost::float16_t, perhaps a proposed __short_float. + // P0192R1, Adding Fundamental Type for Short Float, + // Boris Fomitchev, Sergei Nikolaev, Olivier Giroux, Lawrence Crowl, 2016 Feb14 + // http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2016.pdf #endif #if defined(BOOST_FLOAT32_C) - // Can use boost::float32_t. + // Can use boost::float32_t, usually type `float`. #endif #if defined(BOOST_FLOAT64_C) - // Can use boost::float64_t. + // Can use boost::float64_t, usually type `double`, and sometimes also type `long double`. #endif #if defined(BOOST_FLOAT80_C) - // Can use boost::float80_t. + // Can use boost::float80_t, sometimes type `long double`. #endif #if defined(BOOST_FLOAT128_C) - // Can use boost::float128_t. + // Can use boost::float128_t. Sometimes type `__float128` or `_Quad`. #endif This can be used to write code which will compile and run (albeit differently) on several platforms. Without these tests, if a width, say `float128_t` is not supported, then compilation would fail. -(It is of course, rare for `float64_t` or `float32_t` not to be supported). +(It is, of course, rare for `float64_t` or `float32_t` not to be supported). The number of bits in just the significand can be determined using: std::numeric_limits::digits and from this one can safely infer the total number of bits because the type must be IEEE754 format, +`std::numeric_limits::is_iec559 == true`, so, for example, if `std::numeric_limits::digits == 113`, then `floatmax_t` must be` float128_t`. @@ -184,15 +191,17 @@ and the maximum number of possibly significant decimal digits using std::numeric_limits::max_digits10 [tip `max_digits10` is not always supported, -but can be calculated at compile-time using the Kahan formula. +but can be calculated at compile-time using the Kahan formula, +`2 + binary_digits * 0.3010` which can be calculated [*at compile time] using +`2 + binary_digits * 3010/10000`. ] -[note One could test +[note One could test that std::is_same::value == true -but this would fail to compile on a platform where `boost::float128_t` is not defined. -So use the MACROs BOOST_FLOATnnn_C. ] +but this would fail to compile on a platform where `boost::float128_t` is not defined. +So it is better to use the MACROs `BOOST_FLOATnnn_C`. ] [endsect] [/section:exact_typdefs Exact-Width Floating-Point `typedef`s] @@ -235,8 +244,8 @@ any value of any floating-point type in a given platform most precisely. The greatest-width `typedef` is provided for all platforms, but, of course, the size may vary. -To provide floating-point [*constants] most precisely for a `floatmax_t` type, -use the macro BOOST_FLOATMAX_C. +To provide floating-point [*constants] most precisely representable for a `floatmax_t` type, +use the macro `BOOST_FLOATMAX_C`. For example, replace a constant `123.4567890123456789012345678901234567890` with @@ -244,13 +253,13 @@ For example, replace a constant `123.4567890123456789012345678901234567890` with If, for example, `floatmax_t` is `float64_t` then the result will be equivalent to a `long double` suffixed with L, but if `floatmax_t` is `float128_t` then the result will be equivalent to a `quad type` suffixed with Q -(assuming, of course, that `float128` is supported). +(assuming, of course, that `float128_t` (`__float128` or `Quad`) is supported). If we display with `max_digits10`, the maximum possibly significant decimal digits: [floatmax_widths_1] -then on a 128-bit platform (GCC 4.8.1. with quadmath): +then on a 128-bit platform (GCC 4.8.1 or higher with quadmath): [floatmax_widths_2] @@ -270,6 +279,8 @@ are always defined after inclusion of ``. from [@../../example/cstdfloat_example.cpp cstdfloat_example.cpp]. +See the complete list of __constants. + [endsect] [/section:macros Floating-Point Constant Macros] [section:examples Examples] @@ -301,9 +312,9 @@ For details, see [@../../example/cstdfloat_example.cpp cstdfloat_example.cpp] [h3:normal_table Normal distribution table] This example shows printing tables of a normal distribution's PDF and CDF, -using `boost::math` implmentation of normal. +using `boost::math` implementation of normal distribution. -A function templated on floating-point type prints a table for a range of z values. +A function templated on floating-point type prints a table for a range of standard variate z values. The example shows use of the specified-width typedefs to either use a specific width, or to use the maximum available on the platform, perhaps a high as 128-bit. @@ -321,15 +332,53 @@ Some sample output for two different platforms is appended to the code at [endsect] [/section:examples examples] +[section:float128_hints Hints on using float128 (and __float128)] + +[h5:different_float128 __float128 versus float128] +* __float128 is the compiler supplied hardware type, +it's an C-ish extension to C++ and there is only +minimal support for it in normal C++ +(no IO streams or `numeric_limits` support, +function names in libquadmath all have different names to the +`std::` ones etc.) +So you can program that type directly but it's harder work. + +* Type float128 is a thin wrapper around __float128 and makes it +C++ and generic code friendly. + +[h5 Hints and tips] + +* Make sure you declare variables with the correct type, here `float128`. +* Make sure that if you pass a variable to a function then it is casted to `float128`. +* Make sure you declare literals with the correct suffix - otherwise +they'll be treated as type `double` with catastrophic loss of precision. +So make sure they have a Q suffix for 128-bit floating-point literals. +* All the std library functions, cmath functions, plus all the constants, and special +functions from Boost.Math should then just work. +* Make sure std lib functions are called [*unqualified] so that the correct +overload is found via __ADL. So write + sqrt(variable) +and not + std::sqrt(variable). +* In general, try not to reinvent stuff - using constants from +Boost.Math is probably less error prone than declaring your own, +likewise the special functions etc. + +Some examples of what can go horribly and silently wrong are at [@../../example/float128_example.cpp float128_example.cpp]. + +[endsect] [/section:float128_hints Hints on using float128] + [section:float128 Implementation of Float128 type] -Since few compilers implement a true 128-bit floating-point, and language features like the suffix Q, +Since few compilers implement a true 128-bit floating-point, and language features like the suffix Q +(which may need an option `-fext-numeric-literals` to enable), and C++ Standard library functions are as-yet missing or incomplete in C++11, -this Boost.Math implementation wraps `__float128` provided by the GCC compiler or the `_Quad` type -provided by the Intel compiler. +this Boost.Math implementation wraps `__float128` provided by the GCC compiler +[@https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html GCC floating-point types] +or the `_Quad` type provided by the Intel compiler. This is provided to in order to demonstrate, and users to evaluate, the feasibility and benefits of higher-precision floating-point, -especially to allow use of the full Boost.Math library of functions and distributions at high precision. +especially to allow use of the full and Boost.Math library of functions and distributions at high precision. (It is also possible to use Boost.Math with Boost.Multiprecision decimal and binary, but since these are entirely software solutions, allowing much higher precision or arbitrary precision, they are likely to be slower). @@ -339,13 +388,25 @@ We also provide (we believe full) support for `, `, I/O stream op As a prototype for a future C++ standard, we place all these in `namespace std`. This contravenes the existing C++ standard of course, so selecting any compiler that promises to check conformance will fail. -[tip For GCC, compile with `-std=gnu++11` or `-std=gnu++03` and do not use `-std=stdc++11`or any 'strict' options as +[tip For GCC, compile with `-std=gnu++11` or `-std=gnu++03` and do not use `-std=stdc++11` or any 'strict' options, as these turn off full support for `__float128`. These requirements also apply to the Intel compiler on Linux, for Intel on Windows you need to compile with `-Qoption,cpp,--extended_float_type -DBOOST_MATH_USE_FLOAT128` in order to activate 128-bit floating point support.] The `__float128` type is provided by the [@http://gcc.gnu.org/onlinedocs/libquadmath/ libquadmath library] on GCC or -by Intel's FORTRAN library with Intel C++. +by Intel's FORTRAN library with Intel C++. THey also provide a full set of `` functions in `namespace std`. + +[h4 Using C __float128 quadmath type] + +[quadmath_snprintf_1] + +The source code is at [@../../example/quadmath_snprintf.c quadmath_snprintf.c]. + +[h4 Using C++ `float128` quadmath type] + +For C++ programs, you will want to use the C++ type `float128` + +See example at [@../../example/cstdfloat_example.cpp cstdfloat_example.cpp]. A typical invocation of the compiler is @@ -355,11 +416,33 @@ A typical invocation of the compiler is g++ -O3 -std=gnu++11 test.cpp -I/c/modular-boost/libs/math/include -I/c/modular-boost -lquadmath -o test.exe -[note So far, the only missing detail that we have noted is in trying to use ``, for example for -`std::cout << typeid<__float_128>.name();`. Link fails: undefined reference to `typeinfo for __float128`. -See [@http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622 GCC Bug 43622 - no C++ typeinfo for __float128].] +[note So far, the only missing detail that we had noted was in trying to use ``, +for example for `std::cout << typeid<__float_128>.name();`. +`` +Link fails: undefined reference to typeinfo for __float128. +`` +See [@http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622 GCC Bug 43622 - no C++ typeinfo for __float128]. +But this is reported (Marc Glisse 2015-04-04 ) fixed in GCC 5 (and above). -[section Overloading template functions with float128_t] +For example, with GCC6.1.1 this works as expected to a [*mangled] string name, and output (if possible - not always). +`` +const std::type_info& tifu128 = typeid(__float128); // OK. +//std::cout << tifu128.name() << std::endl; // On GCC, aborts (because not printable string). +//std::cout << typeid(__float128).name() << std::endl; // Aborts - string name cannot be output. + +const std::type_info& tif128 = typeid(float128); // OK. +std::cout << tif128.name() << std::endl; // OK. +std::cout << typeid(float128).name() << std::endl; // OK. + +const std::type_info& tpi = typeid(pi1); // OK GCC 6.1.1 (from GCC 5 according to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622) +std::cout << tpi.name() << std::endl; // Output mangled name: + +// N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE + +`` +] [/note] + +[section:overloading Overloading template functions with float128_t] An artifact of providing C++ standard library support for quadmath may mandate the inclusion of `` @@ -400,28 +483,31 @@ Boost.Math headers, then the compiler will know about and use the `std::fabs(std::float128_t)` that we provide in `#include `. - [endsect] [section:exp_function Exponential function] -There is a bug whe using any quadmath `expq` function on GCC: - +There was a bug when using any quadmath `expq` function on GCC : [@http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60349 GCC bug #60349] - -[@http://sourceforge.net/p/mingw-w64/bugs/368/ mingw-64 bug #368] +caused by +[@http://sourceforge.net/p/mingw-w64/bugs/368/ mingw-64 bug #368]. To work round this defect, an alternative implementation of 128-bit exp -is temporarily provided by `boost/cstdfloat.hpp`. +was temporarily provided by `boost/cstdfloat.hpp`. + +The mingw bug was fixed at 2014-03-12 and GCC 6.1.1 now works as expected. + +[tip It is essential to link to the quadmath library]. [endsect] [/section:exp_function exp function] [section:typeinfo `typeinfo`] -It is not yet possible to use `typeinfo` for float_128 on GCC: see -[@http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622 GCC 43622] +For GCC 4.8.1 it was not yet possible to use `typeinfo` for `float_128` on GCC: +see [@http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622 GCC 43622]. -so this fails to link `undefined reference to typeinfo for __float128` +So this code (to display the mangled name) +failed to link `undefined reference to typeinfo for __float128` std::cout << typeid(boost::float128_t).name() << std::endl; @@ -430,7 +516,10 @@ This prevent using the existing tests for Boost.Math distributions, and if a MACRO BOOST_MATH_INSTRUMENT controlling them is defined then some diagnostic displays in Boost.Math will not work. -However this is only used for display purposes and can be commented out until this is fixed. +However this was only used for display purposes +and could be commented out until this was fixed in GCC 5. + +[tip Not all managed names can be [*displayed] using `std::cout`.] [endsect] [/section:typeinfo `typeinfo`] diff --git a/doc/html/cstdfloat.html b/doc/html/cstdfloat.html index 617985a5a..94ed3bd03 100644 --- a/doc/html/cstdfloat.html +++ b/doc/html/cstdfloat.html @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@

-PrevUpHomeNext +PrevUpHomeNext
@@ -895,6 +899,10 @@
  • +

    epsilon_difference

    + +
  • +
  • erf

    A B C D E F G H I L N O P R S T U V W

    @@ -336,22 +336,13 @@
    S
    -
    T
    diff --git a/doc/html/indexes/s04.html b/doc/html/indexes/s04.html index c3ef0e623..1e8666e46 100644 --- a/doc/html/indexes/s04.html +++ b/doc/html/indexes/s04.html @@ -24,7 +24,7 @@

    -Macro Index

    +Macro Index

    B F

    diff --git a/doc/html/indexes/s05.html b/doc/html/indexes/s05.html index a2e96c338..9c0a71376 100644 --- a/doc/html/indexes/s05.html +++ b/doc/html/indexes/s05.html @@ -23,7 +23,7 @@

    -Index

    +Index

    2 4 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

    @@ -462,6 +462,7 @@
  • +

    bool

    + +
  • +
  • Boost.Math Macros

  • @@ -1578,6 +1583,10 @@
  • +

    Comparing the means of two samples with the Students-t test

    + +
  • +
  • Comparison of Cube Root Finding Algorithms

  • +

    Floating-point Comparison

    + +
  • +
  • Floating-Point Constant Macros

    • BOOST_FLOAT128_C

    • @@ -3779,15 +3800,7 @@
    • GCD Function Object

      - -
    • -
    • -

      gcd_evaluator

      - +
    • Generalizing to Compute the nth root

      @@ -3999,6 +4012,10 @@
    • +

      Hints on using float128 (and __float128)

      + +
    • +
    • History and What's New

      • 2

      • @@ -4242,6 +4259,13 @@
    • +

      Implementation of Float128 type

      + +
    • +
    • Incomplete Beta Function Inverses

      • 41

      • @@ -4358,6 +4382,7 @@
        • data

        • expression

        • +
        • less

        • performance

        • scale

        • variance

        • @@ -4726,15 +4751,7 @@
        • LCM Function Object

          - -
        • -
        • -

          lcm_evaluator

          - +
        • ldexp

          @@ -4791,6 +4808,13 @@
        • +

          less

          + +
        • +
        • lgamma

          • C99 and C++ TR1 C-style Functions

          • @@ -4818,7 +4842,7 @@
          • Library Comparison with Microsoft Visual C++ version 14.0 on Windows x64

            - +
          • llrint

            @@ -5077,6 +5101,10 @@
          • +

            message

            + +
          • +
          • Minimax Approximations and the Remez Algorithm

            • constants

            • @@ -5812,8 +5844,10 @@
            • Polynomials

              @@ -5866,6 +5900,10 @@
              • +

                quadmath_snprintf

                + +
              • +
              • quantile

                • Complements are supported too - and when to use them

                • @@ -6021,6 +6059,10 @@
                • +

                  relative_difference

                  + +
                • +
                • remainder

                  • C99 and C++ TR1 C-style Functions

                  • @@ -6319,13 +6361,6 @@
                  • -

                    second_argument_type

                    - -
                  • -
                  • semipolar

                    • Quaternion Creation Functions

                    • @@ -6379,6 +6414,10 @@
                    • +

                      set_zero

                      + +
                    • +
                    • shape

                      • Cauchy-Lorentz Distribution

                      • @@ -6504,6 +6543,7 @@
                      • +

                        strtoflt128

                        + +
                      • +
                      • Students t Distribution

                        • accuracy

                        • diff --git a/doc/html/math_toolkit/comp_compilers.html b/doc/html/math_toolkit/comp_compilers.html index bd3bd63f9..4d1efb70f 100644 --- a/doc/html/math_toolkit/comp_compilers.html +++ b/doc/html/math_toolkit/comp_compilers.html @@ -79,7 +79,7 @@

                          - 1.11
                          (199ns)
                          + 1.16
                          (208ns)

                          @@ -106,7 +106,7 @@

                          - 1.79
                          (172ns)
                          + 1.57
                          (151ns)

                          @@ -133,7 +133,7 @@

                          - 1.65
                          (167ns)
                          + 1.74
                          (176ns)

                          @@ -160,7 +160,7 @@

                          - 1.38
                          (501ns)
                          + 1.44
                          (520ns)

                          @@ -214,7 +214,7 @@

                          - 1.13
                          (413ns)
                          + 1.11
                          (404ns)

                          @@ -241,7 +241,7 @@

                          - 1.28
                          (258ns)
                          + 1.29
                          (261ns)

                          @@ -268,7 +268,7 @@

                          - 1.20
                          (490ns)
                          + 1.19
                          (488ns)

                          @@ -295,7 +295,7 @@

                          - 1.29
                          (98ns)
                          + 1.36
                          (103ns)

                          @@ -322,7 +322,7 @@

                          - 1.05
                          (749ns)
                          + 1.04
                          (747ns)

                          @@ -376,7 +376,7 @@

                          - 17.51
                          (11716ns)
                          + 16.76
                          (11212ns)

                          @@ -403,22 +403,22 @@

                          - 1.00
                          (226ns)
                          + 1.00
                          (225ns)

                          - 1.78
                          (403ns)
                          + 1.79
                          (403ns)

                          - 1.23
                          (279ns)
                          + 1.24
                          (279ns)

                          - 1.01
                          (229ns)
                          + 1.02
                          (229ns)

                          @@ -430,7 +430,7 @@

                          - 1.25
                          (25ns)
                          + 1.20
                          (24ns)

                          @@ -457,7 +457,7 @@

                          - 1.55
                          (273ns)
                          + 1.87
                          (329ns)

                          @@ -484,7 +484,7 @@

                          - 1.75
                          (49ns)
                          + 2.18
                          (61ns)

                          @@ -511,7 +511,7 @@

                          - 1.51
                          (444ns)
                          + 1.78
                          (525ns)

                          @@ -538,7 +538,7 @@

                          - 1.69
                          (49ns)
                          + 2.14
                          (62ns)

                          @@ -565,7 +565,7 @@

                          - 1.48
                          (884ns)
                          + 1.94
                          (1155ns)

                          @@ -592,7 +592,7 @@

                          - 1.59
                          (558ns)
                          + 2.05
                          (721ns)

                          @@ -619,7 +619,7 @@

                          - 1.23
                          (38ns)
                          + 1.58
                          (49ns)

                          @@ -646,7 +646,7 @@

                          - 1.41
                          (267ns)
                          + 1.75
                          (332ns)

                          @@ -673,7 +673,7 @@

                          - 1.36
                          (57ns)
                          + 1.69
                          (71ns)

                          @@ -700,7 +700,7 @@

                          - 1.43
                          (257ns)
                          + 1.91
                          (344ns)

                          @@ -727,7 +727,7 @@

                          - 1.00
                          (13ns)
                          + 1.77
                          (23ns)

                          @@ -754,7 +754,7 @@

                          - 1.06
                          (18ns)
                          + 1.29
                          (22ns)

                          @@ -781,7 +781,7 @@

                          - 1.00
                          (28ns)
                          + 1.39
                          (39ns)

                          @@ -808,7 +808,7 @@

                          - 1.12
                          (119ns)
                          + 1.10
                          (117ns)

                          @@ -835,22 +835,22 @@

                          - 1.00
                          (11ns)
                          + 1.00
                          (10ns)

                          - 2.82
                          (31ns)
                          + 3.10
                          (31ns)

                          - 2.18
                          (24ns)
                          + 2.40
                          (24ns)

                          - 1.00
                          (11ns)
                          + 1.10
                          (11ns)

                          @@ -862,7 +862,7 @@

                          - 1.24
                          (185ns)
                          + 1.29
                          (192ns)

                          @@ -889,7 +889,7 @@

                          - 1.31
                          (682ns)
                          + 1.36
                          (706ns)

                          @@ -916,7 +916,7 @@

                          - 1.20
                          (185ns)
                          + 1.16
                          (179ns)

                          @@ -943,7 +943,7 @@

                          - 1.33
                          (685ns)
                          + 1.37
                          (703ns)

                          @@ -970,7 +970,7 @@

                          - 1.57
                          (612ns)
                          + 1.34
                          (520ns)

                          @@ -997,7 +997,7 @@

                          - 1.35
                          (1964ns)
                          + 1.51
                          (2193ns)

                          @@ -1024,7 +1024,7 @@

                          - 1.34
                          (537ns)
                          + 1.29
                          (518ns)

                          @@ -1051,7 +1051,7 @@

                          - 1.34
                          (1938ns)
                          + 1.41
                          (2045ns)

                          @@ -1078,7 +1078,7 @@

                          - 1.37
                          (183ns)
                          + 1.36
                          (182ns)

                          @@ -1105,7 +1105,7 @@

                          - 1.37
                          (197ns)
                          + 1.82
                          (262ns)

                          @@ -1132,7 +1132,7 @@

                          - 1.32
                          (181ns)
                          + 1.31
                          (179ns)

                          @@ -1159,22 +1159,22 @@

                          - 1.00
                          (126ns)
                          + 1.00
                          (121ns)

                          - 1.10
                          (139ns)
                          + 1.15
                          (139ns)

                          - 1.00
                          (126ns)
                          + 1.04
                          (126ns)

                          - 1.06
                          (133ns)
                          + 1.10
                          (133ns)

                          @@ -1186,7 +1186,7 @@

                          - 1.03
                          (350ns)
                          + 1.07
                          (364ns)

                          @@ -1213,22 +1213,22 @@

                          - 1.03
                          (443ns)
                          + 1.00
                          (427ns)

                          - 1.19
                          (512ns)
                          + 1.20
                          (512ns)

                          - 1.00
                          (430ns)
                          + 1.01
                          (430ns)

                          - 1.06
                          (455ns)
                          + 1.07
                          (455ns)

                          @@ -1240,22 +1240,22 @@

                          - 1.21
                          (93ns)
                          + 1.00
                          (73ns)

                          - 2.91
                          (224ns)
                          + 3.07
                          (224ns)

                          - 1.73
                          (133ns)
                          + 1.82
                          (133ns)

                          - 1.00
                          (77ns)
                          + 1.05
                          (77ns)

                          @@ -1267,7 +1267,7 @@

                          - 1.29
                          (18ns)
                          + 1.00
                          (14ns)

                          @@ -1294,7 +1294,7 @@

                          - 1.23
                          (3997ns)
                          + 1.16
                          (3773ns)

                          @@ -1321,7 +1321,7 @@

                          - 1.18
                          (1012ns)
                          + 1.17
                          (1005ns)

                          @@ -1348,7 +1348,7 @@

                          - 1.10
                          (1846ns)
                          + 1.08
                          (1827ns)

                          @@ -1375,7 +1375,7 @@

                          - 1.34
                          (79ns)
                          + 1.31
                          (77ns)

                          @@ -1402,7 +1402,7 @@

                          - 1.19
                          (260ns)
                          + 1.26
                          (276ns)

                          @@ -1456,7 +1456,7 @@

                          - 1.36
                          (122ns)
                          + 1.34
                          (121ns)

                          @@ -1478,9 +1478,920 @@
                      -

                      - [table_Compiler_Comparison_on_linux] -

                      +
                      +

                      Table 16.6. Compiler Comparison on linux

                      +
                      +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      +

                      + Function +

                      +
                      +

                      + GNU C++ version 5.3.0
                      boost 1.61 +

                      +
                      +

                      + GNU C++ version 5.3.0
                      boost 1.61
                      promote_double<false> +

                      +
                      +

                      + assoc_laguerre +

                      +
                      +

                      + 1.36
                      (263ns)
                      +

                      +
                      +

                      + 1.00
                      (194ns)
                      +

                      +
                      +

                      + assoc_legendre +

                      +
                      +

                      + 2.55
                      (258ns)
                      +

                      +
                      +

                      + 1.00
                      (101ns)
                      +

                      +
                      +

                      + beta +

                      +
                      +

                      + 4.71
                      (734ns)
                      +

                      +
                      +

                      + 1.00
                      (156ns)
                      +

                      +
                      +

                      + beta (incomplete) +

                      +
                      +

                      + 3.12
                      (1796ns)
                      +

                      +
                      +

                      + 1.00
                      (575ns)
                      +

                      +
                      +

                      + cbrt +

                      +
                      +

                      + 2.53
                      (43ns)
                      +

                      +
                      +

                      + 1.00
                      (17ns)
                      +

                      +
                      +

                      + cyl_bessel_i +

                      +
                      +

                      + 3.47
                      (1410ns)
                      +

                      +
                      +

                      + 1.00
                      (406ns)
                      +

                      +
                      +

                      + cyl_bessel_i (integer order) +

                      +
                      +

                      + 3.38
                      (893ns)
                      +

                      +
                      +

                      + 1.00
                      (264ns)
                      +

                      +
                      +

                      + cyl_bessel_j +

                      +
                      +

                      + 2.69
                      (1071ns)
                      +

                      +
                      +

                      + 1.00
                      (398ns)
                      +

                      +
                      +

                      + cyl_bessel_j (integer order) +

                      +
                      +

                      + 2.59
                      (275ns)
                      +

                      +
                      +

                      + 1.00
                      (106ns)
                      +

                      +
                      +

                      + cyl_bessel_k +

                      +
                      +

                      + 6.86
                      (4589ns)
                      +

                      +
                      +

                      + 1.00
                      (669ns)
                      +

                      +
                      +

                      + cyl_bessel_k (integer order) +

                      +
                      +

                      + 10.17
                      (3673ns)
                      +

                      +
                      +

                      + 1.00
                      (361ns)
                      +

                      +
                      +

                      + cyl_neumann +

                      +
                      +

                      + 2.48
                      (1478ns)
                      +

                      +
                      +

                      + 1.00
                      (597ns)
                      +

                      +
                      +

                      + cyl_neumann (integer order) +

                      +
                      +

                      + 2.20
                      (484ns)
                      +

                      +
                      +

                      + 1.00
                      (220ns)
                      +

                      +
                      +

                      + digamma +

                      +
                      +

                      + 1.92
                      (75ns)
                      +

                      +
                      +

                      + 1.00
                      (39ns)
                      +

                      +
                      +

                      + ellint_1 +

                      +
                      +

                      + 1.94
                      (358ns)
                      +

                      +
                      +

                      + 1.00
                      (185ns)
                      +

                      +
                      +

                      + ellint_1 (complete) +

                      +
                      +

                      + 1.86
                      (52ns)
                      +

                      +
                      +

                      + 1.00
                      (28ns)
                      +

                      +
                      +

                      + ellint_2 +

                      +
                      +

                      + 2.32
                      (805ns)
                      +

                      +
                      +

                      + 1.00
                      (347ns)
                      +

                      +
                      +

                      + ellint_2 (complete) +

                      +
                      +

                      + 1.71
                      (60ns)
                      +

                      +
                      +

                      + 1.00
                      (35ns)
                      +

                      +
                      +

                      + ellint_3 +

                      +
                      +

                      + 2.75
                      (2154ns)
                      +

                      +
                      +

                      + 1.00
                      (783ns)
                      +

                      +
                      +

                      + ellint_3 (complete) +

                      +
                      +

                      + 2.23
                      (1172ns)
                      +

                      +
                      +

                      + 1.00
                      (525ns)
                      +

                      +
                      +

                      + ellint_rc +

                      +
                      +

                      + 1.57
                      (77ns)
                      +

                      +
                      +

                      + 1.00
                      (49ns)
                      +

                      +
                      +

                      + ellint_rd +

                      +
                      +

                      + 2.23
                      (520ns)
                      +

                      +
                      +

                      + 1.00
                      (233ns)
                      +

                      +
                      +

                      + ellint_rf +

                      +
                      +

                      + 1.51
                      (95ns)
                      +

                      +
                      +

                      + 1.00
                      (63ns)
                      +

                      +
                      +

                      + ellint_rj +

                      +
                      +

                      + 2.33
                      (481ns)
                      +

                      +
                      +

                      + 1.00
                      (206ns)
                      +

                      +
                      +

                      + erf +

                      +
                      +

                      + 2.60
                      (39ns)
                      +

                      +
                      +

                      + 1.00
                      (15ns)
                      +

                      +
                      +

                      + erfc +

                      +
                      +

                      + 2.68
                      (59ns)
                      +

                      +
                      +

                      + 1.00
                      (22ns)
                      +

                      +
                      +

                      + expint +

                      +
                      +

                      + 2.47
                      (94ns)
                      +

                      +
                      +

                      + 1.00
                      (38ns)
                      +

                      +
                      +

                      + expint (En) +

                      +
                      +

                      + 1.86
                      (273ns)
                      +

                      +
                      +

                      + 1.00
                      (147ns)
                      +

                      +
                      +

                      + expm1 +

                      +
                      +

                      + 1.00
                      (10ns)
                      +

                      +
                      +

                      + 1.10
                      (11ns)
                      +

                      +
                      +

                      + gamma_p +

                      +
                      +

                      + 2.42
                      (492ns)
                      +

                      +
                      +

                      + 1.00
                      (203ns)
                      +

                      +
                      +

                      + gamma_p_inv +

                      +
                      +

                      + 2.24
                      (1577ns)
                      +

                      +
                      +

                      + 1.00
                      (704ns)
                      +

                      +
                      +

                      + gamma_q +

                      +
                      +

                      + 2.53
                      (508ns)
                      +

                      +
                      +

                      + 1.00
                      (201ns)
                      +

                      +
                      +

                      + gamma_q_inv +

                      +
                      +

                      + 2.45
                      (1841ns)
                      +

                      +
                      +

                      + 1.00
                      (751ns)
                      +

                      +
                      +

                      + ibeta +

                      +
                      +

                      + 2.71
                      (1715ns)
                      +

                      +
                      +

                      + 1.00
                      (634ns)
                      +

                      +
                      +

                      + ibeta_inv +

                      +
                      +

                      + 2.58
                      (5742ns)
                      +

                      +
                      +

                      + 1.00
                      (2224ns)
                      +

                      +
                      +

                      + ibetac +

                      +
                      +

                      + 2.66
                      (1736ns)
                      +

                      +
                      +

                      + 1.00
                      (653ns)
                      +

                      +
                      +

                      + ibetac_inv +

                      +
                      +

                      + 2.44
                      (5451ns)
                      +

                      +
                      +

                      + 1.00
                      (2237ns)
                      +

                      +
                      +

                      + jacobi_cn +

                      +
                      +

                      + 2.77
                      (476ns)
                      +

                      +
                      +

                      + 1.00
                      (172ns)
                      +

                      +
                      +

                      + jacobi_dn +

                      +
                      +

                      + 2.80
                      (481ns)
                      +

                      +
                      +

                      + 1.00
                      (172ns)
                      +

                      +
                      +

                      + jacobi_sn +

                      +
                      +

                      + 2.86
                      (492ns)
                      +

                      +
                      +

                      + 1.00
                      (172ns)
                      +

                      +
                      +

                      + laguerre +

                      +
                      +

                      + 1.09
                      (139ns)
                      +

                      +
                      +

                      + 1.00
                      (128ns)
                      +

                      +
                      +

                      + legendre +

                      +
                      +

                      + 1.16
                      (399ns)
                      +

                      +
                      +

                      + 1.00
                      (345ns)
                      +

                      +
                      +

                      + legendre Q +

                      +
                      +

                      + 1.18
                      (496ns)
                      +

                      +
                      +

                      + 1.00
                      (422ns)
                      +

                      +
                      +

                      + lgamma +

                      +
                      +

                      + 2.20
                      (257ns)
                      +

                      +
                      +

                      + 1.00
                      (117ns)
                      +

                      +
                      +

                      + log1p +

                      +
                      +

                      + 1.00
                      (12ns)
                      +

                      +
                      +

                      + 1.00
                      (12ns)
                      +

                      +
                      +

                      + polygamma +

                      +
                      +

                      + 3.93
                      (2885ns)
                      +

                      +
                      +

                      + 1.00
                      (734ns)
                      +

                      +
                      +

                      + sph_bessel +

                      +
                      +

                      + 1.71
                      (1563ns)
                      +

                      +
                      +

                      + 1.00
                      (915ns)
                      +

                      +
                      +

                      + sph_neumann +

                      +
                      +

                      + 2.15
                      (3745ns)
                      +

                      +
                      +

                      + 1.00
                      (1744ns)
                      +

                      +
                      +

                      + tgamma +

                      +
                      +

                      + 3.69
                      (354ns)
                      +

                      +
                      +

                      + 1.00
                      (96ns)
                      +

                      +
                      +

                      + tgamma (incomplete) +

                      +
                      +

                      + 2.35
                      (744ns)
                      +

                      +
                      +

                      + 1.00
                      (316ns)
                      +

                      +
                      +

                      + trigamma +

                      +
                      +

                      + 1.64
                      (36ns)
                      +

                      +
                      +

                      + 1.00
                      (22ns)
                      +

                      +
                      +

                      + zeta +

                      +
                      +

                      + 2.71
                      (509ns)
                      +

                      +
                      +

                      + 1.00
                      (188ns)
                      +

                      +
                      +
                      +
                    diff --git a/doc/html/math_toolkit/comparisons.html b/doc/html/math_toolkit/comparisons.html index df86d5563..decf9575e 100644 --- a/doc/html/math_toolkit/comparisons.html +++ b/doc/html/math_toolkit/comparisons.html @@ -53,7 +53,7 @@ MSVC-14.0:

                    -

                    Table 16.6. Library Comparison with Microsoft Visual C++ version 14.0 on Windows +

                    Table 16.7. Library Comparison with Microsoft Visual C++ version 14.0 on Windows x64

                    @@ -93,7 +93,7 @@ @@ -105,12 +105,12 @@ @@ -122,12 +122,12 @@ @@ -139,12 +139,12 @@ @@ -156,12 +156,12 @@ @@ -173,12 +173,12 @@ @@ -190,12 +190,12 @@ @@ -207,12 +207,12 @@ @@ -224,12 +224,12 @@ diff --git a/doc/html/math_toolkit/conventions.html b/doc/html/math_toolkit/conventions.html index 0d199f06a..8c4c9dc43 100644 --- a/doc/html/math_toolkit/conventions.html +++ b/doc/html/math_toolkit/conventions.html @@ -27,7 +27,7 @@ Document Conventions

                    - +

                    This documentation aims to use of the following naming and formatting conventions. diff --git a/doc/html/math_toolkit/exact_typdefs.html b/doc/html/math_toolkit/exact_typdefs.html index 7aaa99b7d..98f1248d2 100644 --- a/doc/html/math_toolkit/exact_typdefs.html +++ b/doc/html/math_toolkit/exact_typdefs.html @@ -56,33 +56,36 @@

                    The definition (or not) of a floating-point - constant macro is the way to test if a specific width is available on - a platform. + constant macro is a way to test if a specific + width floating-point is available on a platform.

                    #if defined(BOOST_FLOAT16_C)
                    -// Can use boost::float16_t.
                    +// Can use boost::float16_t, perhaps a proposed __short_float.
                    +// P0192R1, Adding Fundamental Type for Short Float,
                    +// Boris Fomitchev, Sergei Nikolaev, Olivier Giroux, Lawrence Crowl, 2016 Feb14
                    +// http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2016.pdf
                     #endif
                     
                     #if defined(BOOST_FLOAT32_C)
                    -// Can use boost::float32_t.
                    +// Can use boost::float32_t, usually type `float`.
                     #endif
                     
                     #if defined(BOOST_FLOAT64_C)
                    -// Can use boost::float64_t.
                    +// Can use boost::float64_t, usually type `double`, and sometimes also type `long double`.
                     #endif
                     
                     #if defined(BOOST_FLOAT80_C)
                    -// Can use boost::float80_t.
                    +// Can use boost::float80_t, sometimes type `long double`.
                     #endif
                     
                     #if defined(BOOST_FLOAT128_C)
                    -// Can use boost::float128_t.
                    +// Can use boost::float128_t. Sometimes type `__float128` or `_Quad`.
                     #endif
                     

                    This can be used to write code which will compile and run (albeit differently) on several platforms. Without these tests, if a width, say float128_t - is not supported, then compilation would fail. (It is of course, rare for + is not supported, then compilation would fail. (It is, of course, rare for float64_t or float32_t not to be supported).

                    @@ -92,7 +95,9 @@

                    and from this one can safely infer the total number of bits because the type - must be IEEE754 format, so, for example, if std::numeric_limits<boost::floatmax_t>::digits == 113, then + must be IEEE754 format, std::numeric_limits<boost::floatmax_t>::is_iec559 + == true, + so, for example, if std::numeric_limits<boost::floatmax_t>::digits == 113, then floatmax_t must be float128_t.

                    @@ -124,7 +129,12 @@

                    - 1.42
                    (64ns)
                    + 1.44
                    (65ns)

                    - 1.00
                    (98ns)
                    + 1.00
                    (103ns)

                    - 2.35
                    (230ns)
                    + 2.11
                    (217ns)

                    - 1.41
                    (226ns)
                    + 1.57
                    (225ns)

                    - 1.00
                    (160ns)
                    + 1.00
                    (143ns)

                    - 1.00
                    (13ns)
                    + 1.10
                    (23ns)

                    - 1.46
                    (19ns)
                    + 1.00
                    (21ns)

                    - 1.00
                    (18ns)
                    + 1.00
                    (22ns)

                    - 3.11
                    (56ns)
                    + 3.36
                    (74ns)

                    - 1.10
                    (11ns)
                    + 1.00
                    (10ns)

                    - 1.00
                    (10ns)
                    + 1.10
                    (11ns)

                    - 1.00
                    (93ns)
                    + 1.00
                    (73ns)

                    - 1.56
                    (145ns)
                    + 1.74
                    (127ns)

                    - 1.29
                    (18ns)
                    + 1.08
                    (14ns)

                    - 1.00
                    (14ns)
                    + 1.00
                    (13ns)

                    - 1.00
                    (79ns)
                    + 1.00
                    (77ns)

                    - 11.03
                    (871ns)
                    + 12.12
                    (933ns)

                    max_digits10 is not always - supported, but can be calculated at compile-time using the Kahan formula. + supported, but can be calculated at compile-time using the Kahan formula, + 2 + + binary_digits * + 0.3010 which can be calculated at compile time using 2 + + binary_digits + * 3010/10000.

                  @@ -134,14 +144,14 @@

                  - One could test + One could test that

                  std::is_same<boost::floatmax_t, boost::float128_t>::value == true

                  but this would fail to compile on a platform where boost::float128_t - is not defined. So use the MACROs BOOST_FLOATnnn_C. + is not defined. So it is better to use the MACROs BOOST_FLOATnnn_C.

                  diff --git a/doc/html/math_toolkit/examples.html b/doc/html/math_toolkit/examples.html index 8fafee611..f1bde1a7e 100644 --- a/doc/html/math_toolkit/examples.html +++ b/doc/html/math_toolkit/examples.html @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@

                  -PrevUpHomeNext +PrevUpHomeNext

                  @@ -49,8 +49,8 @@ 15 decimal digits of precision, regardless of the compiler or version or operating system.

                  -
                  #include <boost/cstdfloat.hpp> // For float_64_t. Must be first include!
                  -#include <cmath>  // for pow function. 
                  +
                  #include <boost/cstdfloat.hpp> // For float_64_t, float128_t. Must be first include!
                  +#include <cmath>  // for pow function.
                   #include <boost/math/special_functions.hpp> // For gamma function.
                   
                  boost::float64_t jahnke_emden_lambda(boost::float64_t v, boost::float64_t x)
                  @@ -87,11 +87,11 @@
                       

                  This example shows printing tables of a normal distribution's PDF and CDF, - using boost::math implmentation of normal. + using boost::math implementation of normal distribution.

                  - A function templated on floating-point type prints a table for a range of z - values. + A function templated on floating-point type prints a table for a range of standard + variate z values.

                  The example shows use of the specified-width typedefs to either use a specific @@ -109,14 +109,14 @@ normal_tables.cpp.

                  #ifdef BOOST_FLOAT32_C
                  -    normal_table<boost::float32_t>();
                  +    normal_table<boost::float32_t>(); // Usually type float
                   #endif
                  -    normal_table<boost::float64_t>(); // Assume that float64_t is always available.
                  +    normal_table<boost::float64_t>(); // Uusually type double. Assume that float64_t is always available.
                   #ifdef BOOST_FLOAT80_C
                  -    normal_table<boost::float80_t>();
                  +    normal_table<boost::float80_t>(); // Type long double on some X86 platforms.
                   #endif
                   #ifdef BOOST_FLOAT128_C
                  -    normal_table<boost::float128_t>();
                  +    normal_table<boost::float128_t>(); // Type _Quad on some Intel and __float128 on some GCC platforms.
                   #endif
                       normal_table<boost::floatmax_t>();
                   
                  @@ -134,7 +134,7 @@
                  -PrevUpHomeNext +PrevUpHomeNext
                  diff --git a/doc/html/math_toolkit/float128.html b/doc/html/math_toolkit/float128.html index d1f5e58fc..a72ce789c 100644 --- a/doc/html/math_toolkit/float128.html +++ b/doc/html/math_toolkit/float128.html @@ -6,8 +6,8 @@ - - + + @@ -20,29 +20,32 @@

                  -PrevUpHomeNext +PrevUpHomeNext

                  Since few compilers implement a true 128-bit floating-point, and language features - like the suffix Q, and C++ Standard library functions are as-yet missing or - incomplete in C++11, this Boost.Math implementation wraps __float128 - provided by the GCC compiler or the _Quad + like the suffix Q (which may need an option -fext-numeric-literals + to enable), and C++ Standard library functions are as-yet missing or incomplete + in C++11, this Boost.Math implementation wraps __float128 + provided by the GCC compiler GCC + floating-point types or the _Quad type provided by the Intel compiler.

                  This is provided to in order to demonstrate, and users to evaluate, the feasibility and benefits of higher-precision floating-point, especially to allow use of - the full Boost.Math library of functions and distributions at high precision. + the full <cmath> and Boost.Math library of functions and distributions + at high precision.

                  (It is also possible to use Boost.Math with Boost.Multiprecision decimal and @@ -64,7 +67,7 @@

                  For GCC, compile with -std=gnu++11 or -std=gnu++03 and do - not use -std=stdc++11or any 'strict' options as these turn off + not use -std=stdc++11 or any 'strict' options, as these turn off full support for __float128. These requirements also apply to the Intel compiler on Linux, for Intel on Windows you need to compile with -Qoption,cpp,--extended_float_type -DBOOST_MATH_USE_FLOAT128 in order to activate @@ -74,7 +77,69 @@

                  The __float128 type is provided by the libquadmath - library on GCC or by Intel's FORTRAN library with Intel C++. + library on GCC or by Intel's FORTRAN library with Intel C++. THey also + provide a full set of <cmath> functions in namespace + std. +

                  +
                  + + Using + C __float128 quadmath type +
                  +

                  + Example of using GCC Quad-Precision Math Library quadmath __float128 + type, taking a square root with sqrtq, and output using quadmath_snprintf. +

                  +

                  + From GCC Quad-Precision Math Library, 3.2 + quadmath_snprintf, Convert to string (pages 9 and 10). +

                  +

                  + Requires GCC linker option -lquadmath. +

                  +

                  + If this linker option is missing then you will get errors like: +

                  +
                  /Cpp/float128/quadmath_snprintf/quadmath_snprintf.c:44: undefined reference to 'sqrtq'.
                  +/Cpp/float128/quadmath_snprintf/quadmath_snprintf.c:45: undefined reference to 'quadmath_snprintf'.
                  +
                  +

                  + On one system, the header file (that contains all the extern + declarations), included, for example: +

                  +
                  extern __float128 sqrtq (__float128) __quadmath_throw;
                  +extern __float128 strtoflt128 (const char *, char **) __quadmath_throw;
                  +extern int quadmath_snprintf (char *str, size_t size, const char *format, ...) __quadmath_throw;
                  +
                  +

                  + An example of a location of quadmath.h is +

                  +
                  C:\program files\gcc-6-win64\lib\gcc\x86_64-w64-mingw32\6.1.1\include\quadmath.h
                  +
                  +

                  + and library at +

                  +
                  C:\Program Files\gcc-6-win64\bin\libquadmath-0.dll
                  +
                  +

                  + Command lines used (using CodeBLocks: +

                  +
                  gcc.exe -Wall -g  -c J:\Cpp\float128\quadmath_snprintf\main.c -o obj\Debug\main.o
                  +g++.exe  -o bin\Debug\quadmath_snprintf.exe obj\Debug\main.o  -lquadmath
                  +
                  +

                  + The source code is at quadmath_snprintf.c. +

                  +
                  + + Using + C++ float128 quadmath type +
                  +

                  + For C++ programs, you will want to use the C++ type float128 +

                  +

                  + See example at cstdfloat_example.cpp.

                  A typical invocation of the compiler is @@ -98,11 +163,35 @@ [Note] Note -

                  - So far, the only missing detail that we have noted is in trying to use <typeinfo>, for example for std::cout << typeid<__float_128>.name();. Link fails: undefined reference to typeinfo for - __float128. See GCC - Bug 43622 - no C++ typeinfo for __float128. -

                  + +

                  + So far, the only missing detail that we had noted was in trying to use <typeinfo>, for example for std::cout << typeid<__float_128>.name();. +

                  +
                  Link fails: undefined reference to typeinfo for __float128.
                  +
                  +

                  + See GCC Bug + 43622 - no C++ typeinfo for __float128. But this is reported (Marc + Glisse 2015-04-04 ) fixed in GCC 5 (and above). +

                  +

                  + For example, with GCC6.1.1 this works as expected to a mangled + string name, and output (if possible - not always). +

                  +
                  const std::type_info& tifu128 = typeid(__float128); // OK.
                  +//std::cout << tifu128.name() << std::endl; // On GCC, aborts (because not printable string).
                  +//std::cout << typeid(__float128).name() << std::endl; // Aborts - string name cannot be output.
                  +
                  +const std::type_info& tif128 = typeid(float128); // OK.
                  +std::cout << tif128.name() << std::endl; // OK.
                  +std::cout << typeid(float128).name() << std::endl; // OK.
                  +
                  +const std::type_info& tpi = typeid(pi1); // OK GCC 6.1.1 (from GCC 5 according to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622)
                  +std::cout << tpi.name() << std::endl; // Output mangled name:
                  +
                  +// N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE
                  +
                  +
                  @@ -118,7 +207,7 @@

                  -PrevUpHomeNext +PrevUpHomeNext
                  diff --git a/doc/html/math_toolkit/float128/exp_function.html b/doc/html/math_toolkit/float128/exp_function.html index be42085c6..7e0fa8121 100644 --- a/doc/html/math_toolkit/float128/exp_function.html +++ b/doc/html/math_toolkit/float128/exp_function.html @@ -6,7 +6,7 @@ - + @@ -20,26 +20,37 @@
                  -PrevUpHomeNext +PrevUpHomeNext

                  - There is a bug whe using any quadmath expq - function on GCC: + There was a bug when using any quadmath expq + function on GCC : GCC + bug #60349 caused by mingw-64 + bug #368.

                  - GCC bug #60349 -

                  -

                  - mingw-64 bug #368 -

                  -

                  - To work round this defect, an alternative implementation of 128-bit exp is + To work round this defect, an alternative implementation of 128-bit exp was temporarily provided by boost/cstdfloat.hpp.

                  +

                  + The mingw bug was fixed at 2014-03-12 and GCC 6.1.1 now works as expected. +

                  +
                  + + + + + +
                  [Tip]Tip

                  + It is essential to link to the quadmath library +

                  +

                  + . +

                  @@ -54,7 +65,7 @@

                  -PrevUpHomeNext +PrevUpHomeNext
                  diff --git a/doc/html/math_toolkit/float128/typeinfo.html b/doc/html/math_toolkit/float128/typeinfo.html index cf4bf07f3..8a7d71b38 100644 --- a/doc/html/math_toolkit/float128/typeinfo.html +++ b/doc/html/math_toolkit/float128/typeinfo.html @@ -27,12 +27,12 @@ typeinfo

                  - It is not yet possible to use typeinfo - for float_128 on GCC: see GCC - 43622 + For GCC 4.8.1 it was not yet possible to use typeinfo + for float_128 on GCC: see + GCC 43622.

                  - so this fails to link undefined + So this code (to display the mangled name) failed to link undefined reference to typeinfo for __float128 @@ -45,9 +45,19 @@ them is defined then some diagnostic displays in Boost.Math will not work.

                  - However this is only used for display purposes and can be commented out until - this is fixed. + However this was only used for display purposes and could be commented out + until this was fixed in GCC 5.

                  +
                  + + + + + +
                  [Tip]Tip

                  + Not all managed names can be displayed + using std::cout. +

                diff --git a/doc/html/math_toolkit/float_comparison.html b/doc/html/math_toolkit/float_comparison.html index e1e77bd90..9f1e267bd 100644 --- a/doc/html/math_toolkit/float_comparison.html +++ b/doc/html/math_toolkit/float_comparison.html @@ -111,23 +111,23 @@ Comparison of Floating-point Values

                - #include <boost/math/special_functions/relative_distance.hpp> + #include <boost/math/special_functions/relative_difference.hpp>

                template <class T, class U>
                -calculated-result-type relative_distance(T a, U b);
                +calculated-result-type relative_difference(T a, U b);
                 
                 template <class T, class U>
                -calculated-result-type epsilon_distance(T a, U b);
                +calculated-result-type epsilon_difference(T a, U b);
                 

                - The function relative_distance + The function relative_difference returns the relative distance/error E between two values as defined by:

                E = fabs((a - b) / min(a,b))

                The function epsilon_difference - is a convenience function that returns relative_distance(a, + is a convenience function that returns relative_difference(a, b) / eps where eps is the machine epsilon for the result type. diff --git a/doc/html/math_toolkit/getting_best.html b/doc/html/math_toolkit/getting_best.html index ecf4f1c95..0c4fee530 100644 --- a/doc/html/math_toolkit/getting_best.html +++ b/doc/html/math_toolkit/getting_best.html @@ -80,17 +80,17 @@

                - 19.93
                (279ns)
                + 18.29
                (256ns)

                - 4.36
                (61ns)
                + 4.29
                (60ns)

                - 3.50
                (49ns)
                + 3.14
                (44ns)

                @@ -107,17 +107,17 @@

                - 10.19
                (754ns)
                + 10.03
                (742ns)

                - 1.61
                (119ns)
                + 1.77
                (131ns)

                - 1.43
                (106ns)
                + 1.36
                (101ns)

                @@ -134,17 +134,17 @@

                - 4.30
                (6545ns)
                + 4.32
                (6583ns)

                - 1.32
                (2014ns)
                + 1.29
                (1963ns)

                - 1.33
                (2029ns)
                + 1.28
                (1957ns)

                diff --git a/doc/html/math_toolkit/greatest_typdefs.html b/doc/html/math_toolkit/greatest_typdefs.html index 2d30e744c..6d920a71c 100644 --- a/doc/html/math_toolkit/greatest_typdefs.html +++ b/doc/html/math_toolkit/greatest_typdefs.html @@ -38,8 +38,8 @@

                To provide floating-point constants most precisely - for a floatmax_t type, use - the macro BOOST_FLOATMAX_C. + representable for a floatmax_t + type, use the macro BOOST_FLOATMAX_C.

                For example, replace a constant 123.4567890123456789012345678901234567890 @@ -53,7 +53,8 @@ will be equivalent to a long double suffixed with L, but if floatmax_t is float128_t then the result will be equivalent to a quad type suffixed with Q (assuming, of - course, that float128 is supported). + course, that float128_t (__float128 or Quad) + is supported).

                If we display with max_digits10, @@ -68,7 +69,7 @@ #endif

                - then on a 128-bit platform (GCC 4.8.1. with quadmath): + then on a 128-bit platform (GCC 4.8.1 or higher with quadmath):

                BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) = 123.456787
                 BOOST_FLOAT64_C(123.4567890123456789012345678901234567890) = 123.45678901234568
                diff --git a/doc/html/math_toolkit/macros.html b/doc/html/math_toolkit/macros.html
                index 6d7ab6a95..c8565870b 100644
                --- a/doc/html/math_toolkit/macros.html
                +++ b/doc/html/math_toolkit/macros.html
                @@ -59,12 +59,15 @@
                   boost::floatmax_t pi_max = boost::math::constants::pi<boost::floatmax_t>();
                   std::cout.precision(std::numeric_limits<boost::floatmax_t>::digits10);
                   std::cout << "Most precise pi = "  << pi_max << std::endl;
                -// If floatmax_t is float_128_t, then 
                +// If floatmax_t is float_128_t, then
                 // Most precise pi = 3.141592653589793238462643383279503
                 

                from cstdfloat_example.cpp.

                +

                + See the complete list of constants. +

                diff --git a/doc/html/math_toolkit/navigation.html b/doc/html/math_toolkit/navigation.html index fba155737..6bdbc3d31 100644 --- a/doc/html/math_toolkit/navigation.html +++ b/doc/html/math_toolkit/navigation.html @@ -27,7 +27,7 @@ Navigation

                - +

                Boost.Math documentation is provided in both HTML and PDF formats. diff --git a/doc/html/math_toolkit/overview.html b/doc/html/math_toolkit/overview.html index 381c1c1ef..7fb48b21d 100644 --- a/doc/html/math_toolkit/overview.html +++ b/doc/html/math_toolkit/overview.html @@ -50,12 +50,14 @@ fast types, and the corresponding maximum-width type. The typedefs are based on underlying built-in types such as float, double, or long - double, or based on other compiler-specific - non-standardized types such as __float128. - The underlying types of these typedefs + double, or the proposed N2016 + short float type, or based on other compiler-specific non-standardized + types such as __float128. The + underlying types of these typedefs must conform with the corresponding specifications of binary16, binary32, binary64, and binary128 in IEEE_floating_point - floating-point format. + floating-point format, and std::numeric_limits<>::is_iec559 + == true.

                The 128-bit floating-point type (of great interest in scientific and numeric @@ -65,10 +67,11 @@

                See Jahnke-Emden-Lambda function - example for an example using both a CMath function and a Boost.Math - function to evaluate a moderately interesting function, the Jahnke-Emden-Lambda + example for an example using both a <cmath> + function and a Boost.Math function to evaluate a moderately interesting function, + the Jahnke-Emden-Lambda function and normal - distribution an example of a statistical distribution from Boost.Math + distribution as an example of a statistical distribution from Boost.Math.

                diff --git a/doc/html/math_toolkit/rationale.html b/doc/html/math_toolkit/rationale.html index 166013a13..763d46645 100644 --- a/doc/html/math_toolkit/rationale.html +++ b/doc/html/math_toolkit/rationale.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@

                -PrevUpHomeNext +PrevUpHomeNext

                @@ -33,7 +33,7 @@ definitions in <float.h> such as FLT_MAX, DBL_MAX, etc. Based on the results of these queries, an attempt is made to automatically detect the presence of built-in floating-point types - having specified widths. An unequivocal test regarding conformance with IEEE_floating_point + having specified widths. An unequivocal test requiring conformance with IEEE_floating_point (IEC599) based on std::numeric_limits<>::is_iec559 is performed with BOOST_STATIC_ASSERT.

                @@ -42,7 +42,7 @@ supports an 80-bit floating-point typedef if it can be detected, and a 128-bit floating-point typedef if it can be detected, provided that the underlying types conform with IEEE-754 precision extension - (ifstd::numeric_limits<>::is_iec559 is true for this type). + (provided std::numeric_limits<>::is_iec559 == true for this type).

                The header <boost/cstdfloat.hpp> @@ -125,8 +125,8 @@ double) is used for one of the specified width types. If generic code (for example in another Boost.Math header) calls a standard library function, then the correct overload will only be found - if these overloads are defined prior to the point of use. See implementation - for more details. + if these overloads are defined prior to the point of use. See overloading + template functions with float128_t and the implementation of cstdfloat.hpp for more details.

                For this reason, making #include @@ -149,7 +149,7 @@


                -PrevUpHomeNext +PrevUpHomeNext
                diff --git a/doc/html/math_toolkit/roots/polynomials.html b/doc/html/math_toolkit/roots/polynomials.html index 78ace2d43..f432a87e5 100644 --- a/doc/html/math_toolkit/roots/polynomials.html +++ b/doc/html/math_toolkit/roots/polynomials.html @@ -60,6 +60,10 @@ const value_type& operator[](size_type i)const; std::vector<T> const& data() const; std::vector<T>& data(); + explicit operator bool() const; + + // modify: + void set_zero(); // operators: template <class U> @@ -116,11 +120,23 @@ template <class T> polynomial<T> operator - (const polynomial<T>& a); +template <class T> +polynomial<T> operator >>= (const U& a); +template <class T> +polynomial<T> operator >> (polynomial<T> const &a, const U& b); +template <class T> +polynomial<T> operator <<= (const U& a); +template <class T> +polynomial<T> operator << (polynomial<T> const &a, const U& b); + template <class T> bool operator == (const polynomial<T> &a, const polynomial<T> &b); template <class T> bool operator != (const polynomial<T> &a, const polynomial<T> &b); +template <class T> +polynomial<T> pow(polynomial<T> base, int exp); + template <class charT, class traits, class T> std::basic_ostream<charT, traits>& operator << (std::basic_ostream<charT, traits>& os, const polynomial<T>& poly); diff --git a/doc/html/math_toolkit/run_time.html b/doc/html/math_toolkit/run_time.html index 6931c5cf9..9395ef712 100644 --- a/doc/html/math_toolkit/run_time.html +++ b/doc/html/math_toolkit/run_time.html @@ -32,17 +32,24 @@
                template < typename IntegerType >
                 IntegerType  boost::math::gcd( IntegerType const &a, IntegerType const &b );
                 
                +template < typename ForwardIterator >
                +std::pair<typename std::iterator_traits<I>::value_type, I> gcd_range(I first, I last);
                +
                 template < typename IntegerType >
                 IntegerType  boost::math::lcm( IntegerType const &a, IntegerType const &b );
                 

                The boost::math::gcd function template returns the greatest common (nonnegative) divisor of the - two integers passed to it. The boost::math::lcm function template returns the - least common (nonnegative) multiple of the two integers passed to it. The function - templates are parameterized on the function arguments' IntegerType, which is - also the return type. Internally, these function templates use an object of - the corresponding version of the gcd_evaluator + two integers passed to it. boost::math::gcd_range is the iteration of the above gcd + algorithm over a range, returning the greatest common divisor of all the elements. + The algorithm terminates when the gcd reaches unity or the end of the range. + Thus it also returns the iterator after the last element inspected because + this may not be equal to the end of the range. The boost::math::lcm function + template returns the least common (nonnegative) multiple of the two integers + passed to it. The function templates are parameterized on the function arguments' + IntegerType, which is also the return type. Internally, these function templates + use an object of the corresponding version of the gcd_evaluator and lcm_evaluator class templates, respectively.

                diff --git a/doc/html/math_toolkit/synopsis.html b/doc/html/math_toolkit/synopsis.html index 9c16a301c..8ce7e3692 100644 --- a/doc/html/math_toolkit/synopsis.html +++ b/doc/html/math_toolkit/synopsis.html @@ -38,6 +38,8 @@ template < typename IntegerType > IntegerType gcd( IntegerType const &a, IntegerType const &b ); +template < typename ForwardIterator > + std::pair<typename std::iterator_traits<I>::value_type, I> gcd_range(I first, I last); template < typename IntegerType > IntegerType lcm( IntegerType const &a, IntegerType const &b ); diff --git a/doc/html/math_toolkit/tuning.html b/doc/html/math_toolkit/tuning.html index bf2b9fe97..0c2a17f65 100644 --- a/doc/html/math_toolkit/tuning.html +++ b/doc/html/math_toolkit/tuning.html @@ -321,7 +321,7 @@

                - 1.11
                (10ns)
                + 1.00
                (9ns)

                @@ -331,12 +331,12 @@

                - 1.11
                (10ns)
                + 1.00
                (9ns)

                - 1.11
                (10ns)
                + 1.00
                (9ns)

                @@ -348,42 +348,42 @@

                - 2.15
                (28ns)
                + 2.08
                (25ns)

                - 2.46
                (32ns)
                + 2.75
                (33ns)

                - 1.00
                (13ns)
                + 1.08
                (13ns)

                - 1.08
                (14ns)
                + 1.08
                (13ns)

                - 1.00
                (13ns)
                + 1.08
                (13ns)

                - 1.00
                (13ns)
                + 1.08
                (13ns)

                - 1.08
                (14ns)
                + 1.08
                (13ns)

                - 1.08
                (14ns)
                + 1.00
                (12ns)

                @@ -395,42 +395,42 @@

                - 2.38
                (38ns)
                + 2.06
                (35ns)

                - 3.06
                (49ns)
                + 2.71
                (46ns)

                - 1.13
                (18ns)
                + 1.06
                (18ns)

                - 1.06
                (17ns)
                + 1.00
                (17ns)

                - 1.06
                (17ns)
                + 1.06
                (18ns)

                - 1.06
                (17ns)
                + 1.06
                (18ns)

                - 1.00
                (16ns)
                + 1.00
                (17ns)

                - 1.00
                (16ns)
                + 1.00
                (17ns)

                @@ -442,42 +442,42 @@

                - 1.43
                (30ns)
                + 1.32
                (29ns)

                - 2.14
                (45ns)
                + 2.00
                (44ns)

                - 1.10
                (23ns)
                + 1.00
                (22ns)

                - 1.05
                (22ns)
                + 1.00
                (22ns)

                - 1.00
                (21ns)
                + 1.05
                (23ns)

                - 1.00
                (21ns)
                + 1.05
                (23ns)

                - 1.00
                (21ns)
                + 1.05
                (23ns)

                - 1.14
                (24ns)
                + 1.05
                (23ns)

                @@ -489,42 +489,42 @@

                - 1.44
                (39ns)
                + 1.38
                (36ns)

                - 1.93
                (52ns)
                + 2.04
                (53ns)

                - 1.07
                (29ns)
                + 1.08
                (28ns)

                - 1.00
                (27ns)
                + 1.00
                (26ns)

                - 1.04
                (28ns)
                + 1.08
                (28ns)

                - 1.07
                (29ns)
                + 1.08
                (28ns)

                - 1.33
                (36ns)
                + 1.35
                (35ns)

                - 1.33
                (36ns)
                + 1.38
                (36ns)

                @@ -541,17 +541,7 @@

                - 2.20
                (66ns)
                -

                - - -

                - 1.03
                (31ns)
                -

                - - -

                - 1.07
                (32ns)
                + 2.13
                (64ns)

                @@ -566,12 +556,22 @@

                - 1.20
                (36ns)
                + 1.10
                (33ns)

                - 1.20
                (36ns)
                + 1.03
                (31ns)
                +

                + + +

                + 1.10
                (33ns)
                +

                + + +

                + 1.13
                (34ns)

                @@ -583,22 +583,12 @@

                - 1.46
                (54ns)
                + 1.65
                (61ns)

                - 2.05
                (76ns)
                -

                - - -

                - 1.11
                (41ns)
                -

                - - -

                - 1.11
                (41ns)
                + 2.22
                (82ns)

                @@ -608,12 +598,7 @@

                - 1.03
                (38ns)
                -

                - - -

                - 1.19
                (44ns)
                + 1.08
                (40ns)

                @@ -621,6 +606,21 @@ 1.14
                (42ns)

                + +

                + 1.05
                (39ns)
                +

                + + +

                + 1.08
                (40ns)
                +

                + + +

                + 1.11
                (41ns)
                +

                + @@ -630,42 +630,42 @@

                - 1.58
                (60ns)
                + 1.39
                (57ns)

                - 2.39
                (91ns)
                + 2.05
                (84ns)

                - 1.29
                (49ns)
                + 1.17
                (48ns)

                - 1.26
                (48ns)
                + 1.17
                (48ns)

                - 1.05
                (40ns)
                + 1.00
                (41ns)

                - 1.00
                (38ns)
                + 1.05
                (43ns)

                - 1.13
                (43ns)
                + 1.15
                (47ns)

                - 1.16
                (44ns)
                + 1.12
                (46ns)

                @@ -677,17 +677,12 @@

                - 1.50
                (69ns)
                + 1.37
                (63ns)

                - 2.17
                (100ns)
                -

                - - -

                - 1.24
                (57ns)
                + 2.20
                (101ns)

                @@ -695,6 +690,11 @@ 1.22
                (56ns)

                + +

                + 1.24
                (57ns)
                +

                +

                1.00
                (46ns)
                @@ -702,17 +702,17 @@

                - 1.02
                (47ns)
                + 1.00
                (46ns)

                - 1.15
                (53ns)
                + 1.17
                (54ns)

                - 1.15
                (53ns)
                + 1.17
                (54ns)

                @@ -724,42 +724,42 @@

                - 1.56
                (81ns)
                + 1.59
                (78ns)

                - 2.15
                (112ns)
                + 2.24
                (110ns)

                - 1.25
                (65ns)
                + 1.37
                (67ns)

                - 1.19
                (62ns)
                + 1.29
                (63ns)

                - 1.04
                (54ns)
                + 1.22
                (60ns)

                - 1.00
                (52ns)
                + 1.00
                (49ns)

                - 1.13
                (59ns)
                + 1.22
                (60ns)

                - 1.13
                (59ns)
                + 1.22
                (60ns)

                @@ -771,42 +771,42 @@

                - 1.37
                (86ns)
                + 1.46
                (83ns)

                - 2.02
                (127ns)
                + 2.16
                (123ns)

                - 1.13
                (71ns)
                + 1.28
                (73ns)

                - 1.14
                (72ns)
                + 1.26
                (72ns)

                - 1.02
                (64ns)
                + 1.02
                (58ns)

                - 1.00
                (63ns)
                + 1.00
                (57ns)

                - 1.03
                (65ns)
                + 1.07
                (61ns)

                - 1.03
                (65ns)
                + 1.05
                (60ns)

                @@ -818,42 +818,42 @@

                - 1.62
                (99ns)
                + 1.61
                (90ns)

                - 2.38
                (145ns)
                + 2.55
                (143ns)

                - 1.33
                (81ns)
                + 1.32
                (74ns)

                - 1.44
                (88ns)
                + 1.39
                (78ns)

                - 1.02
                (62ns)
                + 1.04
                (58ns)

                - 1.00
                (61ns)
                + 1.00
                (56ns)

                - 1.08
                (66ns)
                + 1.11
                (62ns)

                - 1.05
                (64ns)
                + 1.07
                (60ns)

                @@ -865,42 +865,42 @@

                - 1.64
                (105ns)
                + 1.61
                (106ns)

                - 2.45
                (157ns)
                + 2.23
                (147ns)

                - 1.56
                (100ns)
                + 1.45
                (96ns)

                - 1.52
                (97ns)
                + 1.45
                (96ns)

                - 1.03
                (66ns)
                + 1.02
                (67ns)

                - 1.00
                (64ns)
                + 1.02
                (67ns)

                - 1.03
                (66ns)
                + 1.00
                (66ns)

                - 1.09
                (70ns)
                + 1.09
                (72ns)

                @@ -912,42 +912,42 @@

                - 1.62
                (123ns)
                + 1.49
                (119ns)

                - 2.33
                (177ns)
                + 2.10
                (168ns)

                - 1.53
                (116ns)
                + 1.35
                (108ns)

                - 1.61
                (122ns)
                + 1.35
                (108ns)

                - 1.00
                (76ns)
                + 1.00
                (80ns)

                - 1.07
                (81ns)
                + 1.00
                (80ns)

                - 1.07
                (81ns)
                + 1.00
                (80ns)

                - 1.11
                (84ns)
                + 1.02
                (82ns)

                @@ -959,42 +959,42 @@

                - 1.37
                (126ns)
                + 1.54
                (129ns)

                - 1.87
                (172ns)
                + 1.99
                (167ns)

                - 1.41
                (130ns)
                + 1.49
                (125ns)

                - 1.28
                (118ns)
                + 1.45
                (122ns)

                - 1.01
                (93ns)
                + 1.07
                (90ns)

                - 1.00
                (92ns)
                + 1.00
                (84ns)

                - 1.00
                (92ns)
                + 1.08
                (91ns)

                - 1.00
                (92ns)
                + 1.02
                (86ns)

                @@ -1006,42 +1006,42 @@

                - 1.41
                (135ns)
                + 1.51
                (133ns)

                - 1.88
                (180ns)
                + 2.02
                (178ns)

                - 1.54
                (148ns)
                + 1.57
                (138ns)

                - 1.48
                (142ns)
                + 1.50
                (132ns)

                - 1.00
                (96ns)
                + 1.02
                (90ns)

                - 1.00
                (96ns)
                + 1.00
                (88ns)

                - 1.04
                (100ns)
                + 1.07
                (94ns)

                - 1.04
                (100ns)
                + 1.06
                (93ns)

                @@ -1053,42 +1053,42 @@

                - 1.57
                (159ns)
                + 1.53
                (148ns)

                - 2.01
                (203ns)
                + 2.16
                (210ns)

                - 1.54
                (156ns)
                + 1.49
                (145ns)

                - 1.56
                (158ns)
                + 1.57
                (152ns)

                - 1.00
                (101ns)
                + 1.11
                (108ns)

                - 1.03
                (104ns)
                + 1.09
                (106ns)

                - 1.05
                (106ns)
                + 1.00
                (97ns)

                - 1.08
                (109ns)
                + 1.08
                (105ns)

                @@ -1100,42 +1100,42 @@

                - 1.44
                (160ns)
                + 1.90
                (194ns)

                - 2.09
                (232ns)
                + 2.27
                (232ns)

                - 1.54
                (171ns)
                + 1.62
                (165ns)

                - 1.49
                (165ns)
                + 1.62
                (165ns)

                - 1.04
                (115ns)
                + 1.08
                (110ns)

                - 1.00
                (111ns)
                + 1.00
                (102ns)

                - 1.02
                (113ns)
                + 1.17
                (119ns)

                - 1.08
                (120ns)
                + 1.19
                (121ns)

                @@ -1147,42 +1147,42 @@

                - 1.50
                (179ns)
                + 1.65
                (206ns)

                - 2.11
                (251ns)
                + 2.08
                (260ns)

                - 1.59
                (189ns)
                + 1.45
                (181ns)

                - 1.55
                (184ns)
                + 1.44
                (180ns)

                - 1.07
                (127ns)
                + 1.00
                (125ns)

                - 1.09
                (130ns)
                + 1.00
                (125ns)

                - 1.04
                (124ns)
                + 1.01
                (126ns)

                - 1.00
                (119ns)
                + 1.03
                (129ns)

                @@ -1271,32 +1271,32 @@

                - 2.14
                (92ns)
                + 2.12
                (89ns)

                - 2.12
                (91ns)
                + 1.95
                (82ns)

                - 1.07
                (46ns)
                + 1.00
                (42ns)

                - 1.00
                (43ns)
                + 1.00
                (42ns)

                - 1.02
                (44ns)
                + 1.00
                (42ns)

                - 1.00
                (43ns)
                + 1.00
                (42ns)

                @@ -1308,42 +1308,42 @@

                - 2.07
                (89ns)
                + 2.10
                (88ns)

                - 1.95
                (84ns)
                + 2.10
                (88ns)

                - 2.19
                (94ns)
                + 2.05
                (86ns)

                - 2.16
                (93ns)
                + 2.10
                (88ns)

                - 1.05
                (45ns)
                + 1.05
                (44ns)

                - 1.07
                (46ns)
                + 1.00
                (42ns)

                - 1.00
                (43ns)
                + 1.00
                (42ns)

                - 1.02
                (44ns)
                + 1.00
                (42ns)

                @@ -1355,42 +1355,42 @@

                - 1.98
                (85ns)
                + 2.12
                (89ns)

                - 2.23
                (96ns)
                + 2.21
                (93ns)

                - 2.33
                (100ns)
                + 1.98
                (83ns)

                - 2.16
                (93ns)
                + 2.10
                (88ns)

                - 1.00
                (43ns)
                + 1.02
                (43ns)

                - 1.02
                (44ns)
                + 1.02
                (43ns)

                - 1.05
                (45ns)
                + 1.02
                (43ns)

                - 1.02
                (44ns)
                + 1.00
                (42ns)

                @@ -1402,42 +1402,42 @@

                - 1.00
                (89ns)
                + 1.07
                (90ns)

                - 1.02
                (91ns)
                + 1.15
                (97ns)

                - 1.09
                (97ns)
                + 1.08
                (91ns)

                - 1.17
                (104ns)
                + 1.00
                (84ns)

                - 1.46
                (130ns)
                + 1.45
                (122ns)

                - 1.51
                (134ns)
                + 1.46
                (123ns)

                - 1.46
                (130ns)
                + 1.45
                (122ns)

                - 1.42
                (126ns)
                + 1.45
                (122ns)

                @@ -1449,42 +1449,42 @@

                - 1.02
                (96ns)
                + 1.16
                (102ns)

                - 1.13
                (106ns)
                + 1.58
                (139ns)

                - 1.00
                (94ns)
                + 1.00
                (88ns)

                - 1.13
                (106ns)
                + 1.03
                (91ns)

                - 1.35
                (127ns)
                + 1.44
                (127ns)

                - 1.44
                (135ns)
                + 1.44
                (127ns)

                - 1.36
                (128ns)
                + 1.41
                (124ns)

                - 1.37
                (129ns)
                + 1.38
                (121ns)

                @@ -1496,42 +1496,42 @@

                - 1.00
                (101ns)
                + 1.29
                (121ns)

                - 1.30
                (131ns)
                + 1.44
                (135ns)

                - 1.14
                (115ns)
                + 1.01
                (95ns)

                - 1.04
                (105ns)
                + 1.00
                (94ns)

                - 1.40
                (141ns)
                + 1.38
                (130ns)

                - 1.28
                (129ns)
                + 1.36
                (128ns)

                - 1.32
                (133ns)
                + 1.33
                (125ns)

                - 1.32
                (133ns)
                + 1.36
                (128ns)

                @@ -1543,42 +1543,42 @@

                - 1.06
                (117ns)
                + 1.33
                (134ns)

                - 1.46
                (161ns)
                + 1.52
                (154ns)

                - 1.05
                (115ns)
                + 1.00
                (101ns)

                - 1.00
                (110ns)
                + 1.08
                (109ns)

                - 1.22
                (134ns)
                + 1.38
                (139ns)

                - 1.20
                (132ns)
                + 1.31
                (132ns)

                - 1.32
                (145ns)
                + 1.39
                (140ns)

                - 1.33
                (146ns)
                + 1.37
                (138ns)

                @@ -1590,42 +1590,42 @@

                - 1.08
                (142ns)
                + 1.18
                (141ns)

                - 1.23
                (163ns)
                + 1.45
                (172ns)

                - 1.00
                (132ns)
                + 1.00
                (119ns)

                - 1.12
                (148ns)
                + 1.08
                (128ns)

                - 1.08
                (143ns)
                + 1.13
                (135ns)

                - 1.11
                (146ns)
                + 1.26
                (150ns)

                - 1.21
                (160ns)
                + 1.26
                (150ns)

                - 1.20
                (159ns)
                + 1.27
                (151ns)

                @@ -1637,42 +1637,42 @@

                - 1.01
                (150ns)
                + 1.29
                (180ns)

                - 1.15
                (170ns)
                + 1.28
                (178ns)

                - 1.11
                (165ns)
                + 1.05
                (146ns)

                - 1.05
                (155ns)
                + 1.00
                (139ns)

                - 1.01
                (149ns)
                + 1.06
                (147ns)

                - 1.00
                (148ns)
                + 1.06
                (147ns)

                - 1.16
                (171ns)
                + 1.18
                (164ns)

                - 1.16
                (172ns)
                + 1.17
                (163ns)

                @@ -1684,42 +1684,42 @@

                - 1.19
                (178ns)
                + 1.28
                (187ns)

                - 1.32
                (196ns)
                + 1.28
                (187ns)

                - 1.16
                (173ns)
                + 1.06
                (155ns)

                - 1.14
                (170ns)
                + 1.05
                (154ns)

                - 1.00
                (149ns)
                + 1.03
                (151ns)

                - 1.01
                (151ns)
                + 1.00
                (146ns)

                - 1.21
                (180ns)
                + 1.19
                (174ns)

                - 1.49
                (222ns)
                + 1.47
                (215ns)

                @@ -1731,22 +1731,22 @@

                - 1.17
                (189ns)
                + 1.22
                (197ns)

                - 1.32
                (214ns)
                + 1.38
                (223ns)

                - 1.23
                (199ns)
                + 1.04
                (168ns)

                - 1.20
                (194ns)
                + 1.04
                (169ns)

                @@ -1756,12 +1756,12 @@

                - 1.02
                (165ns)
                + 1.04
                (169ns)

                - 1.41
                (228ns)
                + 1.22
                (198ns)

                @@ -1778,42 +1778,42 @@

                - 1.26
                (220ns)
                + 1.23
                (209ns)

                - 1.34
                (234ns)
                + 1.29
                (220ns)

                - 1.22
                (213ns)
                + 1.15
                (196ns)

                - 1.35
                (235ns)
                + 1.10
                (187ns)

                - 1.07
                (187ns)
                + 1.00
                (170ns)

                - 1.00
                (174ns)
                + 1.15
                (196ns)

                - 1.22
                (213ns)
                + 1.22
                (208ns)

                - 1.55
                (269ns)
                + 1.61
                (273ns)

                @@ -1825,42 +1825,42 @@

                - 1.22
                (234ns)
                + 1.28
                (242ns)

                - 1.29
                (247ns)
                + 1.39
                (262ns)

                - 1.29
                (247ns)
                + 1.15
                (218ns)

                - 1.30
                (250ns)
                + 1.14
                (216ns)

                - 1.08
                (208ns)
                + 1.00
                (189ns)

                - 1.00
                (192ns)
                + 1.01
                (191ns)

                - 1.44
                (277ns)
                + 1.49
                (282ns)

                - 1.56
                (299ns)
                + 1.53
                (290ns)

                @@ -1872,42 +1872,42 @@

                - 1.18
                (240ns)
                + 1.28
                (260ns)

                - 1.43
                (291ns)
                + 1.34
                (273ns)

                - 1.44
                (293ns)
                + 1.12
                (227ns)

                - 1.37
                (279ns)
                + 1.15
                (233ns)

                - 1.03
                (211ns)
                + 1.00
                (203ns)

                - 1.00
                (204ns)
                + 1.00
                (203ns)

                - 1.40
                (285ns)
                + 1.38
                (280ns)

                - 1.50
                (307ns)
                + 1.47
                (298ns)

                @@ -1919,42 +1919,42 @@

                - 1.66
                (357ns)
                + 1.35
                (288ns)

                - 1.72
                (369ns)
                + 1.40
                (300ns)

                - 1.29
                (277ns)
                + 1.22
                (261ns)

                - 1.27
                (273ns)
                + 1.18
                (252ns)

                - 1.00
                (215ns)
                + 1.00
                (214ns)

                - 1.19
                (256ns)
                + 1.23
                (264ns)

                - 1.46
                (314ns)
                + 1.43
                (305ns)

                - 1.55
                (334ns)
                + 1.52
                (325ns)

                @@ -1966,42 +1966,42 @@

                - 1.35
                (298ns)
                + 1.16
                (259ns)

                - 1.63
                (361ns)
                + 1.47
                (328ns)

                - 1.37
                (302ns)
                + 1.15
                (256ns)

                - 1.40
                (309ns)
                + 1.35
                (302ns)

                - 1.00
                (221ns)
                + 1.00
                (223ns)

                - 1.27
                (281ns)
                + 1.22
                (273ns)

                - 1.52
                (336ns)
                + 1.50
                (334ns)

                - 1.57
                (348ns)
                + 1.52
                (339ns)

                @@ -2013,42 +2013,42 @@

                - 1.32
                (316ns)
                + 1.10
                (273ns)

                - 1.60
                (382ns)
                + 1.46
                (363ns)

                - 1.26
                (300ns)
                + 1.10
                (273ns)

                - 1.45
                (347ns)
                + 1.75
                (434ns)

                - 1.00
                (239ns)
                + 1.00
                (248ns)

                - 1.23
                (294ns)
                + 1.30
                (322ns)

                - 1.50
                (358ns)
                + 1.41
                (349ns)

                - 1.56
                (373ns)
                + 1.46
                (363ns)

                @@ -2060,42 +2060,42 @@

                - 1.31
                (337ns)
                + 1.26
                (330ns)

                - 1.73
                (446ns)
                + 1.35
                (352ns)

                - 1.24
                (319ns)
                + 1.24
                (324ns)

                - 1.40
                (362ns)
                + 1.33
                (348ns)

                - 1.00
                (258ns)
                + 1.00
                (261ns)

                - 1.24
                (319ns)
                + 1.22
                (319ns)

                - 1.51
                (389ns)
                + 1.44
                (377ns)

                - 1.48
                (383ns)
                + 1.46
                (381ns)

                @@ -2107,42 +2107,42 @@

                - 1.35
                (364ns)
                + 1.24
                (330ns)

                - 1.51
                (408ns)
                + 1.60
                (427ns)

                - 1.18
                (319ns)
                + 1.22
                (327ns)

                - 1.44
                (390ns)
                + 1.56
                (416ns)

                - 1.00
                (270ns)
                + 1.00
                (267ns)

                - 1.22
                (329ns)
                + 1.19
                (317ns)

                - 1.52
                (411ns)
                + 1.57
                (418ns)

                - 1.52
                (411ns)
                + 1.56
                (416ns)

                diff --git a/doc/html/standalone_HTML.manifest b/doc/html/standalone_HTML.manifest index 13a783446..319e71a2f 100644 --- a/doc/html/standalone_HTML.manifest +++ b/doc/html/standalone_HTML.manifest @@ -40,7 +40,7 @@ math_toolkit/next_float/float_advance.html math_toolkit/next_float/ulp.html math_toolkit/float_comparison.html cstdfloat.html -math_toolkit/overview.html +math_toolkit/specified_typedefs.html math_toolkit/rationale.html math_toolkit/exact_typdefs.html math_toolkit/minimum_typdefs.html @@ -48,8 +48,9 @@ math_toolkit/fastest_typdefs.html math_toolkit/greatest_typdefs.html math_toolkit/macros.html math_toolkit/examples.html +math_toolkit/float128_hints.html math_toolkit/float128.html -math_toolkit/float128/overloading_template_functions_w.html +math_toolkit/float128/overloading.html math_toolkit/float128/exp_function.html math_toolkit/float128/typeinfo.html constants.html diff --git a/doc/math.qbk b/doc/math.qbk index 552a6e6d9..240496030 100644 --- a/doc/math.qbk +++ b/doc/math.qbk @@ -133,6 +133,7 @@ and use the function's name as the link text.] [def __multiprecision_root [link math_toolkit.roots.root_finding_examples.multiprecision_root multiprecision root]] [def __polynomial_arithmetic [link math_toolkit.roots.polynomial_arithmetic polynomial arithmetic]] [def __evaluation [link math_toolkit.roots.rational.polynomial_evaluation polynomial \& rational evaluation]] + [/gammas] [def __lgamma [link math_toolkit.sf_gamma.lgamma lgamma]] [def __digamma [link math_toolkit.sf_gamma.digamma digamma]] @@ -260,7 +261,6 @@ and use the function's name as the link text.] [def __float_advance [link math_toolkit.next_float.float_advance float_advance]] [def __ulp [link math_toolkit.next_float.ulp ulp]] - [/powers etc] [def __expm1 [link math_toolkit.powers.expm1 expm1]] [def __log1p [link math_toolkit.powers.log1p log1p]] @@ -296,6 +296,8 @@ and use the function's name as the link text.] [def __expint [link math_toolkit.expint.expint_i expint]] [def __spherical_harmonic [link math_toolkit.sf_poly.sph_harm spherical_harmonic]] [def __owens_t [link math_toolkit.owens_t Owens T]] +[def __constants_intro [link math_toolkit.constants_intro constants]] +[def __constants[link math_toolkit.constants constants]] [/tools] [def __tuple [link math_toolkit.internals.tuples boost::math::tuple]] @@ -369,9 +371,7 @@ and use the function's name as the link text.] [def __promotion_policy [link math_toolkit.pol_ref.internal_promotion internal promotion policy]] [def __precision_policy [link math_toolkit.pol_ref.precision_pol precision policy]] [def __policy_macros [link math_toolkit.pol_ref.policy_defaults Using Macros to Change the Policy Defaults]] -[def __random_variate [@http://en.wikipedia.org/wiki/Random_variate random variate]] -[def __random_variable [@http://en.wikipedia.org/wiki/Random_variable random variable]] -[def __probability_distribution [@http://en.wikipedia.org/wiki/Probability_distribution probability_distribution]] + [def __usual_accessors __cdf, __pdf, __quantile, __hazard, __chf, __mean, __median, __mode, __variance, __sd, __skewness, @@ -424,6 +424,10 @@ and use the function's name as the link text.] [def __guard_digits [@http://en.wikipedia.org/wiki/Guard_digit guard digits]] [def __SSE2 [@http://en.wikipedia.org/wiki/SSE2 SSE2 instructions]] [def __representable [@http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding representable]] +[def __short_float [@http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2016.pdf N2016 short float type]] +[def __random_variate [@http://en.wikipedia.org/wiki/Random_variate random variate]] +[def __random_variable [@http://en.wikipedia.org/wiki/Random_variable random variable]] +[def __probability_distribution [@http://en.wikipedia.org/wiki/Probability_distribution probability_distribution]] [/ Some composite templates] [template super[x]''''''[x]''''''] diff --git a/example/cstdfloat_example.cpp b/example/cstdfloat_example.cpp index 0509bea79..119532a08 100644 --- a/example/cstdfloat_example.cpp +++ b/example/cstdfloat_example.cpp @@ -1,6 +1,6 @@ // Copyright John Maddock 2014 // Copyright Christopher Kormanyos 2014. -// Copyright Paul A. Bristow 2014. +// Copyright Paul A. Bristow 2016. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file @@ -26,8 +26,8 @@ Dover, New York, 4th ed., (1945), pages 180-188. */ //[cstdfloat_example_1 -#include // For float_64_t. Must be first include! -#include // for pow function. +#include // For float_64_t, float128_t. Must be first include! +#include // for pow function. #include // For gamma function. //] [/cstdfloat_example_1] #include @@ -85,10 +85,10 @@ int main() std::cout.precision(std::numeric_limits::max_digits10); std::cout.setf(std::ios::showpoint); // Show trailing zeros. - + try { // Always use try'n'catch blocks to ensure any error messages are displayed. - + // Evaluate and display an evaluation of the Jahnke-Emden lambda function: boost::float64_t v = 1.; boost::float64_t x = 1.; @@ -110,7 +110,7 @@ int main() std::cout << std::setprecision(2) << boost::floatmax_t(i) << ' ' << std::setprecision(std::numeric_limits::max_digits10) << jahnke_emden_lambda(boost::floatmax_t(i), v) << std::endl; // - } + } } // Show the precision of long double (this might be 64, 80 or 128 bits). std::cout << "Floating-point type long double is available with:" << std::endl; @@ -121,32 +121,32 @@ int main() long double p = boost::math::constants::pi(); std::cout.precision(std::numeric_limits::digits10); std::cout << "pi = " << p << std::endl; - + //[cstdfloat_constant_2 //`These allow floating-point [*constants of at least the specified width] to be declared: - + // Declare Archimedes' constant using float32_t with approximately 7 decimal digits of precision. static const boost::float32_t pi = BOOST_FLOAT32_C(3.1415926536); // Declare the Euler-gamma constant with approximately 15 decimal digits of precision. - static const boost::float64_t euler = + static const boost::float64_t euler = BOOST_FLOAT64_C(0.57721566490153286060651209008240243104216); // Declare the Golden Ratio constant with the maximum decimal digits of precision that the platform supports. static const boost::floatmax_t golden_ratio = BOOST_FLOATMAX_C(1.61803398874989484820458683436563811772); -//] [/cstdfloat_constant_2] - -// http://www.boost.org/doc/libs/1_55_0/libs/multiprecision/doc/html/boost_multiprecision/tut/floats/float128.html +//] [/cstdfloat_constant_2] + +// http://www.boost.org/doc/libs/1_55_0/libs/multiprecision/doc/html/boost_multiprecision/tut/floats/float128.html //[cstdfloat_constant_1 // Display the constant pi to the maximum available precision. boost::floatmax_t pi_max = boost::math::constants::pi(); std::cout.precision(std::numeric_limits::digits10); std::cout << "Most precise pi = " << pi_max << std::endl; -// If floatmax_t is float_128_t, then -// Most precise pi = 3.141592653589793238462643383279503 -//] [/cstdfloat_constant_1] - +// If floatmax_t is float_128_t, then +// Most precise pi = 3.141592653589793238462643383279503 +//] [/cstdfloat_constant_1] + // Test all the floating-point precisions in turn, and if they are available // then display how many decimal digits of precision. #ifdef BOOST_FLOAT16_C @@ -154,7 +154,7 @@ int main() #else std::cout << "Floating-point type boost::float16_t is NOT available." << std::endl; #endif - + #ifdef BOOST_FLOAT32_C std::cout << "Floating-point type boost::float32_t is available." << std::endl; std::cout << " std::numeric_limits::digits10 == " @@ -164,7 +164,7 @@ int main() #else std::cout << "Floating-point type boost::float32_t is NOT available." << std::endl; #endif - + #ifdef BOOST_FLOAT64_C std::cout << "Floating-point type boost::float64_t is available." << std::endl; std::cout << " std::numeric_limits::digits10 == " @@ -174,7 +174,7 @@ int main() #else std::cout << "Floating-point type boost::float64_t is NOT available." << std::endl; #endif - + #ifdef BOOST_FLOAT80_C std::cout << "Floating-point type boost::float80_t is available." << std::endl; std::cout << " std::numeric_limits::digits10 == " @@ -184,7 +184,7 @@ int main() #else std::cout << "Floating-point type boost::float80_t is NOT available." << std::endl; #endif - + #ifdef BOOST_FLOAT128_C std::cout << "Floating-point type boost::float128_t is available." << std::endl; std::cout << " std::numeric_limits::digits10 == " @@ -204,7 +204,7 @@ int main() << BOOST_FLOAT16_C(123.456789012345678901234567890) << std::endl; // BOOST_FLOAT16_C(123.456789012345678901234567890) = 123.45678901234568 #endif - + //[floatmax_widths_1 #ifdef BOOST_FLOAT32_C std::cout.precision(boost::max_digits10()); // Show all significant decimal digits, @@ -238,18 +238,18 @@ int main() << BOOST_FLOAT128_C(123.4567890123456789012345678901234567890) << std::endl; // BOOST_FLOAT128_C(123.4567890123456789012345678901234567890) = 123.456789012345678901234567890123453 #endif - + /* //[floatmax_widths_2 BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) = 123.456787 BOOST_FLOAT64_C(123.4567890123456789012345678901234567890) = 123.45678901234568 BOOST_FLOAT80_C(123.4567890123456789012345678901234567890) = 123.456789012345678903 BOOST_FLOAT128_C(123.4567890123456789012345678901234567890) = 123.456789012345678901234567890123453 -//] [/floatmax_widths_2] +//] [/floatmax_widths_2] */ - -// Display the precisions available for floatmax_t - + +// Display the precisions available for floatmax_t + #ifdef BOOST_FLOATMAX_C BOOST_ASSERT(std::numeric_limits::is_specialized == true); BOOST_ASSERT(std::numeric_limits::is_iec559 == true); @@ -258,25 +258,25 @@ BOOST_FLOAT128_C(123.4567890123456789012345678901234567890) = 123.45678901234567 std::cout << "floatmax_t " << std::numeric_limits::digits << " bits\n" // 113 << std::numeric_limits::digits10 << " decimal digits\n" // 34 << std::numeric_limits::max_digits10 << " max_digits\n" // 36 - << std::numeric_limits::radix << " radix\n" + << std::numeric_limits::radix << " radix\n" << std::endl; - + int significand_bits = std::numeric_limits::digits; int exponent_max = std::numeric_limits::max_exponent; - int exponent_min = std::numeric_limits::min_exponent; + int exponent_min = std::numeric_limits::min_exponent; int exponent_bits = 1 + static_cast(std::log2(std::numeric_limits::max_exponent)); int sign_bits = std::numeric_limits::is_signed; - - std::cout << "significand_bits (including one implicit bit)" << significand_bits + + std::cout << "significand_bits (including one implicit bit)" << significand_bits << ", exponent_bits " << exponent_bits << ", sign_bits " << sign_bits << std::endl; - + // One can compute the total number of bits in the floatmax_t, // but probably not at compile time. - + std::cout << "bits = " << significand_bits + exponent_bits + sign_bits -1 << std::endl; // -1 to take account of the implicit bit that is not part of the physical layout. - + // One can compare typedefs (but, of course, only those that are defined for the platform in use.) std::cout.setf(std::ios::boolalpha); std::cout << "double, double: " << std::is_same::value << std::endl; @@ -286,10 +286,10 @@ BOOST_FLOAT128_C(123.4567890123456789012345678901234567890) = 123.45678901234567 << std::is_same::value << std::endl; /*`So the simplest way of obtaining the total number of bits in the floatmax_t -is to infer it from the std::numeric_limits<>::digits value. +is to infer it from the std::numeric_limits<>::digits value. This is possible because the type, must be a IEEE754 layout. */ -//[floatmax_1 - const int fpbits = +//[floatmax_1 + const int fpbits = (std::numeric_limits::digits == 113) ? 128 : (std::numeric_limits::digits == 64) ? 80 : (std::numeric_limits::digits == 53) ? 64 : @@ -299,10 +299,10 @@ This is possible because the type, must be a IEEE754 layout. */ std::cout << fpbits << " bits." << std::endl; //] [/floatmax_1] #endif - + } catch (std::exception ex) - { // Display details about why any exceptions are thrown. + { // Display details about why any exceptions are thrown. std::cout << "Thrown exception " << ex.what() << std::endl; } @@ -312,7 +312,7 @@ This is possible because the type, must be a IEEE754 layout. */ [cstdfloat_output GCC 4.8.1 with quadmath - + pi = 1.00000 0.88010117148986700 0.0 0.0000000000000000 @@ -371,6 +371,65 @@ GCC 4.8.1 with quadmath RUN SUCCESSFUL (total time: 53ms) +GCC 6.1.1 + +pi = 1.00000 +0.88010117148986700 +0.0 0.0000000000000000 +1.0 0.88010117148986700 +2.0 4.6137984620549872 +3.0 16.274830009244951 +4.0 -25.360637961042869 +5.0 -1257.9038883512264 +6.0 -12749.592182518225 +7.0 -3020.9830849309437 +8.0 2421897.6013183584 +9.0 45577595.449204877 +0.0 0.00000000000000000000000000000000000 +1.0 0.880101171489866995756301548681221902 +2.0 4.61379846205498722611082484945654869 +3.0 16.2748300092449511566883302293717861 +4.0 -25.3606379610428689375112298876047134 +5.0 -1257.90388835122644195507746189832687 +6.0 -12749.5921825182249449426308274269104 +7.0 -3020.98308493094373261556029319763184 +8.0 2421897.60131835844367742538452148438 +9.0 45577595.4492048770189285278320312500 +Floating-point type long double is available with: + std::numeric_limits::digits10 == 18 + std::numeric_limits::max_digits10 == 21 +pi = 3.14159265358979312 +Most precise pi = 3.14159265358979323846264338327950 +Floating-point type boost::float16_t is NOT available. +Floating-point type boost::float32_t is available. + std::numeric_limits::digits10 == 6 + std::numeric_limits::max_digits10 == 9 +Floating-point type boost::float64_t is available. + std::numeric_limits::digits10 == 15 + std::numeric_limits::max_digits10 == 17 +Floating-point type boost::float80_t is available. + std::numeric_limits::digits10 == 18 + std::numeric_limits::max_digits10 == 21 +Floating-point type boost::float128_t is available. + std::numeric_limits::digits10 == 33 + std::numeric_limits::max_digits10 == 36 +BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) = 123.456787 +BOOST_FLOAT64_C(123.4567890123456789012345678901234567890) = 123.45678901234568 +BOOST_FLOAT80_C(123.4567890123456789012345678901234567890) = 123.456789012345678903 +BOOST_FLOAT128_C(123.4567890123456789012345678901234567890) = 123.456789012345678901234567890123453 +floatmax_t 113 bits +33 decimal digits +36 max_digits +2 radix + +significand_bits (including one implicit bit)113, exponent_bits 15, sign_bits 1 +bits = 128 +double, double: true +boost::is_same::value; false +floatmax_t, float64_t: false +128 bits. + + MSVC 2013 64-bit 1> pi = 1.00000 diff --git a/example/float128_example.cpp b/example/float128_example.cpp new file mode 100644 index 000000000..418abf07b --- /dev/null +++ b/example/float128_example.cpp @@ -0,0 +1,296 @@ +// Copyright John Maddock 2016 +// Copyright Christopher Kormanyos 2016. +// Copyright Paul A. Bristow 2016. + +// 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) + +// Contains Quickbook snippets as C++ comments - do not remove. + +// http://gcc.gnu.org/onlinedocs/libquadmath/ GCC Quad-Precision Math Library +// https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format + +// https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options GNU 3.5 Options Controlling C++ Dialect +// https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options 3.4 Options Controlling C Dialect + +//[float128_includes_1 + +#include // For float_64_t, float128_t. Must be first include! +//#include +#include +#include // For gamma function. +#include // For constants pi, e ... +#include // + +#include // for pow function. + +// #include +// C:\program files\gcc-6-win64\lib\gcc\x86_64-w64-mingw32\6.1.1\include\quadmath.h + +// i:\modular-boost\boost\multiprecision\float128.hpp|210| undefined reference to `quadmath_snprintf'. + +//] [/float128_includes_1] + +//[float128_dialect_1 +/*`To make float128 available it is vital to get the dialect and options on the command line correct. + +Quad type is forbidden by all the strict C++ standards, so using or adding -std=c++11 and later standards will prevent its use. +so explicitly use -std=gnu++11, 1y, 14, , 1z or 17 ... + +For GCC 6.1.1, for example, the default is if no C++ language dialect options are given, is -std=gnu++14. + +See https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options +https://gcc.gnu.org/onlinedocs/gcc/Standards.html#Standards 2 Language Standards Supported by GCC + + g++.exe -Wall -fexceptions -std=gnu++17 -g -fext-numeric-literals -fpermissive -lquadmath + -II:\modular-boost\libs\math\include -Ii:\modular-boost -c J:\Cpp\float128\float128\float128_example.cpp -o obj\Debug\float128_example.o + +Requires GCC linker option -lquadmath + +If this is missing, then get errors like: + + \modular-boost\boost\multiprecision\float128.hpp|210|undefined reference to `quadmath_snprintf'| + \modular-boost\boost\multiprecision\float128.hpp|351|undefined reference to `sqrtq'| + +Requires compile option + + -fext-numeric-literals +If missing, then get errors like: + +\modular-boost\libs\math\include/boost/math/cstdfloat/cstdfloat_types.hpp:229:43: error: unable to find numeric literal operator 'operator""Q' + +A successful build log was: + + g++.exe -Wall -std=c++11 -fexceptions -std=gnu++17 -g -fext-numeric-literals -II:\modular-boost\libs\math\include -Ii:\modular-boost -c J:\Cpp\float128\float128\float128_example.cpp -o obj\Debug\float128_example.o + g++.exe -o bin\Debug\float128.exe obj\Debug\float128_example.o -lquadmath +*/ + +//] [/float128_dialect_1] + +void show_versions(std::string title) +{ + std::cout << title << std::endl; + + std::cout << "Platform: " << BOOST_PLATFORM << '\n' + << "Compiler: " << BOOST_COMPILER << '\n' + << "STL : " << BOOST_STDLIB << '\n' + << "Boost : " << BOOST_VERSION / 100000 << "." + << BOOST_VERSION / 100 % 1000 << "." + << BOOST_VERSION % 100 + << std::endl; +#ifdef _MSC_VER + std::cout << "_MSC_FULL_VER = " << _MSC_FULL_VER << std::endl; // VS 2015 190023026 +#if defined _M_IX86 + std::cout << "(x86)" << std::endl; +#endif +#if defined _M_X64 + std::cout << " (x64)" << std::endl; +#endif +#if defined _M_IA64 + std::cout << " (Itanium)" << std::endl; +#endif + // Something very wrong if more than one is defined (so show them in all just in case)! +#endif // _MSC_VER +#ifdef __GNUC__ +//PRINT_MACRO(__GNUC__); +//PRINT_MACRO(__GNUC_MINOR__); +//PRINT_MACRO(__GNUC_PATCH__); +std::cout << "GCC " << __VERSION__ << std::endl; +//PRINT_MACRO(LONG_MAX); +#endif // __GNUC__ + return; +} // void show_version(std::string title) + +int main() +{ + try + { + +//[float128_example_3 +// Always use try'n'catch blocks to ensure any error messages are displayed. +//`Ensure that all possibly significant digits (17) including trailing zeros are shown. + + std::cout.precision(std::numeric_limits::max_digits10); + std::cout.setf(std::ios::showpoint); // Show all significant trailing zeros. + //] [/ float128_example_3] + +#ifdef BOOST_FLOAT128_C + std::cout << "Floating-point type boost::float128_t is available." << std::endl; + std::cout << " std::numeric_limits::digits10 == " + << std::numeric_limits::digits10 << std::endl; + std::cout << " std::numeric_limits::max_digits10 == " + << std::numeric_limits::max_digits10 << std::endl; +#else + std::cout << "Floating-point type boost::float128_t is NOT available." << std::endl; +#endif + + show_versions(""); + + using boost::multiprecision::float128; // Wraps, for example, __float128 or _Quad. + // or + //using namespace boost::multiprecision; + + std::cout.precision(std::numeric_limits::max_digits10); // Show all potentially meaningful digits. + std::cout.setf(std::ios::showpoint); // Show all significant trailing zeros. + + // float128 pi0 = boost::math::constants::pi(); // Compile fails - need to specify a type for the constant! + + float128 pi1 = boost::math::constants::pi(); // Returns a constant of type float128. + std::cout << sqrt(pi1) << std::endl; // 1.77245385090551602729816748334114514 + + float128 pi2 = boost::math::constants::pi<__float128>(); // Constant of type __float128 gets converted to float128 on the assignment. + std::cout << sqrt(pi2) << std::endl; // 1.77245385090551602729816748334114514 + + // DIY decimal digit literal constant, with suffix Q. + float128 pi3 = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348Q; + std::cout << sqrt(pi3) << std::endl; // 1.77245385090551602729816748334114514 + + // Compare to ready-rolled sqrt(pi) constant from Boost.Math: + std::cout << boost::math::constants::root_pi() << std::endl; // 1.77245385090551602729816748334114514 + + // DIY decimal digit literal constant, without suffix Q, suffering seventeen silent digits loss of precision! + float128 pi4 = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348; + std::cout << sqrt(pi4) << std::endl; // 1.77245385090551599275151910313924857 + + // float128 variables constructed from a quad-type literal can be declared constexpr if required: + +#ifndef BOOST_NO_CXX11_CONSTEXPR + constexpr float128 pi_constexpr = 3.1415926535897932384626433832795028841971693993751058Q; +#endif + std::cout << pi_constexpr << std::endl; // 3.14159265358979323846264338327950280 + + // But sadly functions like sqrt are not yet available constexpr for float128. + + //constexpr float128 root_pi_constexpr = sqrt(pi_constexpr); // Fails - not constexpr (yet). + //constexpr float128 root_pi_constexpr = std::sqrt(pi_constexpr); // Fails - no know conversion for argument 1 from 'const float128'. + // constexpr float128 root_pi_constexpr = sqrt(pi_constexpr); // Call to non-constexpr + //constexpr float128 root_pi_constexpr = boost::math::constants::root_pi(); // Missing type for constant. + + // Best current way to get a constexpr is to use a Boost.Math constant if one is available. + constexpr float128 root_pi_constexpr = boost::math::constants::root_pi(); + std::cout << root_pi_constexpr << std::endl; // 1.77245385090551602729816748334114514 + + /* + inline _GLIBCXX_CONSTEXPR long double + sqrt(long double __x) + { return __builtin_sqrtl(__x); } + + Need a float128 version of __builtin_sqrt_128. + */ + + // Note that casts within the sqrt call are NOT NEEDED (nor allowed) + // since all the variables are the correct type to begin with. + // std::cout << sqrt(pi3) << std::endl; + // But note examples of catastrophic (but hard to see) loss of precision below. + + // Note also that the library functions, here sqrt, is NOT defined using std::sqrt, + // so that the correct overload is found using Argument Dependent LookUp (ADL). + + float128 ee = boost::math::constants::e(); + std::cout << ee << std::endl; // 2.71828182845904523536028747135266231 + + float128 e1 = exp(1.Q); // Note argument to exp is type float128. + std::cout << e1 << std::endl; // 2.71828182845904523536028747135266231 + + // Beware - it is all too easy to silently get a much lower precision by mistake. + + float128 e1d = exp(1.); // Caution - only double 17 decimal digits precision! + std::cout << e1d << std::endl; // 2.71828182845904509079559829842764884 + + float128 e1i = exp(1); // Caution int promoted to double so only 17 decimal digits precision! + std::cout << e1i << std::endl; // 2.71828182845904509079559829842764884 + + float f1 = 1.F; + float128 e1f = exp(f1); // Caution float so only 6 decimal digits precision out of 36! + std::cout << e1f << std::endl; // 2.71828174591064453125000000000000000 + + // In all these cases you get what you asked for and not what you expected or wanted. + + // Casting is essential if you start with a lower precision type. + + float128 e1q = exp(static_cast(f1)); // Full 36 decimal digits precision! + std::cout << e1q << std::endl; // 2.71828182845904523536028747135266231 + + float128 e1qc = exp((float128)f1); // Full 36 decimal digits precision! + std::cout << e1qc << std::endl; // 2.71828182845904523536028747135266231 + + float128 e1qcc = exp(float128(f1)); // Full 36 decimal digits precision! + std::cout << e1qcc << std::endl; // 2.71828182845904523536028747135266231 + + //float128 e1q = exp(1.); // Compile fails. + // std::cout << e1q << std::endl; // + +// http://en.cppreference.com/w/cpp/language/typeid +// The name()is implementation-dependent mangled, and may not be able to be output. +// The example showing output using one of the implementations where type_info::name prints full type names; +// filter through c++filt -t if using gcc or similar. + +//[float128_type_info +const std::type_info& tifu128 = typeid(__float128); // OK. +//std::cout << tifu128.name() << std::endl; // On GCC, aborts (because not printable string). +//std::cout << typeid(__float128).name() << std::endl; // Aborts - +// string name cannot be output. + +const std::type_info& tif128 = typeid(float128); // OK. +std::cout << tif128.name() << std::endl; // OK. +std::cout << typeid(float128).name() << std::endl; // OK. + +const std::type_info& tpi = typeid(pi1); // OK using GCC 6.1.1. +// (from GCC 5 according to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622) +std::cout << tpi.name() << std::endl; // OK, Output implementation-dependent mangled name: + +// N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE + +//] [/float128_type_info] + + } + catch (std::exception ex) + { // Display details about why any exceptions are thrown. + std::cout << "Thrown exception " << ex.what() << std::endl; + } +} // int main() + +/* +[float128_output + +-std=c++11 or -std=c++17 don't work + +Floating-point type boost::float128_t is NOT available. + +Platform: Win32 +Compiler: GNU C++ version 6.1.1 20160609 +STL : GNU libstdc++ version 20160609 +Boost : 1.62.0 +GCC 6.1.1 20160609 + + +Added -fext-numeric-literals to + +-std=gnu++11 -fext-numeric-literals -lquadmath + +Floating-point type boost::float128_t is available. + std::numeric_limits::digits10 == 33 + std::numeric_limits::max_digits10 == 36 + +Platform: Win32 +Compiler: GNU C++ version 6.1.1 20160609 +STL : GNU libstdc++ version 20160609 +Boost : 1.62.0 +GCC 6.1.1 20160609 +1.77245385090551602729816748334114514 +1.77245385090551602729816748334114514 +1.77245385090551602729816748334114514 +1.77245385090551602729816748334114514 +N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE +N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE +N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE + +Process returned 0 (0x0) execution time : 0.033 s +Press any key to continue. + + + +//] [/float128_output] + +*/ diff --git a/example/normal_tables.cpp b/example/normal_tables.cpp index b8ce5c8a0..ffdffbcd1 100644 --- a/example/normal_tables.cpp +++ b/example/normal_tables.cpp @@ -1,7 +1,7 @@ // normal_misc_examples.cpp -// Copyright Paul A. Bristow 2007, 2010, 2014. +// Copyright Paul A. Bristow 2007, 2010, 2014, 2016. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. @@ -19,25 +19,26 @@ First we need some includes to access the normal distribution */ #include // MUST be first include!!! +// See Implementation of Float128 type, Overloading template functions with float128_t. -#include // for normal_distribution +#include // for normal_distribution. using boost::math::normal; // typedef provides default type of double. #include - //using std::cout; using std::endl; + //using std::cout; using std::endl; //using std::left; using std::showpoint; using std::noshowpoint; #include //using std::setw; using std::setprecision; #include //using std::numeric_limits; - + /*! Function max_digits10 Returns maximum number of possibly significant decimal digits for a floating-point type FPT, even for older compilers/standard libraries that lack support for std::std::numeric_limits::max_digits10, when the Kahan formula 2 + binary_digits * 0.3010 is used instead. -Also provides the correct result for Visual Studio 2010 where the value provided for float is wrong. +Also provides the correct result for Visual Studio 2010 where the max_digits10 provided for float is wrong. */ namespace boost { @@ -47,7 +48,7 @@ template int max_digits10() { // Since max_digits10 is not defined (or wrong) on older systems, define a local max_digits10. - + // Usage: int m = max_digits10(); const int m = #if (defined BOOST_NO_CXX11_NUMERIC_LIMITS) || (_MSC_VER == 1600) // is wrongly 8 not 9 for VS2010. @@ -76,24 +77,25 @@ void normal_table() // is number of @b guaranteed digits, the other two digits being 'noisy'. // Here we use a custom version of max_digits10 which deals with those platforms // where @c std::numeric_limits is not specialized, - // or @c std::numeric_limits<>::max_digits10 not implemented, or wrong. + // or @c std::numeric_limits<>::max_digits10 not implemented, or wrong. int precision = boost::math::max_digits10(); -// std::cout << typeid(FPT).name() << std::endl; -// demo_normal.cpp:85: undefined reference to `typeinfo for __float128' +// std::cout << typeid(FPT).name() << std::endl; +// demo_normal.cpp:85: undefined reference to `typeinfo for __float128' // [@http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43622 GCC 43622] -// typeinfo for __float128 is still missing Mar 2014. - - // Construct a standard normal distribution s, with - normal s; // (default mean = zero, and standard deviation = unity) - std::cout << "\nStandard normal distribution, mean = "<< s.mean() +// typeinfo for __float128 was missing GCC 4.9 Mar 2014, but OK for GCC 6.1.1. + + // Construct a standard normal distribution s, with + // (default mean = zero, and standard deviation = unity) + normal s; + std::cout << "\nStandard normal distribution, mean = "<< s.mean() << ", standard deviation = " << s.standard_deviation() << std::endl; - - std::cout << "maxdigits_10 is " << precision + + std::cout << "maxdigits_10 is " << precision << ", digits10 is " << std::numeric_limits::digits10 << std::endl; std::cout << "Probability distribution function values" << std::endl; - + std::cout << " z " " PDF " << std::endl; for (FPT z = -range; z < range + step; z += step) { @@ -101,7 +103,7 @@ void normal_table() << std::setprecision(precision) << std::setw(12) << pdf(s, z) << std::endl; } std::cout.precision(6); // Restore to default precision. - + /*`And the area under the normal curve from -[infin] up to z, the cumulative distribution function (CDF). */ @@ -127,16 +129,16 @@ int main() try {// Tip - always use try'n'catch blocks to ensure that messages from thrown exceptions are shown. -//[normal_table_1 +//[normal_table_1 #ifdef BOOST_FLOAT32_C - normal_table(); + normal_table(); // Usually type float #endif - normal_table(); // Assume that float64_t is always available. + normal_table(); // Uusually type double. Assume that float64_t is always available. #ifdef BOOST_FLOAT80_C - normal_table(); + normal_table(); // Type long double on some X86 platforms. #endif #ifdef BOOST_FLOAT128_C - normal_table(); + normal_table(); // Type _Quad on some Intel and __float128 on some GCC platforms. #endif normal_table(); //] [/normal_table_1 ] @@ -145,7 +147,7 @@ int main() { std::cout << "exception thrown " << ex.what() << std::endl; } - + return 0; } // int main() @@ -153,13 +155,13 @@ int main() /* GCC 4.8.1 with quadmath - + Example: Normal distribution tables. Standard normal distribution, mean = 0, standard deviation = 1 maxdigits_10 is 9, digits10 is 6 Probability distribution function values - z PDF + z PDF -10 7.69459863e-023 -9 1.02797736e-018 -8 5.05227108e-015 @@ -169,9 +171,9 @@ Probability distribution function values -4 0.000133830226 -3 0.00443184841 -2 0.0539909665 --1 0.241970725 -0 0.39894228 -1 0.241970725 +-1 0.241970725 +0 0.39894228 +1 0.241970725 2 0.0539909665 3 0.00443184841 4 0.000133830226 @@ -183,7 +185,7 @@ Probability distribution function values 10 7.69459863e-023 Standard normal mean = 0, standard deviation = 1 Integral (area under the curve) from - infinity up to z. - z CDF + z CDF -10 7.61985302e-024 -9 1.12858841e-019 -8 6.22096057e-016 @@ -193,23 +195,23 @@ Integral (area under the curve) from - infinity up to z. -4 3.16712418e-005 -3 0.00134989803 -2 0.0227501319 --1 0.158655254 -0 0.5 -1 0.841344746 -2 0.977249868 -3 0.998650102 -4 0.999968329 -5 0.999999713 -6 0.999999999 -7 1 -8 1 -9 1 -10 1 +-1 0.158655254 +0 0.5 +1 0.841344746 +2 0.977249868 +3 0.998650102 +4 0.999968329 +5 0.999999713 +6 0.999999999 +7 1 +8 1 +9 1 +10 1 Standard normal distribution, mean = 0, standard deviation = 1 maxdigits_10 is 17, digits10 is 15 Probability distribution function values - z PDF + z PDF -10 7.6945986267064199e-023 -9 1.0279773571668917e-018 -8 5.0522710835368927e-015 @@ -233,7 +235,7 @@ Probability distribution function values 10 7.6945986267064199e-023 Standard normal mean = 0, standard deviation = 1 Integral (area under the curve) from - infinity up to z. - z CDF + z CDF -10 7.6198530241605945e-024 -9 1.1285884059538422e-019 -8 6.2209605742718204e-016 @@ -244,7 +246,7 @@ Integral (area under the curve) from - infinity up to z. -3 0.0013498980316300957 -2 0.022750131948179216 -1 0.15865525393145705 -0 0.5 +0 0.5 1 0.84134474606854293 2 0.97724986805182079 3 0.9986501019683699 @@ -253,13 +255,13 @@ Integral (area under the curve) from - infinity up to z. 6 0.9999999990134123 7 0.99999999999872013 8 0.99999999999999933 -9 1 -10 1 +9 1 +10 1 Standard normal distribution, mean = 0, standard deviation = 1 maxdigits_10 is 21, digits10 is 18 Probability distribution function values - z PDF + z PDF -10 7.69459862670641993759e-023 -9 1.0279773571668916523e-018 -8 5.05227108353689273243e-015 @@ -283,7 +285,7 @@ Probability distribution function values 10 7.69459862670641993759e-023 Standard normal mean = 0, standard deviation = 1 Integral (area under the curve) from - infinity up to z. - z CDF + z CDF -10 7.61985302416059451083e-024 -9 1.12858840595384222719e-019 -8 6.22096057427182035917e-016 @@ -294,7 +296,7 @@ Integral (area under the curve) from - infinity up to z. -3 0.00134989803163009566139 -2 0.0227501319481792155242 -1 0.158655253931457046468 -0 0.5 +0 0.5 1 0.841344746068542925777 2 0.977249868051820791415 3 0.998650101968369896532 @@ -303,13 +305,13 @@ Integral (area under the curve) from - infinity up to z. 6 0.999999999013412299576 7 0.999999999998720134897 8 0.999999999999999333866 -9 1 -10 1 +9 1 +10 1 Standard normal distribution, mean = 0, standard deviation = 1 maxdigits_10 is 36, digits10 is 34 Probability distribution function values - z PDF + z PDF -10 7.69459862670641993759264402330435296e-023 -9 1.02797735716689165230378750485667109e-018 -8 5.0522710835368927324337437844893081e-015 @@ -333,7 +335,7 @@ Probability distribution function values 10 7.69459862670641993759264402330435296e-023 Standard normal mean = 0, standard deviation = 1 Integral (area under the curve) from - infinity up to z. - z CDF + z CDF -10 7.61985302416059451083278826816793623e-024 -9 1.1285884059538422271881384555435713e-019 -8 6.22096057427182035917417257601387863e-016 @@ -344,7 +346,7 @@ Integral (area under the curve) from - infinity up to z. -3 0.001349898031630095661392854111682027 -2 0.0227501319481792155241528519127314212 -1 0.158655253931457046467912164189328905 -0 0.5 +0 0.5 1 0.841344746068542925776512220181757584 2 0.977249868051820791414741051994496956 3 0.998650101968369896532351503992686048 @@ -353,13 +355,13 @@ Integral (area under the curve) from - infinity up to z. 6 0.999999999013412299575520592043176293 7 0.999999999998720134897212119540199637 8 0.999999999999999333866185224906075746 -9 1 -10 1 +9 1 +10 1 Standard normal distribution, mean = 0, standard deviation = 1 maxdigits_10 is 36, digits10 is 34 Probability distribution function values - z PDF + z PDF -10 7.69459862670641993759264402330435296e-023 -9 1.02797735716689165230378750485667109e-018 -8 5.0522710835368927324337437844893081e-015 @@ -383,7 +385,7 @@ Probability distribution function values 10 7.69459862670641993759264402330435296e-023 Standard normal mean = 0, standard deviation = 1 Integral (area under the curve) from - infinity up to z. - z CDF + z CDF -10 7.61985302416059451083278826816793623e-024 -9 1.1285884059538422271881384555435713e-019 -8 6.22096057427182035917417257601387863e-016 @@ -394,7 +396,7 @@ Integral (area under the curve) from - infinity up to z. -3 0.001349898031630095661392854111682027 -2 0.0227501319481792155241528519127314212 -1 0.158655253931457046467912164189328905 -0 0.5 +0 0.5 1 0.841344746068542925776512220181757584 2 0.977249868051820791414741051994496956 3 0.998650101968369896532351503992686048 @@ -403,8 +405,8 @@ Integral (area under the curve) from - infinity up to z. 6 0.999999999013412299575520592043176293 7 0.999999999998720134897212119540199637 8 0.999999999999999333866185224906075746 -9 1 -10 1 +9 1 +10 1 MSVC 2013 64-bit 1> diff --git a/example/quadmath_snprintf.c b/example/quadmath_snprintf.c new file mode 100644 index 000000000..dff9aee59 --- /dev/null +++ b/example/quadmath_snprintf.c @@ -0,0 +1,93 @@ +// Original source file copyright gcc.gnu.org, GNU Free Documentation License, Version 1.3. + +// Notes for Boost.Math, (contains Quickbook snippets as C/C++ comments - do not remove!) +// Copyright Paul Bristow 2016. +// Distributed under 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) + + +//[quadmath_snprintf_1 +/*`Example of using GCC Quad-Precision Math Library quadmath `__float128` type, +taking a square root with sqrtq, and output using quadmath_snprintf. + +From GCC Quad-Precision Math Library, +[@https://gcc.gnu.org/onlinedocs/libquadmath.pdf 3.2 quadmath_snprintf, Convert to string] +(pages 9 and 10). + +Requires GCC linker option `-lquadmath`. + +If this linker option is missing then you will get errors like: +`` + /Cpp/float128/quadmath_snprintf/quadmath_snprintf.c:44: undefined reference to 'sqrtq'. + /Cpp/float128/quadmath_snprintf/quadmath_snprintf.c:45: undefined reference to 'quadmath_snprintf'. +`` +On one system, the header file (that contains all the `extern` declarations), included, for example: +`` + extern __float128 sqrtq (__float128) __quadmath_throw; + extern __float128 strtoflt128 (const char *, char **) __quadmath_throw; + extern int quadmath_snprintf (char *str, size_t size, const char *format, ...) __quadmath_throw; +`` +An example of a location of `quadmath.h` is +`` + C:\program files\gcc-6-win64\lib\gcc\x86_64-w64-mingw32\6.1.1\include\quadmath.h + `` +and library at +`` + C:\Program Files\gcc-6-win64\bin\libquadmath-0.dll +`` + +Command lines used (using [@http://www.codeblocks.org CodeBLocks]: +`` +gcc.exe -Wall -g -c J:\Cpp\float128\quadmath_snprintf\main.c -o obj\Debug\main.o +g++.exe -o bin\Debug\quadmath_snprintf.exe obj\Debug\main.o -lquadmath +`` +*/ +//] [/quadmath_snprintf_1] + +#include +#include +#include + +int main () +{ + __float128 r; + int prec = 20; + + int width = 46; + char buf[128]; + r = 2.0q; + r = sqrtq (r); + int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r); + if ((size_t) n < sizeof buf) + printf ("%s\n", buf); + /* Prints: +1.41421356237309504880e+00 */ + quadmath_snprintf (buf, sizeof buf, "%Qa", r); + if ((size_t) n < sizeof buf) + printf ("%s\n", buf); + /* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */ + n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r); + if (n > -1) + { + char *str = malloc (n + 1); + if (str) + { + quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r); + printf ("%s\n", str); + /* Prints: +1.41421356237309504880e+00 */ + } + free (str); + } + return 0; +} + +/* + +Output: + ++1.41421356237309504880e+00 +0x1.6a09e667f3bcc908b2fb1366ea96p+0 ++1.41421356237309504880e+00 + +*/ +