Boost logo

Boost Users :

From: Stefano Gragnani (stefano.gragnani_at_[hidden])
Date: 2021-07-21 18:07:27


further clarification if possible:

why the 2 lines that don't compile:

// float128 e1 = exp(1.Q); // Note argument to exp is type float128.
// std::cout << e1 << std::endl; // 2.71828182845904523536028747135266231

 if i put them in the following code compile regularly?

#include <iomanip>
#include <iostream>

#include <boost/cstdfloat.hpp> // For float_64_t, float128_t. Must be first include!
#include <boost/multiprecision/float128.hpp>
#include <boost/math/special_functions.hpp> // For gamma function.
#include <boost/math/constants/constants.hpp> // For constants pi, e ...
#include <typeinfo>
#include <cmath> // for pow function.

using namespace std;

int main()
{
   using boost::multiprecision::float128;

   // Operations at 128-bit precision and full numeric_limits support:
   float128 b = 2;
   // There are 113-bits of precision:
   std::cout << std::numeric_limits<float128>::digits << std::endl;
   // Or 34 decimal places:
   std::cout << std::numeric_limits<float128>::digits10 << std::endl;
   // We can use any C++ std lib function, lets print all the digits as well:
   std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10) << log(b) << std::endl; // print log(2) = 0.693147180559945309417232121458176575
   // We can also use any function from Boost.Math:
   std::cout << boost::math::tgamma(b) << std::endl;
   // And since we have an extended exponent range we can generate some really large
   // numbers here (4.02387260077093773543702433923004111e+2564):
   std::cout << boost::math::tgamma(float128(1000)) << std::endl;
   //
   // We can declare constants using GCC or Intel's native types, and the Q suffix,
   // these can be declared constexpr if required:

   constexpr float128 pi = 3.1415926535897932384626433832795028841971693993751058Q;

   float128 e1 = exp(1.Q); // Note argument to exp is type float128.
   std::cout << e1 << std::endl; // 2.71828182845904523536028747135266231

   cout << "pi = " << pi << endl;
   cout << "e1 = " << e1 << endl;
   return 0;
}

> Executing task: ./main <

113
33
0.693147180559945309417232121458176575
1
4.02387260077093773543702433923004111e+2564
2.71828182845904523536028747135266231
pi = 3.1415926535897932384626433832795028
e1 = 2.71828182845904523536028747135266231

Thanks

> Il giorno 21 lug 2021, alle ore 19:14, Stefano Gragnani <stefano.gragnani_at_[hidden]> ha scritto:
>
> // float128 e1 = exp(1.Q); // Note argument to exp is type float128.
> // std::cout << e1 << std::endl; // 2.71828182845904523536028747135266231



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net