GRASS 8 Programmer's Manual
8.6.0dev(2026)-5f4f7ad06c
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
}
calc.h
E_RES_TYPE
@ E_RES_TYPE
Definition
calc.h:14
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
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
IS_NULL_D
#define IS_NULL_D(x)
Definition
calc.h:28
AMI_STREAM
Definition
ami_stream.h:153
f_log
func_t f_log
gis.h
DCELL
double DCELL
Definition
gis.h:635
raster.h
DCELL_TYPE
#define DCELL_TYPE
Definition
raster.h:13
lib
calc
xlog.c
Generated on Sat Apr 4 2026 07:00:45 for GRASS 8 Programmer's Manual by
1.9.8