Skip to content

Commit

Permalink
Use correct absolute value function
Browse files Browse the repository at this point in the history
according to given argument type. (#1248)

Addresses -Wabsolute-value compiler warnings.
  • Loading branch information
nilason committed Feb 2, 2021
1 parent 313581c commit 6146f05
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions lib/gmath/blas_level_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ void G_math_i_asum_norm(int *x, double *value, int rows)

#pragma omp parallel for schedule (static) reduction(+:s)
for (i = rows - 1; i >= 0; i--) {
s += fabs(x[i]);
s += (double)abs(x[i]);
}
#pragma omp single
{
Expand Down Expand Up @@ -579,10 +579,10 @@ void G_math_i_max_norm(int *x, int *value, int rows)

int max = 0.0;

max = fabs(x[rows - 1]);
max = abs(x[rows - 1]);
for (i = rows - 2; i >= 0; i--) {
if (max < fabs(x[i]))
max = fabs(x[i]);
if (max < abs(x[i]))
max = abs(x[i]);
}

*value = max;
Expand Down
4 changes: 2 additions & 2 deletions lib/imagery/iscatt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ static int get_rows_and_cols_bounds(struct Cell_head *A, struct Cell_head *B,
struct Cell_head intersec;

/* TODO is it right check? */
if (abs(A->ns_res - B->ns_res) > GRASS_EPSILON) {
if (fabs(A->ns_res - B->ns_res) > GRASS_EPSILON) {
G_warning(
"'get_rows_and_cols_bounds' ns_res does not fit, A->ns_res: %f B->ns_res: %f",
A->ns_res, B->ns_res);
return -2;
}

if (abs(A->ew_res - B->ew_res) > GRASS_EPSILON) {
if (fabs(A->ew_res - B->ew_res) > GRASS_EPSILON) {
G_warning(
"'get_rows_and_cols_bounds' ew_res does not fit, A->ew_res: %f B->ew_res: %f",
A->ew_res, B->ew_res);
Expand Down
2 changes: 1 addition & 1 deletion lib/raster3d/test/test_put_get_value_large_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
for(x = 0; x < region.cols; x++) {
/* Check the counter as cell value */
Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
if(fabs(value - (double)(count) > EPSILON)) {
if(fabs(value - (double)(count)) > EPSILON) {
G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n",
z, y, x, value, (double)(count));
sum++;
Expand Down
4 changes: 2 additions & 2 deletions lib/vector/neta/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int NetA_compute_bridges(dglGraph_s * graph, struct ilist *bridge_list)
dglEdgeGet_Tail(graph, current_edge[node_id]);
dglInt32_t edge_id =
dglEdgeGet_Id(graph, current_edge[node_id]);
if (abs(edge_id) == parent[node_id])
if (labs(edge_id) == parent[node_id])
continue; /*skip edge we used to travel to this node */
int to_id = dglNodeGet_Id(graph, to);

Expand All @@ -111,7 +111,7 @@ int NetA_compute_bridges(dglGraph_s * graph, struct ilist *bridge_list)
min_tin[node_id] = tin[to_id];
}
else { /*forward edge */
parent[to_id] = abs(edge_id);
parent[to_id] = labs(edge_id);
stack[stack_size++] = to;
break;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/vector/neta/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int NetA_flow(dglGraph_s * graph, struct ilist *source_list,
dglInt32_t to =
dglNodeGet_Id(graph, dglEdgeGet_Tail(graph, edge));
if (!is_source[to] && prev[to] == NULL &&
cap > sign(id) * flow[abs(id)]) {
cap > sign(id) * flow[labs(id)]) {
prev[to] = edge;
if (is_sink[to]) {
found = to;
Expand All @@ -127,15 +127,15 @@ int NetA_flow(dglGraph_s * graph, struct ilist *source_list,
edge_id = dglEdgeGet_Id(graph, prev[node]);
min_residue =
dglEdgeGet_Cost(graph,
prev[node]) - sign(edge_id) * flow[abs(edge_id)];
prev[node]) - sign(edge_id) * flow[labs(edge_id)];
while (!is_source[node]) {
dglInt32_t residue;

edge_id = dglEdgeGet_Id(graph, prev[node]);
residue =
dglEdgeGet_Cost(graph,
prev[node]) -
sign(edge_id) * flow[abs(edge_id)];
sign(edge_id) * flow[labs(edge_id)];
if (residue < min_residue)
min_residue = residue;
node = dglNodeGet_Id(graph, dglEdgeGet_Head(graph, prev[node]));
Expand All @@ -145,7 +145,7 @@ int NetA_flow(dglGraph_s * graph, struct ilist *source_list,
node = found;
while (!is_source[node]) {
edge_id = dglEdgeGet_Id(graph, prev[node]);
flow[abs(edge_id)] += sign(edge_id) * min_residue;
flow[labs(edge_id)] += sign(edge_id) * min_residue;
node = dglNodeGet_Id(graph, dglEdgeGet_Head(graph, prev[node]));
}
}
Expand Down Expand Up @@ -214,7 +214,7 @@ int NetA_min_cut(dglGraph_s * graph, struct ilist *source_list,
dglInt32_t id = dglEdgeGet_Id(graph, edge);
dglInt32_t to =
dglNodeGet_Id(graph, dglEdgeGet_Tail(graph, edge));
if (!visited[to] && cap > sign(id) * flow[abs(id)]) {
if (!visited[to] && cap > sign(id) * flow[labs(id)]) {
visited[to] = 1;
queue[end++] = to;
}
Expand All @@ -236,10 +236,10 @@ int NetA_min_cut(dglGraph_s * graph, struct ilist *source_list,
dglInt32_t to, edge_id;

to = dglNodeGet_Id(graph, dglEdgeGet_Tail(graph, edge));
edge_id = abs(dglEdgeGet_Id(graph, edge));
edge_id = labs(dglEdgeGet_Id(graph, edge));
if (!visited[to] && flow[edge_id] != 0) {
Vect_list_append(cut, edge_id);
total_flow += abs(flow[abs(edge_id)]);
total_flow += abs(flow[labs(edge_id)]);
}
}
dglEdgeset_T_Release(&et);
Expand Down
4 changes: 2 additions & 2 deletions lib/vector/neta/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ int NetA_find_path(dglGraph_s * graph, int from, int to, int *edges,
dglNodeGet_OutEdgeset(graph, node));
for (edge = dglEdgeset_T_First(&et); edge;
edge = dglEdgeset_T_Next(&et)) {
dglInt32_t edge_id = abs(dglEdgeGet_Id(graph, edge));
dglInt32_t edge_id = labs(dglEdgeGet_Id(graph, edge));
dglInt32_t node_id =
dglNodeGet_Id(graph, dglEdgeGet_Tail(graph, edge));
if (edges[edge_id] && !vis[node_id]) {
Expand All @@ -313,7 +313,7 @@ int NetA_find_path(dglGraph_s * graph, int from, int to, int *edges,

cur = to;
while (prev[cur] != NULL) {
Vect_list_append(list, abs(dglEdgeGet_Id(graph, prev[cur])));
Vect_list_append(list, labs(dglEdgeGet_Id(graph, prev[cur])));
cur = dglNodeGet_Id(graph, dglEdgeGet_Head(graph, prev[cur]));
}

Expand Down
4 changes: 2 additions & 2 deletions raster/r.grow.distance/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ static double distance_euclidean_squared(double dx, double dy)

static double distance_maximum(double dx, double dy)
{
return MAX(abs(dx), abs(dy));
return MAX(fabs(dx), fabs(dy));
}

static double distance_manhattan(double dx, double dy)
{
return abs(dx) + abs(dy);
return fabs(dx) + fabs(dy);
}

static double geodesic_distance(int x1, int y1, int x2, int y2)
Expand Down
4 changes: 2 additions & 2 deletions raster/r.latlong/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ int main(int argc, char *argv[])
ymax = cellhd.north;
nrows = Rast_window_rows();
ncols = Rast_window_cols();
stepx = abs(xmax-xmin)/(double)ncols;
stepy = abs(ymax-ymin)/(double)nrows;
stepx = fabs(xmax-xmin)/(double)ncols;
stepy = fabs(ymax-ymin)/(double)nrows;

/*Stolen from r.sun */
/* Set up parameters for projection to lat/long if necessary */
Expand Down
4 changes: 2 additions & 2 deletions vector/v.generalize/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int graph_generalization(struct Map_info *In, struct Map_info *Out,

to_degree = dglNodeGet_OutDegree(gr, to);
from_degree = dglNodeGet_OutDegree(gr, from);
id = abs(dglEdgeGet_Id(gr, edge));
id = labs(dglEdgeGet_Id(gr, edge));

/* allocate memory, if it has not been not allocated already */
if (!g.edge[id]) {
Expand All @@ -135,7 +135,7 @@ int graph_generalization(struct Map_info *In, struct Map_info *Out,

for (to_edge = dglEdgeset_T_First(&to_et); to_edge;
to_edge = dglEdgeset_T_Next(&to_et)) {
int id2 = abs(dglEdgeGet_Id(gr, to_edge));
int id2 = labs(dglEdgeGet_Id(gr, to_edge));

g.edge[id][g.degree[id]++] = id2;
}
Expand Down
8 changes: 4 additions & 4 deletions vector/v.label.sa/labels.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,8 @@ static double label_lineover(label_t * label, label_candidate_t * candidate,
candidate->point.x, candidate->point.y);
/* trsk = skyline_trans_rot(label->skyline, &candidate->point,
candidate->rotation); */
b.x = abs((label->bb.E - label->bb.W) * cos(candidate->rotation));
b.y = abs((label->bb.E - label->bb.W) * sin(candidate->rotation));
b.x = fabs((label->bb.E - label->bb.W) * cos(candidate->rotation));
b.y = fabs((label->bb.E - label->bb.W) * sin(candidate->rotation));

trbb = box_trans_rot(&label->bb, &candidate->point, candidate->rotation);
n = Vect_select_lines_by_polygon(&Map, trbb, 0, NULL, linetype, il);
Expand Down Expand Up @@ -1083,8 +1083,8 @@ static double label_lineover(label_t * label, label_candidate_t * candidate,
if (found > 1) {
double cosvb;

v.x = abs(v2.x - v1.x);
v.y = abs(v2.y - v1.y);
v.x = fabs(v2.x - v1.x);
v.y = fabs(v2.y - v1.y);
cosvb = ((b.x * v.x + b.y * v.y) /
(sqrt(b.x * b.x + b.y * b.y) *
sqrt(v.x * v.x + v.y * v.y)));
Expand Down
12 changes: 6 additions & 6 deletions vector/v.patch/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,14 @@ int main(int argc, char *argv[])

Vect_get_map_box(&OutMap, &box);

if (abs(box.E) > abs(box.W))
xmax = abs(box.E);
if (fabs(box.E) > fabs(box.W))
xmax = fabs(box.E);
else
xmax = abs(box.W);
if (abs(box.N) > abs(box.S))
ymax = abs(box.N);
xmax = fabs(box.W);
if (fabs(box.N) > fabs(box.S))
ymax = fabs(box.N);
else
ymax = abs(box.S);
ymax = fabs(box.S);

if (xmax < ymax)
xmax = ymax;
Expand Down

0 comments on commit 6146f05

Please sign in to comment.