[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug?] Vector view
From: |
Huynh, Hoai Nam |
Subject: |
[Bug?] Vector view |
Date: |
Wed, 25 Mar 2020 20:19:50 +0000 |
<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.1234800000000000341771055900608189.
How do you explain such a result ? How to replicate the result without GSL (for
ex. with Matlab) ?
#include <iostream>
#include <gsl/gsl_blas.h>
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<http://www.mal.mech.ubc.ca/>
[UBC E-mail Signature]
Test_View.cpp
Description: Test_View.cpp
- [Bug?] Vector view,
Huynh, Hoai Nam <=