Automatic Differentiation
 
Loading...
Searching...
No Matches
fdim.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_FDIM_HPP
2#define STAN_MATH_FWD_FUN_FDIM_HPP
3
7
8namespace stan {
9namespace math {
10
20template <typename T>
21inline fvar<T> fdim(const fvar<T>& x, const fvar<T>& y) {
22 if (x.val_ < y.val_) {
23 return fvar<T>(fdim(x.val_, y.val_), 0);
24 } else {
25 return fvar<T>(fdim(x.val_, y.val_), x.d_ - y.d_);
26 }
27}
28
38template <typename T>
39inline fvar<T> fdim(const fvar<T>& x, double y) {
40 if (x.val_ < y) {
41 return fvar<T>(fdim(x.val_, y), 0);
42 } else {
43 return fvar<T>(fdim(x.val_, y), x.d_);
44 }
45}
46
56template <typename T>
57inline fvar<T> fdim(double x, const fvar<T>& y) {
58 if (x < y.val_) {
59 return fvar<T>(fdim(x, y.val_), 0);
60 } else {
61 return fvar<T>(fdim(x, y.val_), -y.d_);
62 }
63}
64
65} // namespace math
66} // namespace stan
67#endif
fvar< T > fdim(const fvar< T > &x, const fvar< T > &y)
Return the positive difference of the specified values (C++11).
Definition fdim.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40