Boost logo

Boost Users :

From: John Maddock (jz.maddock_at_[hidden])
Date: 2021-11-26 19:20:02


On 26/11/2021 17:50, Jacques Mequin via Boost-users wrote:
>
> I am a fresh new user   ( I need to extend some EIGEN library feature
> by using your float128 )
>
> How to assign a "float128" variable with a regular "double" variable ?
>
> With my source code in attachement
>
>       double       double_pi =  3.141592653589793     ;
>       float128  float128_pi =  3.141592653589793Q  ;
>
>       produces the output that looks fine to me
>
>       double_pi =
>       3.141592653589793e+00
>
>       float128_pi =
>       3.141592653589793000000000000000000e+00
>
> but  thestatement    float128_pi = double_pi ;    produces
>
>       float128_pi =
> 3.141592653589793115997963468544185e+00
>
> How to get 3.141592653589793000000000000000000e+00 also from an
> assigment  ???

You can't: remember your double has 53-bit precision, 3.141592653589793
is it's decimal value ROUNDED to 16 decimal places (note that you would
have to print more digits than that to be able to round-trip to and from
decimal), converting to a float128_t gives you EXACTLY the same binary
value, but you're code is now printing out more decimal places, so
you're seeing it's "true" decimal value, rather than the rounded value
you had before from the double output.

Hope that makes sense, John.

-- 
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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