Stan
1.3
probability, sampling & optimization
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerator
Friends
Macros
Pages
src
stan
math
functions
log1p.hpp
Go to the documentation of this file.
1
#ifndef __STAN__MATH__FUNCTIONS__LOG1P_HPP__
2
#define __STAN__MATH__FUNCTIONS__LOG1P_HPP__
3
4
#include <boost/math/tools/promotion.hpp>
5
#include <stdexcept>
6
#include <boost/throw_exception.hpp>
7
8
namespace
stan {
9
namespace
math {
10
20
template
<
typename
T>
21
inline
typename
boost::math::tools::promote_args<T>::type
22
log1p
(
const
T x) {
23
using
std::log
;
24
if
(x < -1.0)
25
BOOST_THROW_EXCEPTION(std::domain_error (
"x can not be less than -1"
));
26
27
if
(x > 1
e
-9 || x < -1
e
-9)
28
return
log
(1.0 + x);
// direct, if distant from 1
29
else
if
(x > 1
e
-16 || x < -1
e
-16)
30
return
x - 0.5 * x * x;
// 2nd order Taylor, if close to 1
31
else
32
return
x;
// 1st order Taylor, if very close to 1
33
}
34
35
}
36
}
37
38
#endif
[
Stan Home Page
]
© 2011–2013, Stan Development Team.