Boost logo

Boost Users :

Subject: Re: [Boost-users] boost/multiprecision/float128
From: Cooper, Bridgette R D (b.cooper_at_[hidden])
Date: 2016-04-30 13:38:15


Hi Paul,

For a moment I thought that worked. It certainly does for log(2). I distinctly get two different values (with the first giving the "correct" value) if I try:

        std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10) << log(float128(2.q)) << std::endl;

        std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10) << log(2.q) << std::endl;

However, this isn't true for sqrt still. I checked by calculating the sqrt(pi) and comparing to

https://github.com/ned14/boost-trunk/blob/master/libs/multiprecision/test/test_sqrt.cpp

        std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10) << sqrt(float128(pie)) << std::endl;

        std::cout << std::setprecision(std::numeric_limits<float128>::max_digits10) << sqrt(pie) << std::endl;

These two lines give me identical results and again only match the first 16 digits.

pie is defined as float128 and I copy/pasted the 100 digit value from the same test_sqrt.cpp given above.

Thanks for your help.

________________________________
From: Boost-users <boost-users-bounces_at_[hidden]> on behalf of Paul A. Bristow <pbristow_at_[hidden]>
Sent: Saturday, April 30, 2016 5:57:41 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] boost/multiprecision/float128

From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Cooper, Bridgette R D
Sent: 30 April 2016 12:32
To: boost-users_at_[hidden]
Subject: [Boost-users] boost/multiprecision/float128

I'm new to boost. I am trying to use the float128 type for calculating sqrts as a larger part of code, however I am not sure the values obtained are accurate to float128 precision. I have tried running the example for printing log(2) found here, I find the same for sqrt:

http://www.boost.org/doc/libs/1_57_0/libs/multiprecision/doc/html/boost_multiprecision/tut/floats/float128.html

However, the value printed log(2) only agrees to 16 decimal places, i.e. double precision. The value I obtain is

0.693147180559945286226763982995180413 rather than 0.693147180559945309417232121458176575

I'm using:

g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15) with boost 1.57.0.

Any advice as to what I am doing incorrectly?

My compile line is:

g++ -I ~/$BOOSTLIB new.cpp -lquadmath -o new

You don't give your exact code but I suspect that you have fallen into what is an annoying (but unavoidable) pit that is eagerly awaiting the unwary.

(Been there, done that - more than once!)

You need to ensure that *all* values processed really are float128 or other multiprecision types by construction or casting, for example log(float128(2)).

(Otherwise computation will take place in double precision and only then be converted to float128 and printed, as you observe).

HTH

Paul



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