GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
xlog.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
log(x)
9
log(x,b)
10
11
first form computes the natural log of x = ln(x)
12
second form computes log of x base b = ln(x)/ln(b)
13
14
if x is non-positive, or floating point exception occurs while
15
computing ln(x), the result is NULL
16
17
if b is non-positive, or 1.0, or floating point exception occurs while
18
computing ln(b), the result is NULL
19
**********************************************************************/
20
21
int
f_log
(
int
argc,
const
int
*argt,
void
**args)
22
{
23
DCELL *res = args[0];
24
DCELL *arg1 = args[1];
25
DCELL *arg2 = (argc >= 2) ? args[2] : (DCELL *)0;
26
int
i;
27
28
if
(argc < 1)
29
return
E_ARG_LO;
30
31
if
(argc > 2)
32
return
E_ARG_HI;
33
34
if
(argt[0] != DCELL_TYPE)
35
return
E_RES_TYPE;
36
37
if
(argt[1] != DCELL_TYPE)
38
return
E_ARG_TYPE;
39
40
if
(argc > 1 && argt[2] != DCELL_TYPE)
41
return
E_ARG_TYPE;
42
43
for
(i = 0; i <
columns
; i++)
44
if
(IS_NULL_D(&arg1[i]) || (arg1[i] <= 0.0))
45
SET_NULL_D(&res[i]);
46
else
if
(argc > 1 && (IS_NULL_D(&arg2[i]) || (arg2[i] <= 0.0)))
47
SET_NULL_D(&res[i]);
48
else
{
49
floating_point_exception
= 0;
50
res[i] = (argc > 1) ? log(arg1[i]) / log(arg2[i]) : log(arg1[i]);
51
if
(
floating_point_exception
)
52
SET_NULL_D(&res[i]);
53
}
54
55
return
0;
56
}
floating_point_exception
volatile int floating_point_exception
Definition
calc.c:8
columns
int columns
Definition
calc.c:11
f_log
int f_log(int argc, const int *argt, void **args)
Definition
xlog.c:21
calc
xlog.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0