GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-36359e2344
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
/****************************************************************
8
mod(a,b) = a % b
9
****************************************************************/
10
11
int
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
{
46
floating_point_exception
= 0;
47
res[i] = (
FCELL
)fmod(arg1[i], arg2[i]);
48
if
(
floating_point_exception
)
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
{
63
floating_point_exception
= 0;
64
res[i] = (
DCELL
)fmod(arg1[i], arg2[i]);
65
if
(
floating_point_exception
)
66
SET_NULL_D
(&res[i]);
67
}
68
}
69
return
0;
70
}
71
default
:
72
return
E_INV_TYPE
;
73
}
74
}
calc.h
E_INV_TYPE
@ E_INV_TYPE
Definition:
calc.h:15
E_ARG_TYPE
@ E_ARG_TYPE
Definition:
calc.h:13
E_ARG_HI
@ E_ARG_HI
Definition:
calc.h:12
E_ARG_LO
@ E_ARG_LO
Definition:
calc.h:11
IS_NULL_C
#define IS_NULL_C(x)
Definition:
calc.h:26
floating_point_exception
volatile int floating_point_exception
Definition:
calc.c:8
SET_NULL_D
#define SET_NULL_D(x)
Definition:
calc.h:32
columns
int columns
Definition:
calc.c:11
SET_NULL_C
#define SET_NULL_C(x)
Definition:
calc.h:30
IS_NULL_F
#define IS_NULL_F(x)
Definition:
calc.h:27
IS_NULL_D
#define IS_NULL_D(x)
Definition:
calc.h:28
SET_NULL_F
#define SET_NULL_F(x)
Definition:
calc.h:31
gis.h
FCELL
float FCELL
Definition:
gis.h:630
DCELL
double DCELL
Definition:
gis.h:629
CELL
int CELL
Definition:
gis.h:628
raster.h
FCELL_TYPE
#define FCELL_TYPE
Definition:
raster.h:12
DCELL_TYPE
#define DCELL_TYPE
Definition:
raster.h:13
CELL_TYPE
#define CELL_TYPE
Definition:
raster.h:11
f_mod
int f_mod(int argc, const int *argt, void **args)
Definition:
xmod.c:11
lib
calc
xmod.c
Generated on Thu Nov 21 2024 07:03:31 for GRASS GIS 8 Programmer's Manual by
1.9.1