Skip to content

Commit

Permalink
use std::log which is more precise for arguments close to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Expander committed Mar 6, 2024
1 parent a96eb55 commit e60222d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cpp/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ namespace polylogarithm {

template <typename T>
struct Complex {
constexpr Complex(T re_ = T{}, T im_ = T{}) : re(re_), im(im_) {}
operator std::complex<T>() const noexcept { return std::complex<T>(re, im); }
constexpr Complex(T re_ = T{}, T im_ = T{}) noexcept : re(re_), im(im_) {}
constexpr Complex(const std::complex<T>& z) noexcept : re(std::real(z)), im(std::imag(z)) {}
constexpr operator std::complex<T>() const noexcept { return std::complex<T>(re, im); }
T re{};
T im{};
};
Expand All @@ -39,7 +40,7 @@ Complex<T> log(const Complex<T>& z) noexcept
} else if (z.im == T(0)) {
return { std::log(-z.re), 4*std::atan(T(1)) };
}
return { std::log(norm(z)), arg(z) };
return std::log(std::complex<T>(z));
}

template <typename T>
Expand Down

0 comments on commit e60222d

Please sign in to comment.