GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72086
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 {
45  res[i] = (argc > 1)
46  ? pow(arg1[i], arg2[i])
47  : exp(arg1[i]);
49  SET_NULL_D(&res[i]);
50  }
51 
52  return 0;
53 }
int f_exp(int argc, const int *argt, void **args)
Definition: xexp.c:16
double DCELL
Definition: gis.h:581
#define NULL
Definition: ccmath.h:32
Definition: calc.h:13
int columns
Definition: calc.c:12
volatile int floating_point_exception
Definition: calc.c:9
#define DCELL_TYPE
Definition: raster.h:13
Definition: calc.h:12
#define IS_NULL_D(x)
Definition: calc.h:30
#define SET_NULL_D(x)
Definition: calc.h:34