Automatic Differentiation
 
Loading...
Searching...
No Matches
fmin.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_FMIN_HPP
2#define STAN_MATH_FWD_FUN_FMIN_HPP
3
9
10namespace stan {
11namespace math {
12
13template <typename T>
14inline fvar<T> fmin(const fvar<T>& x1, const fvar<T>& x2) {
15 if (unlikely(is_nan(x1))) {
16 if (unlikely(is_nan(x2))) {
18 }
19 return x2;
20 }
21 if (unlikely(is_nan(x2))) {
22 return x1;
23 }
24 return x1 < x2 ? x1 : x2;
25}
26
27template <typename T>
28inline fvar<T> fmin(double x1, const fvar<T>& x2) {
29 if (unlikely(is_nan(x1))) {
30 if (unlikely(is_nan(x2))) {
32 }
33 return x2;
34 }
35 if (unlikely(is_nan(x2))) {
36 return fvar<T>(x1, 0);
37 }
38 return x2 <= x1 ? x2 : fvar<T>(x1, 0);
39}
40
41template <typename T>
42inline fvar<T> fmin(const fvar<T>& x1, double x2) {
43 if (unlikely(is_nan(x1))) {
44 if (unlikely(is_nan(x2))) {
46 }
47 return fvar<T>(x2, 0);
48 }
49 if (unlikely(is_nan(x2))) {
50 return x1;
51 }
52 return x1 <= x2 ? x1 : fvar<T>(x2, 0);
53}
54
55} // namespace math
56} // namespace stan
57#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 > fmin(const fvar< T > &x1, const fvar< T > &x2)
Definition fmin.hpp:14
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