As a rookie programmer I'm struggling with type conversion from double to float. I know the easiest is to declare both as double, but that won't work. I have one libabry in single- and another in double precision. The questions are indicated below:
======================================
main ()
{
int i;
float* t;
double a;
typedef struct {
double* user_t;
} lm_data_type;
lm_data_type data;
t=(float *)malloc( (N_POINTS+1)*sizeof(float));
// generate data
for (i=0; i<N_POINTS; i++) {
t = (double) i ;
}
data.user_t = (double*) t; // how can I correctly do the type conversion here?
for (i=0; i<N_POINTS; i++) {
a = data.user_t; // Is this right????????
printf ("%6.3f %6.3f \n", t, a );
}
free(t);
return 0;
}
======================================
main ()
{
int i;
float* t;
double a;
typedef struct {
double* user_t;
} lm_data_type;
lm_data_type data;
t=(float *)malloc( (N_POINTS+1)*sizeof(float));
// generate data
for (i=0; i<N_POINTS; i++) {
t = (double) i ;
}
data.user_t = (double*) t; // how can I correctly do the type conversion here?
for (i=0; i<N_POINTS; i++) {
a = data.user_t; // Is this right????????
printf ("%6.3f %6.3f \n", t, a );
}
free(t);
return 0;
}