| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

fmax.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_FMAX_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_FMAX_HPP
3
4 #include <math.h>
5 #include <stan/math/fwd/core.hpp>
6 #include <stan/math/prim/scal/fun/constants.hpp>
7 #include <stan/math/prim/scal/fun/is_nan.hpp>
8 #include <stan/math/prim/scal/meta/likely.hpp>
9
10 namespace stan {
11 namespace math {
12
13 template <typename T>
14 inline fvar<T> fmax(const fvar<T>& x1, const fvar<T>& x2) {
15 using ::fmax;
16 if (unlikely(is_nan(x1.val_))) {
17 if (is_nan(x2.val_))
18 return fvar<T>(fmax(x1.val_, x2.val_), NOT_A_NUMBER);
19 else
20 return fvar<T>(x2.val_, x2.d_);
21 } else if (unlikely(is_nan(x2.val_))) {
22 return fvar<T>(x1.val_, x1.d_);
23 } else if (x1.val_ > x2.val_) {
24 return fvar<T>(x1.val_, x1.d_);
25 } else if (x1.val_ == x2.val_) {
26 return fvar<T>(x1.val_, NOT_A_NUMBER);
27 } else {
28 return fvar<T>(x2.val_, x2.d_);
29 }
30 }
31
32 template <typename T>
33 inline fvar<T> fmax(const double x1, const fvar<T>& x2) {
34 using ::fmax;
35 if (unlikely(is_nan(x1))) {
36 if (is_nan(x2.val_))
37 return fvar<T>(fmax(x1, x2.val_), NOT_A_NUMBER);
38 else
39 return fvar<T>(x2.val_, x2.d_);
40 } else if (unlikely(is_nan(x2.val_))) {
41 return fvar<T>(x1, 0.0);
42 } else if (x1 > x2.val_) {
43 return fvar<T>(x1, 0.0);
44 } else if (x1 == x2.val_) {
45 return fvar<T>(x2.val_, NOT_A_NUMBER);
46 } else {
47 return fvar<T>(x2.val_, x2.d_);
48 }
49 }
50
51 template <typename T>
52 inline fvar<T> fmax(const fvar<T>& x1, const double x2) {
53 using ::fmax;
54 if (unlikely(is_nan(x1.val_))) {
55 if (is_nan(x2))
56 return fvar<T>(fmax(x1.val_, x2), NOT_A_NUMBER);
57 else
58 return fvar<T>(x2, 0.0);
59 } else if (unlikely(is_nan(x2))) {
60 return fvar<T>(x1.val_, x1.d_);
61 } else if (x1.val_ > x2) {
62 return fvar<T>(x1.val_, x1.d_);
63 } else if (x1.val_ == x2) {
64 return fvar<T>(x1.val_, NOT_A_NUMBER);
65 } else {
66 return fvar<T>(x2, 0.0);
67 }
68 }
69 }
70 }
71 #endif
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:14
stan::math::NOT_A_NUMBER
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:55
is_nan.hpp
stan
Definition: log_sum_exp.hpp:8
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::fvar::val_
T val_
Definition: fvar.hpp:13
likely.hpp
constants.hpp
stan::math::is_nan
int is_nan(const fvar< T > &x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition: is_nan.hpp:21
stan::math::fmax
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmax.hpp:14
stan::math::fvar
Definition: fvar.hpp:12
stan::math::fmax
var fmax(double a, const var &b)
Returns the maximum of a scalar and variable, promoting the scalar to a variable if it is larger (C99...
Definition: fmax.hpp:117

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