Automatic Differentiation
 
Loading...
Searching...
No Matches
operator_division.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_CORE_OPERATOR_DIVISION_HPP
2#define STAN_MATH_FWD_CORE_OPERATOR_DIVISION_HPP
3
6#include <complex>
7#include <type_traits>
8
9namespace stan {
10namespace math {
11
20template <typename T>
21inline fvar<T> operator/(const fvar<T>& x1, const fvar<T>& x2) {
22 return fvar<T>(x1.val_ / x2.val_,
23 (x1.d_ * x2.val_ - x1.val_ * x2.d_) / (x2.val_ * x2.val_));
24}
25
34template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
35inline fvar<T> operator/(const fvar<T>& x1, U x2) {
36 return fvar<T>(x1.val_ / static_cast<double>(x2),
37 x1.d_ / static_cast<double>(x2));
38}
39
48template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
49inline fvar<T> operator/(U x1, const fvar<T>& x2) {
50 return fvar<T>(static_cast<double>(x1) / x2.val_,
51 -static_cast<double>(x1) * x2.d_ / (x2.val_ * x2.val_));
52}
53
54template <typename T>
55inline std::complex<fvar<T>> operator/(const std::complex<fvar<T>>& x1,
56 const std::complex<fvar<T>>& x2) {
57 return internal::complex_divide(x1, x2);
58}
59template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
60inline std::complex<fvar<T>> operator/(const std::complex<fvar<T>>& x1,
61 const std::complex<U>& x2) {
62 return internal::complex_divide(x1, x2);
63}
64template <typename T>
65inline std::complex<fvar<T>> operator/(const std::complex<fvar<T>>& x1,
66 const fvar<T>& x2) {
67 return internal::complex_divide(x1, x2);
68}
69template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
70inline std::complex<fvar<T>> operator/(const std::complex<fvar<T>>& x1, U x2) {
71 return internal::complex_divide(x1, x2);
72}
73
74template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
75inline std::complex<fvar<T>> operator/(const std::complex<U>& x1,
76 const std::complex<fvar<T>>& x2) {
77 return internal::complex_divide(x1, x2);
78}
79template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
80inline std::complex<fvar<T>> operator/(const std::complex<U>& x1,
81 const fvar<T>& x2) {
82 return internal::complex_divide(x1, x2);
83}
84
85template <typename T>
86inline std::complex<fvar<T>> operator/(const fvar<T>& x1,
87 const std::complex<fvar<T>>& x2) {
88 return internal::complex_divide(x1, x2);
89}
90template <typename T, typename U,
91 typename = std::enable_if_t<std::is_arithmetic<U>::value>>
92inline std::complex<fvar<T>> operator/(const fvar<T>& x1,
93 const std::complex<U>& x2) {
94 return internal::complex_divide(x1, x2);
95}
96
97template <typename T, typename U, require_arithmetic_t<U>* = nullptr>
98inline std::complex<fvar<T>> operator/(U x1, const std::complex<fvar<T>>& x2) {
99 return internal::complex_divide(x1, x2);
100}
101
102} // namespace math
103} // namespace stan
104#endif
complex_return_t< U, V > complex_divide(const U &lhs, const V &rhs)
Return the quotient of the specified arguments.
fvar< T > operator/(const fvar< T > &x1, const fvar< T > &x2)
Return the result of dividing the first argument by the second.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40