[multiprecision] static_cast<cpp_bin_float_100> gives strange values.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[multiprecision] static_cast<cpp_bin_float_100> gives strange values.

Boost - Users mailing list
Hi everyone.
The following Situation:

I tried to improve the accuracy of a numerical function by replacing all
double variables with cpp_bin_float_100.
The parameters of this function contain two 3-element double arrays,
which I convert to cpp_bin_float_100 by the following function:

static void equal(cpp_bin_float_100* a, double* b)
{

        for(int i=0; i<3;i++)
        {
                a[i]=static_cast<cpp_bin_float_100>(b[i]);
        }
}

the third element seems to be converted correctly, the first and second
are totally off. (e. g. 100 -> 1.5625)
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [multiprecision] static_cast<cpp_bin_float_100> gives strange values.

Boost - Users mailing list


On 20/04/2018 16:44, Vögl, Christian via Boost-users wrote:

> Hi everyone.
> The following Situation:
>
> I tried to improve the accuracy of a numerical function by replacing
> all double variables with cpp_bin_float_100.
> The parameters of this function contain two 3-element double arrays,
> which I convert to cpp_bin_float_100 by the following function:
>
> static void equal(cpp_bin_float_100* a, double* b)
> {
>
>     for(int i=0; i<3;i++)
>     {
>         a[i]=static_cast<cpp_bin_float_100>(b[i]);
>     }
> }
>
> the third element seems to be converted correctly, the first and
> second are totally off. (e. g. 100 -> 1.5625)

Well that's strange, I suspect that something else is going on here, and
I would need a self-contained test case to investigate.

BTW, the static_cast is unnecessary in this situation, and creates a
not-needed cpp_bin_float_100 temporary (narrow-to-wider conversions are
always implicit in the library).

Best, John.

---
This email has been checked for viruses by AVG.
http://www.avg.com

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users