Re: [Bug?] Vector view

2020-03-25 Thread Jeremy Theler
AFAIK, doubles have approx 15-16 decimal digits of precision.
I think your assignment q_test[0]=1.12348; is actually

q_test[0] = 1.12348000341771055900608189

I bet that if you expand 1.12348 as an actual base-2 IEEE floating-
point representation you'll see the point.

--
jeremy theler
www.seamplex.com


On Wed, 2020-03-25 at 20:19 +, Huynh, Hoai Nam wrote:
> <
> https://stackoverflow.com/posts/60794220/timeline
> >
> 
> Hello,
> 
> 
>Would you please answer the question below regarding
> gsl_vector_view_array() ?
> 
> 
> Using the GSL (GNU Scientific Library), I'm trying to understand why
> gsl_vector_view_array() returns a slighly modified value after
> assignment.
> 
> In the code below, I declare a vector_view 'qview_test' which is
> linked to table q_test[0]=0.0 and display its value which is 0.0.
> Then, I change the value of q_test[0]=1.12348 and expecting the same
> value for qview_test, but it gets alterated to
> qview_test=1.12348000341771055900608189.
> 
> How do you explain such a result ? How to replicate the result
> without GSL (for ex. with Matlab) ?
> 
> #include 
> #include 
> using namespace std;
> 
> double q_test[1]={0.0};
> gsl_vector_view qview_test;
> 
> int nb_variable = 1;
> 
> int main()
> {
> 
> qview_test=gsl_vector_view_array(q_test,nb_variable);
> 
> cout.precision(35);
> cout << "qview before: " <<
> gsl_vector_get(&qview_test.vector,0)<< endl;
> 
> // Assign value
> q_test[0]=1.12348;
> 
> cout << "qview after: " << gsl_vector_get(&qview_test.vector,0)
> << endl;
> 
> return 0;
> }
> 
> Thanks,
> 
> 
> Best regards,
> 
> Dr. Hoai Nam HUYNH
> 
> Postdoctoral fellow
> 
> 
> 
> The University of British Columbia
> 
> Department of Mechanical Engineering
> 
> Manufacturing Automation Laboratory
> 
> 2366 Main Mall (ICICS Room 091)
> 
> Vancouver BC V6T 1Z4 Canada
> 
> Phone: +1 604-827-4370
> 
> www.mal.mech.ubc.ca >
> 
> [UBC E-mail Signature]
> 
> 




[Bug?] Vector view

2020-03-25 Thread Huynh, Hoai Nam


Hello,


   Would you please answer the question below regarding gsl_vector_view_array() 
?


Using the GSL (GNU Scientific Library), I'm trying to understand why 
gsl_vector_view_array() returns a slighly modified value after assignment.

In the code below, I declare a vector_view 'qview_test' which is linked to 
table q_test[0]=0.0 and display its value which is 0.0. Then, I change the 
value of q_test[0]=1.12348 and expecting the same value for qview_test, but it 
gets alterated to qview_test=1.12348000341771055900608189.

How do you explain such a result ? How to replicate the result without GSL (for 
ex. with Matlab) ?

#include 
#include 
using namespace std;

double q_test[1]={0.0};
gsl_vector_view qview_test;

int nb_variable = 1;

int main()
{

qview_test=gsl_vector_view_array(q_test,nb_variable);

cout.precision(35);
cout << "qview before: " << gsl_vector_get(&qview_test.vector,0)<< endl;

// Assign value
q_test[0]=1.12348;

cout << "qview after: " << gsl_vector_get(&qview_test.vector,0) << endl;

return 0;
}

Thanks,


Best regards,

Dr. Hoai Nam HUYNH

Postdoctoral fellow



The University of British Columbia

Department of Mechanical Engineering

Manufacturing Automation Laboratory

2366 Main Mall (ICICS Room 091)

Vancouver BC V6T 1Z4 Canada

Phone: +1 604-827-4370

www.mal.mech.ubc.ca

[UBC E-mail Signature]

#include 
#include 
using namespace std;

double q_test[1]={0.0};
gsl_vector_view qview_test;

int nb_variable = 1;

int main()
{

qview_test=gsl_vector_view_array(q_test,nb_variable);

cout.precision(35);
cout << "qview before: " << gsl_vector_get(&qview_test.vector,0)<< endl;

// Assign value
q_test[0]=1.12348;

cout << "qview after: " << gsl_vector_get(&qview_test.vector,0) << endl;

return 0;
}