GRASS GIS 7 Programmer's Manual  7.8.5(2020)-exported
xdiv.c
Go to the documentation of this file.
1 
2 #include <grass/gis.h>
3 #include <grass/raster.h>
4 #include <grass/calc.h>
5 
6 /****************************************************************
7 div(a,b) = a / b
8 ****************************************************************/
9 
10 int f_div(int argc, const int *argt, void **args)
11 {
12  int i;
13 
14  if (argc < 2)
15  return E_ARG_LO;
16  if (argc > 2)
17  return E_ARG_HI;
18 
19  if (argt[1] != argt[0] || argt[2] != argt[0])
20  return E_ARG_TYPE;
21 
22  switch (argt[0]) {
23  case CELL_TYPE:
24  {
25  CELL *res = args[0];
26  CELL *arg1 = args[1];
27  CELL *arg2 = args[2];
28 
29  for (i = 0; i < columns; i++) {
30  if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]) ||
31  arg2[i] == 0)
32  SET_NULL_C(&res[i]);
33  else
34  res[i] = arg1[i] / arg2[i];
35  }
36  return 0;
37  }
38  case FCELL_TYPE:
39  {
40  FCELL *res = args[0];
41  FCELL *arg1 = args[1];
42  FCELL *arg2 = args[2];
43 
44  for (i = 0; i < columns; i++) {
45  if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]) ||
46  arg2[i] == 0.0f)
47  SET_NULL_F(&res[i]);
48  else {
50  res[i] = arg1[i] / arg2[i];
52  SET_NULL_F(&res[i]);
53  }
54  }
55  return 0;
56  }
57  case DCELL_TYPE:
58  {
59  DCELL *res = args[0];
60  DCELL *arg1 = args[1];
61  DCELL *arg2 = args[2];
62 
63  for (i = 0; i < columns; i++) {
64  if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]) ||
65  arg2[i] == 0.0)
66  SET_NULL_D(&res[i]);
67  else {
69  res[i] = arg1[i] / arg2[i];
71  SET_NULL_D(&res[i]);
72  }
73  }
74  return 0;
75  }
76  default:
77  return E_INV_TYPE;
78  }
79 }
columns
int columns
Definition: calc.c:12
f_div
int f_div(int argc, const int *argt, void **args)
Definition: xdiv.c:10
floating_point_exception
volatile int floating_point_exception
Definition: calc.c:9