Stan Math Library  2.12.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/core.hpp>
9 
10 namespace stan {
11  namespace math {
12 
61  inline var fmax(const var& a,
62  const var& b) {
63  if (unlikely(is_nan(a))) {
64  if (unlikely(is_nan(b)))
65  return var(new precomp_vv_vari(NOT_A_NUMBER,
66  a.vi_, b.vi_,
68  return b;
69  }
70  if (unlikely(is_nan(b)))
71  return a;
72  return a > b ? a : b;
73  }
74 
89  inline var fmax(const var& a,
90  double b) {
91  if (unlikely(is_nan(a))) {
92  if (unlikely(is_nan(b)))
93  return var(new precomp_v_vari(NOT_A_NUMBER,
94  a.vi_,
95  NOT_A_NUMBER));
96  return var(b);
97  }
98  if (unlikely(is_nan(b)))
99  return a;
100  return a >= b ? a : var(b);
101  }
102 
117  inline var fmax(double a,
118  const var& b) {
119  if (unlikely(is_nan(b))) {
120  if (unlikely(is_nan(a)))
121  return var(new precomp_v_vari(NOT_A_NUMBER,
122  b.vi_,
123  NOT_A_NUMBER));
124  return var(a);
125  }
126  if (unlikely(is_nan(a)))
127  return b;
128  return a > b ? var(a) : b;
129  }
130 
131  }
132 }
133 #endif
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:55
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:30
#define unlikely(x)
Definition: likely.hpp:9
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:42
int is_nan(const fvar< T > &x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition: is_nan.hpp:21
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmax.hpp:14

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