GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
xexp.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
/**********************************************************************
9
exp(x) computes e raised to power x
10
exp(x,y) computes x raised to power y
11
12
if floating point exception occurs during the evaluation of exp(x)
13
or exp(x,y) the result is NULL
14
**********************************************************************/
15
16
int
f_exp
(
int
argc,
const
int
*argt,
void
**args)
17
{
18
DCELL
*res = args[0];
19
DCELL
*arg1 = args[1];
20
DCELL
*arg2;
21
int
i;
22
23
if
(argc < 1)
24
return
E_ARG_LO
;
25
if
(argc > 2)
26
return
E_ARG_HI
;
27
28
if
(argt[0] !=
DCELL_TYPE
)
29
return
E_RES_TYPE
;
30
31
if
(argt[1] !=
DCELL_TYPE
)
32
return
E_ARG_TYPE
;
33
34
arg2 = (argc > 1) ? args[2] :
NULL
;
35
36
for
(i = 0; i <
columns
; i++)
37
if
(
IS_NULL_D
(&arg1[i]))
38
SET_NULL_D
(&res[i]);
39
else
if
(argc > 1 &&
IS_NULL_D
(&arg2[i]))
40
SET_NULL_D
(&res[i]);
41
else
if
(argc > 1 && arg1[i] < 0 && arg2[i] != ceil(arg2[i]))
42
SET_NULL_D
(&res[i]);
43
else
{
44
floating_point_exception
= 0;
45
res[i] = (argc > 1)
46
? pow(arg1[i], arg2[i])
47
: exp(arg1[i]);
48
if
(
floating_point_exception
)
49
SET_NULL_D
(&res[i]);
50
}
51
52
return
0;
53
}
f_exp
int f_exp(int argc, const int *argt, void **args)
Definition:
xexp.c:16
DCELL
double DCELL
Definition:
gis.h:614
E_ARG_TYPE
Definition:
calc.h:14
NULL
#define NULL
Definition:
ccmath.h:32
E_ARG_HI
Definition:
calc.h:13
columns
int columns
Definition:
calc.c:12
floating_point_exception
volatile int floating_point_exception
Definition:
calc.c:9
raster.h
gis.h
DCELL_TYPE
#define DCELL_TYPE
Definition:
raster.h:13
E_ARG_LO
Definition:
calc.h:12
IS_NULL_D
#define IS_NULL_D(x)
Definition:
calc.h:30
E_RES_TYPE
Definition:
calc.h:15
SET_NULL_D
#define SET_NULL_D(x)
Definition:
calc.h:34
calc.h
lib
calc
xexp.c
Generated on Tue Feb 14 2023 05:56:02 for GRASS GIS 8 Programmer's Manual by
1.8.13