Skip to content

Commit

Permalink
revert C related INFINITY/NAN changes (this is taken care of in OSGeo…
Browse files Browse the repository at this point in the history
  • Loading branch information
neteler authored and lbartoletti committed Jun 5, 2023
1 parent 24b2396 commit 02846dd
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 52 deletions.
2 changes: 1 addition & 1 deletion general/g.region/printwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ void print_window(struct Cell_head *window, int print_flag, int flat_flag)
double convergence;

if (G_projection() == PROJECTION_XY)
convergence = INFINITY;
convergence = 0. / 0.;
else if (G_projection() == PROJECTION_LL)
convergence = 0.0;
else {
Expand Down
2 changes: 1 addition & 1 deletion lib/btree2/kdtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ int kdtree_knn(struct kdtree *t, double *c, int *uid, double *d, int k,
if (skip)
sn.uid = *skip;

maxdist = INFINITY;
maxdist = 1.0 / 0.0;
found = 0;

/* go down */
Expand Down
6 changes: 3 additions & 3 deletions lib/raster3d/mask.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ void Rast3d_mask_tile(RASTER3D_Map *map, int tileIndex, void *tile, int type)
for (dy = y; dy < rows; dy++) {
for (dx = x; dx < cols; dx++) {
RASTER3D_MASKNUM(map, dx, dy, dz, tile, type);
tile = (int*)tile + length;
tile += length;
}

tile = (int*) + xLength;
tile += xLength;
}
tile = (int*) + yLength;
tile += yLength;
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/vector/Vlib/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int Vect_get_line_box(const struct Map_info *Map, int line,

Line = Plus->Line[line];
if (Line == NULL) { /* dead */
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = INFINITY;
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = 0. / 0.;
return 0;
}

Expand Down Expand Up @@ -313,7 +313,7 @@ int Vect_get_area_box(const struct Map_info *Map, int area,
Area = Plus->Area[area];

if (Area == NULL) { /* dead */
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = INFINITY;
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = 0. / 0.;
return 0;
}

Expand Down Expand Up @@ -360,7 +360,7 @@ int Vect_get_isle_box(const struct Map_info *Map, int isle,
Isle = Plus->Isle[isle];

if (Isle == NULL) { /* dead */
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = INFINITY;
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = 0. / 0.;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion raster/r.horizon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ double horizon_height(void)
{
double height;

tanh0 = -INFINITY;
tanh0 = -1.0 / 0.0; /* -inf */
length = 0;

height = searching();
Expand Down
2 changes: 1 addition & 1 deletion raster/r.in.bin/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ int main(int argc, char *argv[])
const char *outpre;
char output[GNAME_MAX];
const char *title;
double null_val = INFINITY;
double null_val = 0.0 / 0.0;
int is_fp;
int is_signed;
int bytes, hbytes;
Expand Down
3 changes: 1 addition & 2 deletions raster/r.in.lidar/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

#include <string.h>
#include <math.h> /* For INIFINITY */

#include <grass/glocale.h>
#include <liblas/capi/liblas.h>
Expand Down Expand Up @@ -98,7 +97,7 @@ int scan_bounds(LASReaderH LAS_reader, int shell_style, int extents, int update,
first = TRUE;

/* init to nan in case no points are found */
min_x = max_x = min_y = max_y = min_z = max_z = INFINITY;
min_x = max_x = min_y = max_y = min_z = max_z = 0.0 / 0.0;

G_verbose_message(_("Scanning data ..."));

Expand Down
20 changes: 10 additions & 10 deletions raster/r.in.lidar/point_binning.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void write_median(struct BinIndex *bin_index, void *raster_row,
Rast_set_null_value(ptr, 1, rtype);
else { /* one or more points in cell */

head_id = Rast_get_c_value((CELL*)index_array + n_offset, CELL_TYPE);
head_id = Rast_get_c_value(index_array + n_offset, CELL_TYPE);
node_id = head_id;

n = 0;
Expand Down Expand Up @@ -493,7 +493,7 @@ void write_percentile(struct BinIndex *bin_index, void *raster_row,
CELL_TYPE)) /* no points in cell */
Rast_set_null_value(ptr, 1, rtype);
else {
head_id = Rast_get_c_value((CELL*)index_array + n_offset, CELL_TYPE);
head_id = Rast_get_c_value(index_array + n_offset, CELL_TYPE);
node_id = head_id;
n = 0;

Expand Down Expand Up @@ -548,7 +548,7 @@ void write_skewness(struct BinIndex *bin_index, void *raster_row,
CELL_TYPE)) /* no points in cell */
Rast_set_null_value(ptr, 1, rtype);
else {
head_id = Rast_get_c_value((CELL*)index_array + n_offset, CELL_TYPE);
head_id = Rast_get_c_value(index_array + n_offset, CELL_TYPE);
node_id = head_id;

n = 0; /* count */
Expand Down Expand Up @@ -605,7 +605,7 @@ void write_trimmean(struct BinIndex *bin_index, void *raster_row,
CELL_TYPE)) /* no points in cell */
Rast_set_null_value(ptr, 1, rtype);
else {
head_id = Rast_get_c_value((CELL*)index_array + n_offset, CELL_TYPE);
head_id = Rast_get_c_value(index_array + n_offset, CELL_TYPE);

node_id = head_id;
n = 0;
Expand Down Expand Up @@ -697,9 +697,9 @@ void write_values(struct PointBinning *point_binning,
for (col = 0; col < cols; col++) {
size_t offset = ((size_t)row * cols + col) * Rast_cell_size(rtype);
double min =
Rast_get_d_value((DCELL*)point_binning->min_array + offset, rtype);
Rast_get_d_value(point_binning->min_array + offset, rtype);
double max =
Rast_get_d_value((DCELL*)point_binning->max_array + offset, rtype);
Rast_get_d_value(point_binning->max_array + offset, rtype);
Rast_set_d_value(ptr, max - min, rtype);
ptr = G_incr_void_ptr(ptr, Rast_cell_size(rtype));
}
Expand All @@ -714,7 +714,7 @@ void write_values(struct PointBinning *point_binning,
int n =
Rast_get_c_value(point_binning->n_array + n_offset, CELL_TYPE);
double sum =
Rast_get_d_value((DCELL*)point_binning->sum_array + offset, rtype);
Rast_get_d_value(point_binning->sum_array + offset, rtype);

if (n == 0)
Rast_set_null_value(ptr, 1, rtype);
Expand Down Expand Up @@ -765,12 +765,12 @@ void write_values(struct PointBinning *point_binning,
continue;

double sum_x =
Rast_get_d_value((DCELL*)point_binning->x_array + offset, rtype);
Rast_get_d_value(point_binning->x_array + offset, rtype);
double sum_y =
Rast_get_d_value((DCELL*)point_binning->y_array + offset, rtype);
Rast_get_d_value(point_binning->y_array + offset, rtype);
/* TODO: we do this also in mean writing */
double sum_z =
Rast_get_d_value((DCELL*)point_binning->sum_array + offset, rtype);
Rast_get_d_value(point_binning->sum_array + offset, rtype);

/* We are not writing any categories. They are not needed
* and potentially it is too much trouble to do it and it is
Expand Down
12 changes: 6 additions & 6 deletions raster/r.li/r.li.padrange/padrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ int calculate(int fd, struct area_entry *ad, double *result)
(((NS_DIST1 + NS_DIST2) / 2) / hd.rows);

/* get min and max patch size */
min = INFINITY;
max = -INFINITY;
min = 1.0 / 0.0; /* inf */
max = -1.0 / 0.0; /* -inf */
for (old_pid = 1; old_pid <= pid; old_pid++) {
if (pst[old_pid].count > 0) {
area_p = cell_size_m * pst[old_pid].count / 10000;
Expand Down Expand Up @@ -543,8 +543,8 @@ int calculateD(int fd, struct area_entry *ad, double *result)
(((NS_DIST1 + NS_DIST2) / 2) / hd.rows);

/* get min and max patch size */
min = INFINITY;
max = -INFINITY;
min = 1.0 / 0.0; /* inf */
max = -1.0 / 0.0; /* -inf */
for (old_pid = 1; old_pid <= pid; old_pid++) {
if (pst[old_pid].count > 0) {
area_p = cell_size_m * pst[old_pid].count / 10000;
Expand Down Expand Up @@ -777,8 +777,8 @@ int calculateF(int fd, struct area_entry *ad, double *result)
(((NS_DIST1 + NS_DIST2) / 2) / hd.rows);

/* get min and max patch size */
min = INFINITY;
max = -INFINITY;
min = 1.0 / 0.0; /* inf */
max = -1.0 / 0.0; /* -inf */
for (old_pid = 1; old_pid <= pid; old_pid++) {
if (pst[old_pid].count > 0) {
area_p = cell_size_m * pst[old_pid].count / 10000;
Expand Down
4 changes: 2 additions & 2 deletions raster/r.out.gdal/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,11 +1047,11 @@ double set_default_nodata_value(GDALDataType datatype, double min, double max)

case GDT_Float32:
case GDT_CFloat32:
return INFINITY;
return 0.0 / 0.0;

case GDT_Float64:
case GDT_CFloat64:
return INFINITY;
return 0.0 / 0.0;

default:
return 0;
Expand Down
4 changes: 2 additions & 2 deletions raster/r.series.accumulate/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ int main(int argc, char *argv[])
if (G_parser(argc, argv))
exit(EXIT_FAILURE);

lo = INFINITY;
hi = INFINITY;
lo = -1.0 / 0.0; /* -inf */
hi = 1.0 / 0.0; /* inf */

method = METHOD_GDD;
if (G_strncasecmp(parm.method->answer, "gdd", 3) == 0)
Expand Down
4 changes: 2 additions & 2 deletions raster/r.univar/r.univar_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ int main(int argc, char *argv[])
/* table field separator */
zone_info.sep = G_option_to_separator(param.separator);

zone_info.min = NAN;
zone_info.max = NAN;
zone_info.min = 0.0 / 0.0; /* set to nan as default */
zone_info.max = 0.0 / 0.0; /* set to nan as default */
zone_info.n_zones = 0;

fdz = NULL;
Expand Down
8 changes: 4 additions & 4 deletions raster/r.univar/r3.univar_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ int main(int argc, char *argv[])
/* table field separator */
zone_info.sep = G_option_to_separator(param.separator);

dmin = NAN;
dmax = NAN;
zone_info.min = NAN;
zone_info.max = NAN;
dmin = 0.0 / 0.0; /* set to nan as default */
dmax = 0.0 / 0.0; /* set to nan as default */
zone_info.min = 0.0 / 0.0; /* set to nan as default */
zone_info.max = 0.0 / 0.0; /* set to nan as default */
zone_info.n_zones = 0;

/* open 3D zoning raster with default region */
Expand Down
16 changes: 8 additions & 8 deletions raster/r.univar/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ univar_stat *create_univar_stat_struct(int map_type, int n_perc)
for (i = 0; i < n_zones; i++) {
stats[i].sum = 0.0;
stats[i].sumsq = 0.0;
stats[i].min = NAN;
stats[i].max = NAN;
stats[i].min = 0.0 / 0.0; /* set to nan as default */
stats[i].max = 0.0 / 0.0; /* set to nan as default */
stats[i].n_perc = n_perc;
if (n_perc > 0)
stats[i].perc = (double *)G_malloc(n_perc * sizeof(double));
Expand Down Expand Up @@ -131,7 +131,7 @@ int print_stats(univar_stat *stats)
var_coef = (stdev / mean) * 100.; /* perhaps stdev/fabs(mean) ? */

if (stats[z].n == 0)
stats[z].sum = stats[z].sum_abs = NAN;
stats[z].sum = stats[z].sum_abs = 0.0 / 0.0;
sprintf(sum_str, "%.15g", stats[z].sum);
G_trim_decimal(sum_str);

Expand Down Expand Up @@ -190,9 +190,9 @@ int print_stats(univar_stat *stats)
quartile_perc = (double *)G_calloc(stats[z].n_perc, sizeof(double));

if (stats[z].n == 0) {
quartile_25 = median = quartile_75 = NAN;
quartile_25 = median = quartile_75 = 0.0 / 0.0;
for (i = 0; i < stats[z].n_perc; i++)
quartile_perc[i] = NAN;
quartile_perc[i] = 0.0 / 0.0;
}
else {
for (i = 0; i < stats[z].n_perc; i++) {
Expand Down Expand Up @@ -402,7 +402,7 @@ int print_stats_table(univar_stat *stats)
var_coef = (stdev / mean) * 100.; /* perhaps stdev/fabs(mean) ? */

if (stats[z].n == 0)
stats[z].sum = stats[z].sum_abs = NAN;
stats[z].sum = stats[z].sum_abs = 0.0 / 0.0;

if (zone_info.n_zones) {
int z_cat = z + zone_info.min;
Expand Down Expand Up @@ -450,9 +450,9 @@ int print_stats_table(univar_stat *stats)
quartile_perc = (double *)G_calloc(stats[z].n_perc, sizeof(double));

if (stats[z].n == 0) {
quartile_25 = median = quartile_75 = NAN;
quartile_25 = median = quartile_75 = 0.0 / 0.0;
for (i = 0; i < stats[z].n_perc; i++)
quartile_perc[i] = NAN;
quartile_perc[i] = 0.0 / 0.0;
}
else {
for (i = 0; i < stats[z].n_perc; i++) {
Expand Down
3 changes: 1 addition & 2 deletions raster3d/r3.in.lidar/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/

#include <string.h>
#include <math.h>

#include <grass/glocale.h>

Expand Down Expand Up @@ -101,7 +100,7 @@ int scan_bounds(LASReaderH LAS_reader, int shell_style, int extents, int update,
first = TRUE;

/* init to nan in case no points are found */
min_x = max_x = min_y = max_y = min_z = max_z = INFINITY;
min_x = max_x = min_y = max_y = min_z = max_z = 0.0 / 0.0;

G_verbose_message(_("Scanning data ..."));

Expand Down
4 changes: 2 additions & 2 deletions vector/v.cluster/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int main(int argc, char *argv[])
c[2] = 0.0;
n = 0;
sum = sumsq = 0;
min = NAN;
min = 1.0 / 0.0;
max = 0;
kd = G_malloc(minpnts * sizeof(double));
ki = G_malloc(minpnts * sizeof(int));
Expand Down Expand Up @@ -463,7 +463,7 @@ int main(int argc, char *argv[])
c[2] = 0.0;
n = 0;
sum = sumsq = 0;
min = NAN;
min = 1.0 / 0.0;
max = 0;
kd = G_malloc(minpnts * sizeof(double));
ki = G_malloc(minpnts * sizeof(int));
Expand Down
2 changes: 1 addition & 1 deletion vector/v.distance/distance.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int get_line_box(const struct line_pnts *Points, struct bound_box *box)
int i;

if (Points->n_points == 0) {
box->E = box->W = box->N = box->S = box->T = box->B = INFINITY;
box->E = box->W = box->N = box->S = box->T = box->B = 0.0 / 0.0;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion vector/v.voronoi/skeleton.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ int tie_up(void)
IPoints[i]);
}

distmin = INFINITY;
distmin = 1. / 0.; /* +inf */
xmin = x;
ymin = y;

Expand Down

0 comments on commit 02846dd

Please sign in to comment.