Skip to content

Commit

Permalink
Fix most float conversion warnings
Browse files Browse the repository at this point in the history
Fixes ~200 out of ~240 `-Wfloat-conversion` warnings on gcc 13.2
  • Loading branch information
ZedThree committed Oct 26, 2023
1 parent cb61d34 commit 763e54f
Show file tree
Hide file tree
Showing 36 changed files with 136 additions and 135 deletions.
2 changes: 1 addition & 1 deletion examples/C/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ main()
/* Create a bunch of phoney data so we have something to write in
the example file. */
for (fp=(float *)temp, i=0; i<LAT_LEN*LON_LEN; i++)
*fp++ = 10. + i/10.;
*fp++ = 10.f + (float)i/10.f;

/* Now create the file in both formats with the same code. */
for (i=0; i<2; i++)
Expand Down
16 changes: 8 additions & 8 deletions examples/C/pres_temp_4D_wr.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
#define DEGREES_NORTH "degrees_north"

/* These are used to construct some example data. */
#define SAMPLE_PRESSURE 900
#define SAMPLE_TEMP 9.0
#define START_LAT 25.0
#define START_LON -125.0
#define SAMPLE_PRESSURE 900.0f
#define SAMPLE_TEMP 9.0f
#define START_LAT 25.0f
#define START_LON -125.0f

/* For the units attributes. */
#define UNITS "units"
Expand Down Expand Up @@ -87,16 +87,16 @@ main()
* would have some real data to write, for example, model
* output. */
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5.*lat;
lats[lat] = START_LAT + 5.f*(float)lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5.*lon;
lons[lon] = START_LON + 5.f*(float)lon;

for (lvl = 0; lvl < NLVL; lvl++)
for (lat = 0; lat < NLAT; lat++)
for (lon = 0; lon < NLON; lon++)
{
pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + i;
temp_out[lvl][lat][lon] = SAMPLE_TEMP + i++;
pres_out[lvl][lat][lon] = SAMPLE_PRESSURE + (float)i;
temp_out[lvl][lat][lon] = SAMPLE_TEMP + (float)i++;
}

/* Create the file. */
Expand Down
16 changes: 8 additions & 8 deletions examples/C/sfc_pres_temp_wr.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
#define DEGREES_NORTH "degrees_north"

/* These are used to construct some example data. */
#define SAMPLE_PRESSURE 900
#define SAMPLE_TEMP 9.0
#define START_LAT 25.0
#define START_LON -125.0
#define SAMPLE_PRESSURE 900.0f
#define SAMPLE_TEMP 9.0f
#define START_LAT 25.0f
#define START_LON -125.0f

/* Handle errors by printing an error message and exiting with a
* non-zero status. */
Expand Down Expand Up @@ -78,15 +78,15 @@ main()
* would have some real data to write, for example, model
* output. */
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5.*lat;
lats[lat] = START_LAT + 5.f*(float)lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5.*lon;
lons[lon] = START_LON + 5.f*(float)lon;

for (lat = 0; lat < NLAT; lat++)
for (lon = 0; lon < NLON; lon++)
{
pres_out[lat][lon] = SAMPLE_PRESSURE + (lon * NLAT + lat);
temp_out[lat][lon] = SAMPLE_TEMP + .25 * (lon * NLAT + lat);
pres_out[lat][lon] = SAMPLE_PRESSURE + (float)(lon * NLAT + lat);
temp_out[lat][lon] = SAMPLE_TEMP + .25f * (float)(lon * NLAT + lat);
}

/* Create the file. */
Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_atts3.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ main()
if (!(cvc_out[i].data[j].p = calloc(sizeof(struct s1), cvc_out[i].data[j].len))) ERR;
for (k = 0; k < cvc_out[i].data[j].len; k++)
{
((struct s1 *)cvc_out[i].data[j].p)[k].x = 42.42;
((struct s1 *)cvc_out[i].data[j].p)[k].x = 42.42f;
((struct s1 *)cvc_out[i].data[j].p)[k].y = 2.0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_atts4.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ main()
if (!(vc_out[i].p = calloc(sizeof(struct s1), vc_out[i].len))) ERR;
for (k = 0; k < vc_out[i].len; k++)
{
((struct s1 *)vc_out[i].p)[k].x = 42.42;
((struct s1 *)vc_out[i].p)[k].x = 42.42f;
((struct s1 *)vc_out[i].p)[k].y = 2.0;
}
}
Expand Down
24 changes: 12 additions & 12 deletions h5_test/tst_h_compounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ main()
/* Initialize data. */
for (i = 0; i < DIM6_LEN; i++)
{
obsdata[i].day = 15 * i + 1;
obsdata[i].elev = 2 * i + 1;
obsdata[i].day = 15 * (char)i + 1;
obsdata[i].elev = 2 * (short)i + 1;
obsdata[i].count = 2 * i + 1;
obsdata[i].relhum = 2.0 * i + 1;
obsdata[i].relhum = 2.0f * (float)i + 1;
obsdata[i].time = 2.0 * i + 1;
}

