Boost logo

Boost Users :

From: pbristow_at_[hidden]
Date: 2020-08-17 09:46:52


> -----Original Message-----
> From: Boost-users <boost-users-bounces_at_[hidden]> On Behalf Of John Maddock via Boost-users
> Sent: 16 August 2020 21:24
> To: Anirban Pal via Boost-users <boost-users_at_[hidden]>
> Cc: John Maddock <jz.maddock_at_[hidden]>
> Subject: Re: [Boost-users] limited accuracy for tanh-sinh integrator
>
>
> On 16/08/2020 21:15, Anirban Pal via Boost-users wrote:
> >
> > Hello,
> >
> > I’m using the tanh-sinh integrator to integrate a simple function f(x)
> > = 0.26*x from 3.0 to 4.0.
> > The exact result is 0.91. With the integrator I’m getting a result
> > accurate to only 10^-18 with cpp_bin_float_100 multiprecision.
> >
> You have the double precision constant 0.26 in your code, and since this is an inexact binary value,
> everything that depends on that constant is inherently limited to double precision. Try constructing it
> as Real(26) / 100.

Everyone falls into this pit, and in my case, repeatedly ☹

You need to be ever vigilant not to use double precision items by mistake.

Using numeric_limits<>::max_digits10 is useful because it shows the digits beyond double at about 17 decimal digits. Being random should raise suspicions.

If you are only using multiprecision types, then always using decimal digit strings like "1.23456" is simple.

If you can use a fraction like Real(1)/1000 that also works fine.

You may also find the macro BOOST_MATH_TEST_VALUE in I:\boost\libs\math\test\test_value.hpp helpful if you want to make code portable over different floating-point types from fundamental to multiprecision?

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