Stan Math Library  2.20.0
reverse mode automatic differentiation
fmin.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_FMIN_HPP
2 #define STAN_MATH_REV_SCAL_FUN_FMIN_HPP
3 
4 #include <stan/math/rev/meta.hpp>
5 #include <stan/math/rev/core.hpp>
9 
10 namespace stan {
11 namespace math {
12 
57 inline var fmin(const var& a, const var& b) {
58  if (unlikely(is_nan(a))) {
59  if (unlikely(is_nan(b)))
61  NOT_A_NUMBER));
62  return b;
63  }
64  if (unlikely(is_nan(b)))
65  return a;
66  return a < b ? a : b;
67 }
68 
83 inline var fmin(const var& a, double b) {
84  if (unlikely(is_nan(a))) {
85  if (unlikely(is_nan(b)))
87  return var(b);
88  }
89  if (unlikely(is_nan(b)))
90  return a;
91  return a <= b ? a : var(b);
92 }
93 
108 inline var fmin(double a, const var& b) {
109  if (unlikely(is_nan(b))) {
110  if (unlikely(is_nan(a)))
112  return var(a);
113  }
114  if (unlikely(is_nan(a)))
115  return b;
116  return b <= a ? b : var(a);
117 }
118 
119 } // namespace math
120 } // namespace stan
121 #endif
fvar< T > fmin(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmin.hpp:14
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:58
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
#define unlikely(x)
Definition: likely.hpp:9
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:45
int is_nan(const fvar< T > &x)
Returns 1 if the input&#39;s value is NaN and 0 otherwise.
Definition: is_nan.hpp:20

     [ Stan Home Page ] © 2011–2018, Stan Development Team.