Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
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/core.hpp>
5 #include <boost/math/special_functions/fpclassify.hpp>
10 
11 namespace stan {
12 
13  namespace math {
14 
59  inline var fmin(const stan::math::var& a,
60  const stan::math::var& b) {
62  if (unlikely(is_nan(a))) {
63  if (unlikely(is_nan(b)))
64  return var(new precomp_vv_vari(NOT_A_NUMBER,
65  a.vi_, b.vi_,
67  return b;
68  }
69 
70  if (unlikely(is_nan(b)))
71  return a;
72 
73  return a < b ? a : b;
74  }
75 
89  inline var fmin(const stan::math::var& a,
90  double b) {
92  if (unlikely(is_nan(a))) {
93  if (unlikely(is_nan(b)))
94  return var(new precomp_v_vari(NOT_A_NUMBER,
95  a.vi_,
96  NOT_A_NUMBER));
97  return var(b);
98  }
99 
100  if (unlikely(is_nan(b)))
101  return a;
102 
103  return a <= b ? a : var(b);
104  }
105 
120  inline var fmin(double a,
121  const stan::math::var& b) {
123  if (unlikely(is_nan(b))) {
124  if (unlikely(is_nan(a)))
125  return var(new precomp_v_vari(NOT_A_NUMBER,
126  b.vi_,
127  NOT_A_NUMBER));
128 
129  return var(a);
130  }
131 
132  if (unlikely(is_nan(a)))
133  return b;
134 
135  return b <= a ? b : var(a);
136  }
137 
138  }
139 }
140 #endif
fvar< T > fmin(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmin.hpp:13
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:56
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
#define unlikely(x)
Definition: likely.hpp:9
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
int is_nan(const fvar< T > &x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition: is_nan.hpp:22

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