Skip to content

Commit 5766b01

Browse files
committed
cmake support preparation: use of INFINITY and NAN (OSGeo#2681)
* cmake support preparation: use of INFINITY and NAN - use of `INFINITY` rather than only division by zero (this is supported by gcc and other compilers but not on Windows) - use of `NAN` rather than only division by zero Extracted from WIP PR OSGeo#289 Further changes on top: - fix indentation - revert void* arithmetic change - remove superfluous comments - use 0 (zero) to init integers - 0/0 = NAN, 1/0 = INFINITY - Include math.h for Windows - Use c++ include - r.series: add INFINITY - apply clang-format to match reformatting in `main` by using `for i in $(gh pr view 2681 --json files --jq '.files.[].path') ; do clang-format -i $i ; done` Co-authored-by: @rkanavath Co-authored-by: @nilason
1 parent b50ac10 commit 5766b01

File tree

21 files changed

+49
-49
lines changed

21 files changed

+49
-49
lines changed

general/g.region/printwindow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void print_window(struct Cell_head *window, int print_flag, int flat_flag)
469469
double convergence;
470470

471471
if (G_projection() == PROJECTION_XY)
472-
convergence = 0. / 0.;
472+
convergence = NAN;
473473
else if (G_projection() == PROJECTION_LL)
474474
convergence = 0.0;
475475
else {

lib/btree2/kdtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ int kdtree_knn(struct kdtree *t, double *c, int *uid, double *d, int k,
531531
if (skip)
532532
sn.uid = *skip;
533533

534-
maxdist = 1.0 / 0.0;
534+
maxdist = INFINITY;
535535
found = 0;
536536

537537
/* go down */

lib/gmath/la.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ double G_vector_norm1(vec_struct *vc)
12911291

12921292
if (!vc->is_init) {
12931293
G_warning(_("Matrix is not initialised"));
1294-
return 0.0 / 0.0; /* NaN */
1294+
return NAN;
12951295
}
12961296

12971297
idx = (vc->v_indx > 0) ? vc->v_indx : 0;

lib/vector/Vlib/box.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ int Vect_get_line_box(const struct Map_info *Map, int line,
248248

249249
Line = Plus->Line[line];
250250
if (Line == NULL) { /* dead */
251-
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = 0. / 0.;
251+
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = NAN;
252252
return 0;
253253
}
254254

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

315315
if (Area == NULL) { /* dead */
316-
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = 0. / 0.;
316+
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = NAN;
317317
return 0;
318318
}
319319

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

362362
if (Isle == NULL) { /* dead */
363-
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = 0. / 0.;
363+
Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = NAN;
364364
return 0;
365365
}
366366

raster/r.horizon/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ double horizon_height(void)
754754
{
755755
double height;
756756

757-
tanh0 = -1.0 / 0.0; /* -inf */
757+
tanh0 = -INFINITY;
758758
length = 0;
759759

760760
height = searching();

raster/r.in.bin/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ int main(int argc, char *argv[])
254254
const char *outpre;
255255
char output[GNAME_MAX];
256256
const char *title;
257-
double null_val = 0.0 / 0.0;
257+
double null_val = NAN;
258258
int is_fp;
259259
int is_signed;
260260
int bytes, hbytes;

raster/r.in.lidar/info.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
*/
1313

1414
#include <string.h>
15-
15+
#include <math.h>
1616
#include <grass/glocale.h>
17-
1817
#include <liblas/capi/liblas.h>
19-
2018
#include "local_proto.h"
2119

2220
void print_lasinfo(LASHeaderH LAS_header, LASSRSH LAS_srs)
@@ -99,7 +97,7 @@ int scan_bounds(LASReaderH LAS_reader, int shell_style, int extents, int update,
9997
first = TRUE;
10098

10199
/* init to nan in case no points are found */
102-
min_x = max_x = min_y = max_y = min_z = max_z = 0.0 / 0.0;
100+
min_x = max_x = min_y = max_y = min_z = max_z = NAN;
103101

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

raster/r.in.pdal/info.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
*/
1111

1212
#include "info.h"
13+
#include <cmath>
1314

1415
void get_extent(struct StringList *infiles, double *min_x, double *max_x,
1516
double *min_y, double *max_y, double *min_z, double *max_z)
1617
{
1718
pdal::StageFactory factory;
1819
bool first = 1;
1920

20-
*min_x = *max_x = *min_y = *max_y = *min_z = *max_z = 0.0 / 0.0;
21+
*min_x = *max_x = *min_y = *max_y = *min_z = *max_z = NAN;
2122

2223
for (int i = 0; i < infiles->num_items; i++) {
2324
const char *infile = infiles->items[i];

raster/r.in.xyz/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ int main(int argc, char *argv[])
124124
int arr_row, arr_col;
125125
unsigned long count, count_total;
126126

127-
double min = 0.0 / 0.0; /* init as nan */
128-
double max = 0.0 / 0.0; /* init as nan */
127+
double min = NAN;
128+
double max = NAN;
129129
double zscale = 1.0;
130130
double vscale = 1.0;
131131
size_t offset, n_offset;

raster/r.li/r.li.padrange/padrange.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ int calculate(int fd, struct area_entry *ad, double *result)
312312
(((NS_DIST1 + NS_DIST2) / 2) / hd.rows);
313313

314314
/* get min and max patch size */
315-
min = 1.0 / 0.0; /* inf */
316-
max = -1.0 / 0.0; /* -inf */
315+
min = INFINITY;
316+
max = -INFINITY;
317317
for (old_pid = 1; old_pid <= pid; old_pid++) {
318318
if (pst[old_pid].count > 0) {
319319
area_p = cell_size_m * pst[old_pid].count / 10000;
@@ -549,8 +549,8 @@ int calculateD(int fd, struct area_entry *ad, double *result)
549549
(((NS_DIST1 + NS_DIST2) / 2) / hd.rows);
550550

551551
/* get min and max patch size */
552-
min = 1.0 / 0.0; /* inf */
553-
max = -1.0 / 0.0; /* -inf */
552+
min = INFINITY;
553+
max = -INFINITY;
554554
for (old_pid = 1; old_pid <= pid; old_pid++) {
555555
if (pst[old_pid].count > 0) {
556556
area_p = cell_size_m * pst[old_pid].count / 10000;
@@ -786,8 +786,8 @@ int calculateF(int fd, struct area_entry *ad, double *result)
786786
(((NS_DIST1 + NS_DIST2) / 2) / hd.rows);
787787

788788
/* get min and max patch size */
789-
min = 1.0 / 0.0; /* inf */
790-
max = -1.0 / 0.0; /* -inf */
789+
min = INFINITY;
790+
max = -INFINITY;
791791
for (old_pid = 1; old_pid <= pid; old_pid++) {
792792
if (pst[old_pid].count > 0) {
793793
area_p = cell_size_m * pst[old_pid].count / 10000;

0 commit comments

Comments
 (0)