Re: Return type of 'mean_square'

Marco Guazzone <[email protected]>
Newsgroups gmane.comp.lib.boost.ublas
Message-ID <CABbE_O5ZYcpfKN-adbvrtNJd+8fgKA_mWJkqES3fB_ZqrxBWvw@mail.gmail.com>
Don't know enough detail about the mean_square function, but what if
AE::value_type is a long double?

Maybe you could use type deduction like the following:

   typename ublas::promote_traits<typename AE::value_type,double>::promote_type

I've written the following example:

--- [snip] ---
#include <boost/numeric/ublas/traits.hpp>
#include <iostream>

void foo(long double x)
{
    (void)x;
    std::cout << "LONG DOUBLE" << std::endl;
}
void foo(double x)
{
    (void)x;
    std::cout << "DOUBLE" << std::endl;
}

int main()
{
    namespace ublas = boost::numeric::ublas;

    std::cout << "long double vs. double -> ";
    ublas::promote_traits<long double,double>::promote_type ld_d = 0;
    foo(ld_d);
    std::cout << std::endl;

    std::cout << "int vs. double -> ";
    ublas::promote_traits<int,double>::promote_type i_d = 0;
    foo(i_d);
    std::cout << std::endl;

    std::cout << "long vs. double -> ";
    ublas::promote_traits<long,double>::promote_type l_d = 0;
    foo(l_d);
    std::cout << std::endl;
}
--- [/snip] ---

I've compiled on my machine (Linux 64bit with GCC 5.1.1 20150618 (Red
Hat 5.1.1-4)) with flags "-Wall -Wextra -ansi -pedantic", and the
result is:

long double vs. double -> LONG DOUBLE

int vs. double -> DOUBLE

long vs. double -> DOUBLE


Marco

On Tue, Aug 18, 2015 at 4:35 PM, Nasos Iliopoulos <[email protected]> wrote:
> I was debating this myself. I think converting to double is a good idea.
>
> -Nasos
>
> you cast the type do double before.
>
>
> On 08/10/2015 11:40 AM, Joaquim Duran Comas wrote:
>
> Hello,
>
> Few days ago, I patched the function 'mean_square' for vectors and matrices.
> Currently, the current return type of the function is AE::value_type. To get
> better accuracy, is it better return double type than AE::value_type
> (specially if it is an integuer)?
>
> Joaquim Duran
>
>
>
> _______________________________________________
> ublas mailing list
> [email protected]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: [email protected]
>
>
>
> _______________________________________________
> ublas mailing list
> [email protected]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.