Expand Down Expand Up @@ -453,8 +453,8 @@ main()
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].min_temp = -9.99;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
}

Expand Down Expand Up @@ -558,8 +558,8 @@ main()
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].min_temp = -9.99;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
}

Expand Down Expand Up @@ -666,8 +666,8 @@ main()
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].min_temp = -9.99;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
}

Expand Down Expand Up @@ -757,7 +757,7 @@ main()
for (i = 0; i < DIM1_LEN; i++)
{
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].max_temp = 99.99f;
}

/* Open file and get root group. */
Expand Down Expand Up @@ -842,7 +842,7 @@ main()
for (i = 0; i < DIM2_LEN; i++)
{
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].max_temp = 99.99f;
}

/* Open file and get root group. */
Expand Down Expand Up @@ -921,7 +921,7 @@ main()
{
for (j = 0; j < STR_LEN + 1; j++)
data_out[i].x[j] = 4;
data_out[i].y = 99.99;
data_out[i].y = 99.99f;
}

/* Set latest_format in access propertly list and
Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ main()
* dimension varies most slowly. */
for (lat = 0; lat < LAT_LEN; lat++)
for (lon = 0; lon < LON_LEN; lon++)
float_data_out[lat][lon] = -666.666;
float_data_out[lat][lon] = -666.666f;

/* Create file and group. */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_vars2.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ main()
hid_t did, fapl_id, fcpl_id, gcpl_id, attid;
hsize_t num_obj;
hid_t fileid, grpid, spaceid;
float val = 3.1495;
float val = 3.1495f;
#if H5_VERSION_GE(1,12,0)
H5O_info2_t obj_info;
#else
Expand Down
2 changes: 1 addition & 1 deletion libhdf5/hdf5internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ nc4_hdf5_get_chunk_cache(int ncid, size_t *sizep, size_t *nelemsp,
if (H5Pget_cache(plistid, NULL, nelemsp, sizep, &dpreemption) < 0)
return NC_EHDFERR;
if (preemptionp)
*preemptionp = dpreemption;
*preemptionp = (float)dpreemption;

return NC_NOERR;
}
Expand Down
2 changes: 1 addition & 1 deletion libhdf5/hdf5open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ nc4_get_var_meta(NC_VAR_INFO_T *var)
if ((H5Pget_chunk_cache(access_pid, &(var->chunkcache.nelems),
&(var->chunkcache.size), &rdcc_w0)) < 0)
BAIL(NC_EHDFERR);
var->chunkcache.preemption = rdcc_w0;
var->chunkcache.preemption = (float)rdcc_w0;

