GRASS GIS 8 Programmer's Manual 8.2.1(2023)-exported
xmod.c
Go to the documentation of this file.
1
2#include <math.h>
3
4#include <grass/gis.h>
5#include <grass/raster.h>
6#include <grass/calc.h>
7
8/****************************************************************
9mod(a,b) = a % b
10****************************************************************/
11
12int f_mod(int argc, const int *argt, void **args)
13{
14 int i;
15
16 if (argc < 2)
17 return E_ARG_LO;
18 if (argc > 2)
19 return E_ARG_HI;
20
21 if (argt[1] != argt[0] || argt[2] != argt[0])
22 return E_ARG_TYPE;
23
24 switch (argt[0]) {
25 case CELL_TYPE:
26 {
27 CELL *res = args[0];
28 CELL *arg1 = args[1];
29 CELL *arg2 = args[2];
30
31 for (i = 0; i < columns; i++) {
32 if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
33 SET_NULL_C(&res[i]);
34 else
35 res[i] = arg1[i] % arg2[i];
36 }
37 return 0;
38 }
39 case FCELL_TYPE:
40 {
41 FCELL *res = args[0];
42 FCELL *arg1 = args[1];
43 FCELL *arg2 = args[2];
44
45 for (i = 0; i < columns; i++) {
46 if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
47 SET_NULL_F(&res[i]);
48 else {
50 res[i] = (FCELL) fmod(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 SET_NULL_D(&res[i]);
66 else {
68 res[i] = (DCELL) fmod(arg1[i], arg2[i]);
70 SET_NULL_D(&res[i]);
71 }
72 }
73 return 0;
74 }
75 default:
76 return E_INV_TYPE;
77 }
78}
volatile int floating_point_exception
Definition: calc.c:9
int columns
Definition: calc.c:12
int f_mod(int argc, const int *argt, void **args)
Definition: xmod.c:12