Automatic Differentiation
 
Loading...
Searching...
No Matches
fmax.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_FMAX_HPP
2#define STAN_MATH_FWD_FUN_FMAX_HPP
3
9
10namespace stan {
11namespace math {
12
22template <typename T>
23inline fvar<T> fmax(const fvar<T>& x1, const fvar<T>& x2) {
24 if (unlikely(is_nan(x1))) {
25 if (unlikely(is_nan(x2))) {
27 }
28 return x2;
29 }
30 if (unlikely(is_nan(x2))) {
31 return x1;
32 }
33 return x1 > x2 ? x1 : x2;
34}
35
45template <typename T>
46inline fvar<T> fmax(double x1, const fvar<T>& x2) {
47 if (unlikely(is_nan(x1))) {
48 if (unlikely(is_nan(x2))) {
50 }
51 return x2;
52 }
53 if (unlikely(is_nan(x2))) {
54 return fvar<T>(x1, 0);
55 }
56 return x1 > x2 ? fvar<T>(x1, 0) : x2;
57}
58
68template <typename T>
69inline fvar<T> fmax(const fvar<T>& x1, double x2) {
70 if (unlikely(is_nan(x1))) {
71 if (unlikely(is_nan(x2))) {
73 }
74 return fvar<T>(x2, 0);
75 }
76 if (unlikely(is_nan(x2))) {
77 return x1;
78 }
79 return x1 >= x2 ? x1 : fvar<T>(x2, 0);
80}
81
82} // namespace math
83} // namespace stan
84#endif
#define unlikely(x)
static constexpr double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition constants.hpp:56
bool is_nan(T &&x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition is_nan.hpp:22
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Return the greater of the two specified arguments.
Definition fmax.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40