/* Get the dataset creation properties. */
if ((propid = H5Dget_create_plist(hdf5_var->hdf_datasetid)) < 0)
Expand Down
2 changes: 1 addition & 1 deletion libhdf5/hdf5var.c
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@ nc_set_var_chunk_cache_ints(int ncid, int varid, int size, int nelems,
real_nelems = nelems;

if (preemption >= 0)
real_preemption = preemption / 100.;
real_preemption = (float)(preemption / 100.);

return NC4_HDF5_set_var_chunk_cache(ncid, varid, real_size, real_nelems,
real_preemption);
Expand Down
8 changes: 4 additions & 4 deletions nc_test/tst_diskless.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ printf("*** testing diskless file with scalar vars...");
int ndims_in, nvars_in, natts_in, unlimdimid_in;
char name_in[NC_MAX_NAME + 1];
nc_type type_in;
float float_data = 3.14, float_data_in;
float float_data = 3.14f, float_data_in;
int int_data = 42, int_data_in;
short short_data = 2, short_data_in;

Expand Down Expand Up @@ -176,7 +176,7 @@ printf("*** testing diskless file with scalar vars...");

if(!usenetcdf4 && persist) {
int ncid, varid0, varid1, varid2;
float float_data = 3.14, float_data_in;
float float_data = 3.14f, float_data_in;
int int_data = 42, int_data_in;
short short_data = 2, short_data_in;

Expand Down Expand Up @@ -221,7 +221,7 @@ printf("*** testing diskless file with scalar vars...");
size_t start[1] = {0};
size_t count[1] = {DIM1_LEN};
int i;
float float_data = 42.22, float_data_in;
float float_data = 42.22f, float_data_in;

/* This is some really important data that I want to save. */
for (i = 0; i < DIM1_LEN; i++)
Expand Down Expand Up @@ -301,7 +301,7 @@ printf("*** testing diskless file with scalar vars...");
int ndims_in, nvars_in, natts_in, unlimdimid_in;
char name_in[NC_MAX_NAME + 1];
nc_type type_in;
float float_data = 3.14, float_data_in;
float float_data = 3.14f, float_data_in;
int int_data = 42, int_data_in;
short short_data = 2, short_data_in;

Expand Down
4 changes: 2 additions & 2 deletions nc_test/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ inRange_float(const double value, const nc_type xtype)
case NC_UBYTE: min = 0; max = X_UCHAR_MAX; break;
case NC_USHORT: min = 0; max = X_USHORT_MAX; break;
case NC_UINT: min = 0; max = X_UINT_MAX; break;
case NC_INT64: min = X_INT64_MIN; max = X_INT64_MAX; break;
case NC_UINT64: min = 0; max = X_UINT64_MAX; break;
case NC_INT64: min = X_INT64_MIN; max = (double)X_INT64_MAX; break;
case NC_UINT64: min = 0; max = (double)X_UINT64_MAX; break;
default: assert(0);
}
if(!( value >= min && value <= max)) {
Expand Down
6 changes: 3 additions & 3 deletions nc_test4/cdm_sea_soundings.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ main(int argc, char **argv)
/* Create phony data. */
for (i = 0; i < DIM_LEN; i++)
{
if (!(data[i].temp_vl.p = malloc(sizeof(float) * (i + 1))))
if (!(data[i].temp_vl.p = malloc(sizeof(float) * (size_t)(i + 1))))
return NC_ENOMEM;
for (j = 0; j < i + 1; j++)
((float *)(data[i].temp_vl.p))[j] = 23.5 - j;
data[i].temp_vl.len = i + 1;
((float *)(data[i].temp_vl.p))[j] = 23.5f - (float)j;
data[i].temp_vl.len = (size_t)i + 1;
}

printf("\n*** Testing netcdf-4 CDM compliance: sea soundings.\n");
Expand Down
14 changes: 7 additions & 7 deletions nc_test4/tst_atts3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ create_file()
check_err(stat,__LINE__,__FILE__);
}
{ /* Gf */
static const float Gf_att[5] = {-3.4028231e+38, 3.4028231e+38, -9.96921e+36, 9.96921e+36, 531} ;
static const float Gf_att[5] = {-3.4028231e+38f, 3.4028231e+38f, -9.96921e+36f, 9.96921e+36f, 531} ;
stat = nc_put_att_float(ncid, NC_GLOBAL, "Gf", NC_FLOAT, 5, Gf_att);
check_err(stat,__LINE__,__FILE__);
}
Expand Down Expand Up @@ -1247,7 +1247,7 @@ create_file()
check_err(stat,__LINE__,__FILE__);
}
{ /* f */
static const float i_f_att[4] = {-3.4028231e+38, 3.4028231e+38, -9.96921e+36, 9.96921e+36} ;
static const float i_f_att[4] = {-3.4028231e+38f, 3.4028231e+38f, -9.96921e+36f, 9.96921e+36f} ;
stat = nc_put_att_float(ncid, i_id, "f", NC_FLOAT, 4, i_f_att);
check_err(stat,__LINE__,__FILE__);
}
Expand Down Expand Up @@ -1330,7 +1330,7 @@ create_file()
}

