Stan Math Library
2.8.0
reverse mode automatic differentiation
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerator
Friends
Macros
Groups
stan
math
fwd
scal
fun
fdim.hpp
Go to the documentation of this file.
1
#ifndef STAN_MATH_FWD_SCAL_FUN_FDIM_HPP
2
#define STAN_MATH_FWD_SCAL_FUN_FDIM_HPP
3
4
#include <
stan/math/fwd/core.hpp
>
5
#include <
stan/math/prim/scal/fun/fdim.hpp
>
6
7
namespace
stan {
8
namespace
math {
9
10
template
<
typename
T>
11
inline
fvar<T>
fdim
(
const
fvar<T>
& x1,
const
fvar<T>
& x2) {
12
using
stan::math::fdim
;
13
using
std::floor
;
14
if
(x1.
val_
< x2.
val_
)
15
return
fvar<T>
(
fdim
(x1.
val_
, x2.
val_
), 0);
16
else
17
return
fvar<T>
(
fdim
(x1.
val_
, x2.
val_
),
18
x1.
d_
- x2.
d_
*
floor
(x1.
val_
/ x2.
val_
));
19
}
20
21
template
<
typename
T>
22
inline
fvar<T>
fdim
(
const
fvar<T>
& x1,
const
double
x2) {
23
using
stan::math::fdim
;
24
using
std::floor
;
25
if
(x1.
val_
< x2)
26
return
fvar<T>
(
fdim
(x1.
val_
, x2), 0);
27
else
28
return
fvar<T>
(
fdim
(x1.
val_
, x2), x1.
d_
);
29
}
30
31
template
<
typename
T>
32
inline
fvar<T>
fdim
(
const
double
x1,
const
fvar<T>
& x2) {
33
using
stan::math::fdim
;
34
using
std::floor
;
35
if
(x1 < x2.
val_
)
36
return
fvar<T>
(
fdim
(x1, x2.
val_
), 0);
37
else
38
return
fvar<T>
(
fdim
(x1, x2.
val_
), x2.
d_
* -
floor
(x1 / x2.
val_
));
39
}
40
41
}
42
}
43
#endif
core.hpp
stan::math::fvar::d_
T d_
Definition:
fvar.hpp:15
stan::math::fvar::val_
T val_
Definition:
fvar.hpp:14
stan::math::fdim
fvar< T > fdim(const fvar< T > &x1, const fvar< T > &x2)
Definition:
fdim.hpp:11
stan::math::floor
fvar< T > floor(const fvar< T > &x)
Definition:
floor.hpp:11
stan::math::fvar
Definition:
fvar.hpp:13
fdim.hpp
[
Stan Home Page
]
© 2011–2015, Stan Development Team.