All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
fmin.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_FWD_SCAL_FUN_FMIN_HPP
#define STAN_MATH_FWD_SCAL_FUN_FMIN_HPP
#include <math.h>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/scal/fun/constants.hpp>
#include <stan/math/prim/scal/meta/likely.hpp>
namespace stan {
namespace math {
template <typename T>
inline fvar<T> fmin(const fvar<T>& x1, const fvar<T>& x2) {
using ::fmin;
using stan::math::NOT_A_NUMBER;
if (unlikely(boost::math::isnan(x1.val_))) {
if (boost::math::isnan(x2.val_))
return fvar<T>(fmin(x1.val_, x2.val_), NOT_A_NUMBER);
else
return fvar<T>(x2.val_, x2.d_);
} else if (unlikely(boost::math::isnan(x2.val_))) {
return fvar<T>(x1.val_, x1.d_);
} else if (x1.val_ < x2.val_) {
return fvar<T>(x1.val_, x1.d_);
} else if (x1.val_ == x2.val_) {
return fvar<T>(x1.val_, NOT_A_NUMBER);
} else {
return fvar<T>(x2.val_, x2.d_);
}
}
template <typename T>
inline fvar<T> fmin(const double x1, const fvar<T>& x2) {
using ::fmin;
using stan::math::NOT_A_NUMBER;
if (unlikely(boost::math::isnan(x1))) {
if (boost::math::isnan(x2.val_))
return fvar<T>(fmin(x1, x2.val_), NOT_A_NUMBER);
else
return fvar<T>(x2.val_, x2.d_);
} else if (unlikely(boost::math::isnan(x2.val_))) {
return fvar<T>(x1, 0.0);
} else if (x1 < x2.val_) {
return fvar<T>(x1, 0.0);
} else if (x1 == x2.val_) {
return fvar<T>(x2.val_, NOT_A_NUMBER);
} else {
return fvar<T>(x2.val_, x2.d_);
}
}
template <typename T>
inline fvar<T> fmin(const fvar<T>& x1, const double x2) {
using ::fmin;
using stan::math::NOT_A_NUMBER;
if (unlikely(boost::math::isnan(x1.val_))) {
if (boost::math::isnan(x2))
return fvar<T>(fmin(x1.val_, x2), NOT_A_NUMBER);
else
return fvar<T>(x2, 0.0);
} else if (unlikely(boost::math::isnan(x2))) {
return fvar<T>(x1.val_, x1.d_);
} else if (x1.val_ < x2) {
return fvar<T>(x1.val_, x1.d_);
} else if (x1.val_ == x2) {
return fvar<T>(x1.val_, NOT_A_NUMBER);
} else {
return fvar<T>(x2, 0.0);
}
}
}
}
#endif
stan::math::fmin
fvar< T > fmin(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmin.hpp:13
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::fmin
var fmin(double a, const stan::math::var &b)
Returns the minimum of a scalar and variable, promoting the scalar to a variable if it is larger (C99...
Definition: fmin.hpp:120
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::fvar
Definition: fvar.hpp:13

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