{
float fr_data[2] = {-3.4028231e+38, 3.4028231e+38} ;
float fr_data[2] = {-3.4028231e+38f, 3.4028231e+38f} ;
size_t fr_startset[1] = {0} ;
size_t fr_countset[1] = {2} ;
stat = nc_put_vara(ncid, fr_id, fr_startset, fr_countset, fr_data);
Expand Down Expand Up @@ -1378,7 +1378,7 @@ create_file()
}

{
float f1_data[1] = {-3.4028231e+38} ;
float f1_data[1] = {-3.4028231e+38f} ;
size_t f1_startset[1] = {0} ;
size_t f1_countset[1] = {1} ;
stat = nc_put_vara(ncid, f1_id, f1_startset, f1_countset, f1_data);
Expand Down Expand Up @@ -1426,7 +1426,7 @@ create_file()
}

{
float f2_data[2] = {-3.4028231e+38, 3.4028231e+38} ;
float f2_data[2] = {-3.4028231e+38f, 3.4028231e+38f} ;
size_t f2_startset[1] = {0} ;
size_t f2_countset[1] = {2} ;
stat = nc_put_vara(ncid, f2_id, f2_startset, f2_countset, f2_data);
Expand Down Expand Up @@ -1474,7 +1474,7 @@ create_file()
}

{
float f3_data[3] = {-3.4028231e+38, 3.4028231e+38, -9.96921e+36} ;
float f3_data[3] = {-3.4028231e+38f, 3.4028231e+38f, -9.96921e+36f} ;
size_t f3_startset[1] = {0} ;
size_t f3_countset[1] = {3} ;
stat = nc_put_vara(ncid, f3_id, f3_startset, f3_countset, f3_data);
Expand Down Expand Up @@ -1522,7 +1522,7 @@ create_file()
}

{
float f4_data[4] = {-3.4028231e+38, 3.4028231e+38, -9.96921e+36, 9.96921e+36} ;
float f4_data[4] = {-3.4028231e+38f, 3.4028231e+38f, -9.96921e+36f, 9.96921e+36f} ;
size_t f4_startset[1] = {0} ;
size_t f4_countset[1] = {4} ;
stat = nc_put_vara(ncid, f4_id, f4_startset, f4_countset, f4_data);
Expand Down
2 changes: 1 addition & 1 deletion nc_test4/tst_chunks2.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ calculate_waste(int ndims, size_t *dimlen, size_t *chunksize, float *waste)
#endif

/* Percent of the chunked file that is wasted space. */
*waste = ((float)(chunked - unchunked) / (float)chunked) * 100.0;
*waste = ((float)(chunked - unchunked) / (float)chunked) * 100.0f;

#ifdef PRINT_CHUNK_WASTE_REPORT
printf("\ndimlen\tchunksize\tnum_chunks\n");
Expand Down
14 changes: 7 additions & 7 deletions nc_test4/tst_compounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ main(int argc, char **argv)
hr_data_out[i].starfleet_id = i;
hr_data_out[i].svc_rec = data[i];
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].min_temp = -9.99;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .030303;
}

Expand Down Expand Up @@ -659,10 +659,10 @@ main(int argc, char **argv)
/* Initialize data. */
for (i = 0; i < DIM6_LEN; i++)
{
obsdata[i].day = 15 * i + 1;
obsdata[i].elev = 2 * i + 1;
obsdata[i].day = 15 * (char)i + 1;
obsdata[i].elev = 2 * (short)i + 1;
obsdata[i].count = 2 * i + 1;
obsdata[i].relhum = 2.0 * i + 1;
obsdata[i].relhum = 2.0f * (float)i + 1;
obsdata[i].time = 2.0 * i + 1;
}
missing_val.day = 99;
Expand Down Expand Up @@ -863,7 +863,7 @@ main(int argc, char **argv)
for (i = 0; i < DIM1_LEN; i++)
{
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].max_temp = 99.99f;
}

/* Create a file with a nested compound type attribute and variable. */
Expand Down Expand Up @@ -927,7 +927,7 @@ main(int argc, char **argv)
/* Create some phony data. */
for (i = 0; i < DIM1_LEN; i++)
{
hr_data_out[i].max_temp = 99.99;
hr_data_out[i].max_temp = 99.99f;
for (j = 0; j < ARRAY_LEN; j++)
hr_data_out[i].name[j] = j;
}
Expand Down
Loading

0 comments on commit 763e54f

Please sign in to comment.