Automatic Differentiation
 
Loading...
Searching...
No Matches
copysign.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_SCAL_FUN_COPYSIGN_HPP
2#define STAN_MATH_PRIM_SCAL_FUN_COPYSIGN_HPP
3
6#include <cmath>
7#include <complex>
8
9namespace stan {
10namespace math {
11
29template <typename T, typename U>
30inline T copysign(const T& x, const U& y) {
31 return (std::signbit(value_of_rec(x)) != std::signbit(value_of_rec(y))) ? -x
32 : x;
33}
34
48template <typename T, typename U>
49inline T copysign_non_zero(const T& x, const U& y) {
50 return x != 0 ? stan::math::copysign(x, y) : x;
51}
52
71template <typename T, typename U>
72inline std::complex<T> copysign(const std::complex<T>& x,
73 const std::complex<U>& y) {
74 return {copysign_non_zero(x.real(), y.real()),
75 copysign_non_zero(x.imag(), y.imag())};
76}
77
78} // namespace math
79} // namespace stan
80
81#endif
copysign_< as_operation_cl_t< T1 >, as_operation_cl_t< T2 > > copysign(T1 &&a, T2 &&b)
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
T copysign_non_zero(const T &x, const U &y)
Return the negation of the first argument if the first and second arguments have different signs and ...
Definition copysign.hpp:49
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...