| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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/meta/likely.hpp>
8
9 namespace stan {
10 namespace math {
11
12 template <typename T>
13 inline fvar<T> fmax(const fvar<T>& x1, const fvar<T>& x2) {
14 using ::fmax;
15 using stan::math::NOT_A_NUMBER;
16 if (unlikely(boost::math::isnan(x1.val_))) {
17 if (boost::math::isnan(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(boost::math::isnan(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 using stan::math::NOT_A_NUMBER;
36 if (unlikely(boost::math::isnan(x1))) {
37 if (boost::math::isnan(x2.val_))
38 return fvar<T>(fmax(x1, x2.val_), NOT_A_NUMBER);
39 else
40 return fvar<T>(x2.val_, x2.d_);
41 } else if (unlikely(boost::math::isnan(x2.val_))) {
42 return fvar<T>(x1, 0.0);
43 } else if (x1 > x2.val_) {
44 return fvar<T>(x1, 0.0);
45 } else if (x1 == x2.val_) {
46 return fvar<T>(x2.val_, NOT_A_NUMBER);
47 } else {
48 return fvar<T>(x2.val_, x2.d_);
49 }
50 }
51
52 template <typename T>
53 inline fvar<T> fmax(const fvar<T>& x1, const double x2) {
54 using ::fmax;
55 using stan::math::NOT_A_NUMBER;
56 if (unlikely(boost::math::isnan(x1.val_))) {
57 if (boost::math::isnan(x2))
58 return fvar<T>(fmax(x1.val_, x2), NOT_A_NUMBER);
59 else
60 return fvar<T>(x2, 0.0);
61 } else if (unlikely(boost::math::isnan(x2))) {
62 return fvar<T>(x1.val_, x1.d_);
63 } else if (x1.val_ > x2) {
64 return fvar<T>(x1.val_, x1.d_);
65 } else if (x1.val_ == x2) {
66 return fvar<T>(x1.val_, NOT_A_NUMBER);
67 } else {
68 return fvar<T>(x2, 0.0);
69 }
70 }
71 }
72 }
73 #endif
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:15
stan::math::NOT_A_NUMBER
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:56
stan::math::fmax
var fmax(const double &a, const stan::math::var &b)
Returns the maximum of a scalar and variable, promoting the scalar to a variable if it is larger (C99...
Definition: fmax.hpp:127
boost::math::isnan
bool isnan(const stan::math::var &v)
Checks if the given number is NaN.
Definition: boost_isnan.hpp:22
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::fvar::val_
T val_
Definition: fvar.hpp:14
likely.hpp
constants.hpp
stan::math::fmax
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmax.hpp:13
stan::math::fvar
Definition: fvar.hpp:13

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