GRASS GIS 8 Programmer's Manual 8.4.1(2025)-45ca3179ab
Loading...
Searching...
No Matches
xmod.c
Go to the documentation of this file.
1#include <math.h>
2
3#include <grass/gis.h>
4#include <grass/raster.h>
5#include <grass/calc.h>
6
7/****************************************************************
8mod(a,b) = a % b
9****************************************************************/
10
11int f_mod(int argc, const int *argt, void **args)
12{
13 int i;
14
15 if (argc < 2)
16 return E_ARG_LO;
17 if (argc > 2)
18 return E_ARG_HI;
19
20 if (argt[1] != argt[0] || argt[2] != argt[0])
21 return E_ARG_TYPE;
22
23 switch (argt[0]) {
24 case CELL_TYPE: {
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 SET_NULL_C(&res[i]);
32 else
33 res[i] = arg1[i] % arg2[i];
34 }
35 return 0;
36 }
37 case FCELL_TYPE: {
38 FCELL *res = args[0];
39 FCELL *arg1 = args[1];
40 FCELL *arg2 = args[2];
41
42 for (i = 0; i < columns; i++) {
43 if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
44 SET_NULL_F(&res[i]);
45 else {
47 res[i] = (FCELL)fmod(arg1[i], arg2[i]);
49 SET_NULL_F(&res[i]);
50 }
51 }
52 return 0;
53 }
54 case DCELL_TYPE: {
55 DCELL *res = args[0];
56 DCELL *arg1 = args[1];
57 DCELL *arg2 = args[2];
58
59 for (i = 0; i < columns; i++) {
60 if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
61 SET_NULL_D(&res[i]);
62 else {
64 res[i] = (DCELL)fmod(arg1[i], arg2[i]);
66 SET_NULL_D(&res[i]);
67 }
68 }
69 return 0;
70 }
71 default:
72 return E_INV_TYPE;
73 }
74}
volatile int floating_point_exception
Definition calc.c:8
int columns
Definition calc.c:11
int f_mod(int argc, const int *argt, void **args)
Definition xmod.c:11