|
Ublas : |
Subject: Re: [ublas] Return type of 'mean_square'
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2015-08-18 11:14:34
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 <nasos_i_at_[hidden]> 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
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: athanasios.iliopoulos.ctr.gr_at_[hidden]
>
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: marco.guazzone_at_[hidden]