Stan Math Library  2.20.0
reverse mode automatic differentiation
fmax.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_FMAX_HPP
2 #define STAN_MATH_REV_SCAL_FUN_FMAX_HPP
3 
4 #include <stan/math/rev/meta.hpp>
5 #include <stan/math/rev/core.hpp>
9 
10 namespace stan {
11 namespace math {
12 
61 inline var fmax(const var& a, const var& b) {
62  if (unlikely(is_nan(a))) {
63  if (unlikely(is_nan(b)))
65  NOT_A_NUMBER));
66  return b;
67  }
68  if (unlikely(is_nan(b)))
69  return a;
70  return a > b ? a : b;
71 }
72 
87 inline var fmax(const var& a, double b) {
88  if (unlikely(is_nan(a))) {
89  if (unlikely(is_nan(b)))
91  return var(b);
92  }
93  if (unlikely(is_nan(b)))
94  return a;
95  return a >= b ? a : var(b);
96 }
97 
112 inline var fmax(double a, const var& b) {
113  if (unlikely(is_nan(b))) {
114  if (unlikely(is_nan(a)))
116  return var(a);
117  }
118  if (unlikely(is_nan(a)))
119  return b;
120  return a > b ? var(a) : b;
121 }
122 
123 } // namespace math
124 } // namespace stan
125 #endif
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
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Return the greater of the two specified arguments.
Definition: fmax.hpp:22

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