HelenOS sources
This source file includes following definitions.
- imag_
- real
- real
- imag
- imag
- imag_
- real
- real
- imag
- imag
- imag_
- real
- real
- imag
- imag
- imag_
- real
- real
- imag
- imag
- real
- imag
- abs
- arg
- norm
- conj
- proj
- polar
- acos
- asin
- atan
- acosh
- asinh
- atanh
- cos
- cosh
- exp
- log
- log10
- pow
- pow
- pow
- sin
- sinh
- sqrt
- tan
- tanh
#ifndef LIBCPP_BITS_COMPLEX
#define LIBCPP_BITS_COMPLEX
#include <cassert>
#include <iosfwd>
#include <sstream>
namespace std
{
template<class T>
class complex
{
public:
using value_type = T;
constexpr complex(const value_type& re = value_type{},
const value_type& im = value_type{})
: real_{re}, imag_{im}
{ }
constexpr complex(const complex& other)
: real_{other.real_}, imag_{other.imag_}
{ }
template<class U>
constexpr complex(const complex<U>& other)
: real_(other.real()), imag_(other.imag())
{ }
constexpr value_type real() const
{
return real_;
}
void real(value_type val)
{
real_ = val;
}
constexpr value_type imag() const
{
return imag_;
}
void imag(value_type val)
{
imag_ = val;
}
complex& operator=(const value_type& val)
{
real_ = val;
imag_ = value_type{};
return *this;
}
complex& operator+=(const value_type& val)
{
real_ += val;
return *this;
}
complex& operator-=(const value_type& val)
{
real_ -= val;
return *this;
}
complex& operator*=(const value_type& val)
{
real_ *= val;
imag_ *= val;
return *this;
}
complex& operator/=(const value_type& val)
{
real_ /= val;
imag_ /= val;
return *this;
}
complex& operator=(const complex& other)
{
real_ = other.real_;
imag_ = other.imag_;
return *this;
}
template<class U>
complex& operator=(const complex<U>& rhs)
{
real_ = rhs.real_;
imag_ = rhs.imag_;
return *this;
}
template<class U>
complex& operator+=(const complex<U>& rhs)
{
real_ += rhs.real_;
imag_ += rhs.imag_;
return *this;
}
template<class U>
complex& operator-=(const complex<U>& rhs)
{
real_ -= rhs.real_;
imag_ -= rhs.imag_;
return *this;
}
template<class U>
complex& operator*=(const complex<U>& rhs)
{
auto old_real = real_;
real_ = real_ * rhs.real_ - imag_ * rhs.imag_;
imag_ = old_real * rhs.imag_ + imag_ * rhs.real_;
return *this;
}
template<class U>
complex& operator/=(const complex<U>& rhs)
{
auto old_real = real_;
real_ = (real_ * rhs.real_ + imag_ * rhs.imag_)
/ (rhs.real_ * rhs.real_ + rhs.imag_ * rhs.imag_);
imag_ = (imag_ * rhs.real_ - old_real * rhs.imag_)
/ (rhs.real_ * rhs.real_ + rhs.imag_ * rhs.imag_);
return *this;
}
private:
value_type real_;
value_type imag_;
};
template<>
class complex<float>
{
public:
using value_type = float;
constexpr complex(const value_type& re = value_type{},
const value_type& im = value_type{})
: real_{re}, imag_{im}
{ }
constexpr complex(const complex& other)
: real_{other.real_}, imag_{other.imag_}
{ }
template<class U>
constexpr complex(const complex<U>& other)
: real_(other.real()), imag_(other.imag())
{ }
constexpr value_type real() const
{
return real_;
}
void real(value_type val)
{
real_ = val;
}
constexpr value_type imag() const
{
return imag_;
}
void imag(value_type val)
{
imag_ = val;
}
complex& operator=(const value_type& val)
{
real_ = val;
imag_ = value_type{};
return *this;
}
complex& operator+=(const value_type& val)
{
real_ += val;
return *this;
}
complex& operator-=(const value_type& val)
{
real_ -= val;
return *this;
}
complex& operator*=(const value_type& val)
{
real_ *= val;
imag_ *= val;
return *this;
}
complex& operator/=(const value_type& val)
{
real_ /= val;
imag_ /= val;
return *this;
}
complex& operator=(const complex& other)
{
real_ = other.real_;
imag_ = other.imag_;
return *this;
}
template<class U>
complex& operator=(const complex<U>& rhs)
{
real_ = rhs.real_;
imag_ = rhs.imag_;
return *this;
}
template<class U>
complex& operator+=(const complex<U>& rhs)
{
real_ += rhs.real_;
imag_ += rhs.imag_;
return *this;
}
template<class U>
complex& operator-=(const complex<U>& rhs)
{
real_ -= rhs.real_;
imag_ -= rhs.imag_;
return *this;
}
template<class U>
complex& operator*=(const complex<U>& rhs)
{
auto old_real = real_;
real_ = real_ * rhs.real_ - imag_ * rhs.imag_;
imag_ = old_real * rhs.imag_ + imag_ * rhs.real_;
return *this;
}
template<class U>
complex& operator/=(const complex<U>& rhs)
{
auto old_real = real_;
real_ = (real_ * rhs.real_ + imag_ * rhs.imag_)
/ (rhs.real_ * rhs.real_ + rhs.imag_ * rhs.imag_);
imag_ = (imag_ * rhs.real_ - old_real * rhs.imag_)
/ (rhs.real_ * rhs.real_ + rhs.imag_ * rhs.imag_);
return *this;
}
private:
value_type real_;
value_type imag_;
};
template<>
class complex<double>
{
public:
using value_type = double;
constexpr complex(const value_type& re = value_type{},
const value_type& im = value_type{})
: real_{re}, imag_{im}
{ }
constexpr complex(const complex& other)
: real_{other.real_}, imag_{other.imag_}
{ }
template<class U>
constexpr complex(const complex<U>& other)
: real_(other.real()), imag_(other.imag())
{ }
constexpr value_type real() const
{
return real_;
}
void real(value_type val)
{
real_ = val;
}
constexpr value_type imag() const
{
return imag_;
}
void imag(value_type val)
{
imag_ = val;
}
complex& operator=(const value_type& val)
{
real_ = val;
imag_ = value_type{};
return *this;
}
complex& operator+=(const value_type& val)
{
real_ += val;
return *this;
}
complex& operator-=(const value_type& val)
{
real_ -= val;
return *this;
}
complex& operator*=(const value_type& val)
{
real_ *= val;
imag_ *= val;
return *this;
}
complex& operator/=(const value_type& val)
{
real_ /= val;
imag_ /= val;
return *this;
}
complex& operator=(const complex& other)
{
real_ = other.real_;
imag_ = other.imag_;
return *this;
}
template<class U>
complex& operator=(const complex<U>& rhs)
{
real_ = rhs.real_;
imag_ = rhs.imag_;
return *this;
}
template<class U>
complex& operator+=(const complex<U>& rhs)
{
real_ += rhs.real_;
imag_ += rhs.imag_;
return *this;
}
template<class U>
complex& operator-=(const complex<U>& rhs)
{
real_ -= rhs.real_;
imag_ -= rhs.imag_;
return *this;
}
template<class U>
complex& operator*=(const complex<U>& rhs)
{
auto old_real = real_;
real_ = real_ * rhs.real_ - imag_ * rhs.imag_;
imag_ = old_real * rhs.imag_ + imag_ * rhs.real_;
return *this;
}
template<class U>
complex& operator/=(const complex<U>& rhs)
{
auto old_real = real_;
real_ = (real_ * rhs.real_ + imag_ * rhs.imag_)
/ (rhs.real_ * rhs.real_ + rhs.imag_ * rhs.imag_);
imag_ = (imag_ * rhs.real_ - old_real * rhs.imag_)
/ (rhs.real_ * rhs.real_ + rhs.imag_ * rhs.imag_);
return *this;
}
private:
value_type real_;
value_type imag_;
};
template<>
class complex<long double>
{
public:
using value_type = long double;
constexpr complex(const value_type& re = value_type{},
const value_type& im = value_type{})
: real_{re}, imag_{im}
{ }
constexpr complex(const complex& other)
: real_{other.real_}, imag_{other.imag_}
{ }
template<class U>
constexpr complex(const complex<U>& other)
: real_(other.real()), imag_(other.imag())
{ }
constexpr value_type real() const
{
return real_;
}
void real(value_type val)
{
real_ = val;
}
constexpr value_type imag() const
{
return imag_;
}
void imag(value_type val)
{
imag_ = val;
}
complex& operator=(const value_type& val)
{
real_ = val;
imag_ = value_type{};
return *this;
}
complex& operator+=(const value_type& val)
{
real_ += val;
return *this;
}
complex& operator-=(const value_type& val)
{
real_ -= val;
return *this;
}
complex& operator*=(const value_type& val)
{
real_ *= val;
imag_ *= val;
return *this;
}
complex& operator/=(const value_type& val)
{
real_ /= val;
imag_ /= val;
return *this;
}
complex& operator=(const complex& other)
{
real_ = other.real_;
imag_ = other.imag_;
return *this;
}
template<class U>
complex& operator=(const complex<U>& rhs)
{
real_ = rhs.real_;
imag_ = rhs.imag_;
return *this;
}
template<class U>
complex& operator+=(const complex<U>& rhs)
{
real_ += rhs.real_;
imag_ += rhs.imag_;
return *this;
}
template<class U>
complex& operator-=(const complex<U>& rhs)
{
real_ -= rhs.real_;
imag_ -= rhs.imag_;
return *this;
}
template<class U>
complex& operator*=(const complex<U>& rhs)
{
auto old_real = real_;
real_ = real_ * rhs.real_ - imag_ * rhs.imag_;
imag_ = old_real * rhs.imag_ + imag_ * rhs.real_;
return *this;
}
template<class U>
complex& operator/=(const complex<U>& rhs)
{
auto old_real = real_;
real_ = (real_ * rhs.real_ + imag_ * rhs.imag_)
/ (rhs.real_ * rhs.real_ + rhs.imag_ * rhs.imag_);
imag_ = (imag_ * rhs.real_ - old_real* rhs.imag_)
/ (rhs.real_ * rhs.real_ + rhs.imag_ * rhs.imag_);
return *this;
}
private:
value_type real_;
value_type imag_;
};
template<class T>
complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs)
{
return complex<T>{lhs} += rhs;
}
template<class T>
complex<T> operator+(const complex<T>& lhs, const T& rhs)
{
return complex<T>{lhs} += rhs;
}
template<class T>
complex<T> operator+(const T& lhs, const complex<T>& rhs)
{
return complex<T>{lhs} += rhs;
}
template<class T>
complex<T> operator-(const complex<T>& lhs, const complex<T>& rhs)
{
return complex<T>{lhs} -= rhs;
}
template<class T>
complex<T> operator-(const complex<T>& lhs, const T& rhs)
{
return complex<T>{lhs} -= rhs;
}
template<class T>
complex<T> operator-(const T& lhs, const complex<T>& rhs)
{
return complex<T>{lhs} -= rhs;
}
template<class T>
complex<T> operator*(const complex<T>& lhs, const complex<T>& rhs)
{
return complex<T>{lhs} *= rhs;
}
template<class T>
complex<T> operator*(const complex<T>& lhs, const T& rhs)
{
return complex<T>{lhs} *= rhs;
}
template<class T>
complex<T> operator*(const T& lhs, const complex<T>& rhs)
{
return complex<T>{lhs} *= rhs;
}
template<class T>
complex<T> operator/(const complex<T>& lhs, const complex<T>& rhs)
{
return complex<T>{lhs} /= rhs;
}
template<class T>
complex<T> operator/(const complex<T>& lhs, const T& rhs)
{
return complex<T>{lhs} /= rhs;
}
template<class T>
complex<T> operator/(const T& lhs, const complex<T>& rhs)
{
return complex<T>{lhs} /= rhs;
}
template<class T>
complex<T> operator+(const complex<T>& c)
{
return complex<T>{c};
}
template<class T>
complex<T> operator-(const complex<T>& c)
{
return complex<T>{-c.real(), -c.imag()};
}
template<class T>
constexpr bool operator==(const complex<T>& lhs, const complex<T>& rhs)
{
return lhs.real() == rhs.real() && lhs.imag() == rhs.imag();
}
template<class T>
constexpr bool operator==(const complex<T>& lhs, const T& rhs)
{
return lhs.real() == rhs && lhs.imag() == T{};
}
template<class T>
constexpr bool operator==(const T& lhs, const complex<T>& rhs)
{
return lhs == rhs.real() && T{} == rhs.imag();
}
template<class T>
constexpr bool operator!=(const complex<T>& lhs, const complex<T>& rhs)
{
return lhs.real() != rhs.real() || lhs.imag() != rhs.imag();
}
template<class T>
constexpr bool operator!=(const complex<T>& lhs, const T& rhs)
{
return lhs.real() != rhs || lhs.imag() != T{};
}
template<class T>
constexpr bool operator!=(const T& lhs, const complex<T>& rhs)
{
return lhs != rhs.real() || T{} != rhs.imag();
}
template<class T, class Char, class Traits>
basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is,
const complex<T>& c)
{
__unimplemented();
return is;
}
template<class T, class Char, class Traits>
basic_ostream<Char, Traits>& operator<<(basic_ostream<Char, Traits>& os,
const complex<T>& c)
{
basic_ostringstream<Char, Traits> oss{};
oss.flags(os.flags());
oss.imbue(os.getloc());
oss.precision(os.precision());
oss << "(" << c.real() << "," << c.imag() << ")";
return os << oss.str();
}
template<class T>
constexpr T real(const complex<T>& c)
{
return c.real();
}
template<class T>
constexpr T imag(const complex<T>& c)
{
return c.imag();
}
template<class T>
T abs(const complex<T>& c)
{
return c.real() * c.real() + c.imag() * c.imag();
}
template<class T>
T arg(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
T norm(const complex<T>& c)
{
return abs(c) * abs(c);
}
template<class T>
complex<T> conj(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> proj(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> polar(const T&, const T& = T{})
{
__unimplemented();
return complex<T>{};
}
template<class T>
complex<T> acos(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> asin(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> atan(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> acosh(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> asinh(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> atanh(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> cos(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> cosh(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> exp(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> log(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> log10(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> pow(const complex<T>& base, const T& exp)
{
__unimplemented();
return base;
}
template<class T>
complex<T> pow(const complex<T>& base, const complex<T>& exp)
{
__unimplemented();
return base;
}
template<class T>
complex<T> pow(const T& base, const complex<T>& exp)
{
__unimplemented();
return complex<T>{base};
}
template<class T>
complex<T> sin(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> sinh(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> sqrt(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> tan(const complex<T>& c)
{
__unimplemented();
return c;
}
template<class T>
complex<T> tanh(const complex<T>& c)
{
__unimplemented();
return c;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wliteral-suffix"
inline namespace literals {
inline namespace complex_literals
{
constexpr complex<long double> operator ""il(long double val)
{
return complex<long double>{0.0L, val};
}
constexpr complex<long double> operator ""il(unsigned long long val)
{
return complex<long double>{0.0L, static_cast<long double>(val)};
}
constexpr complex<double> operator ""i(long double val)
{
return complex<double>{0.0, static_cast<double>(val)};
}
constexpr complex<double> operator ""i(unsigned long long val)
{
return complex<double>{0.0, static_cast<double>(val)};
}
constexpr complex<float> operator ""if(long double val)
{
return complex<float>{0.0f, static_cast<float>(val)};
}
constexpr complex<float> operator ""if(unsigned long long val)
{
return complex<float>{0.0f, static_cast<float>(val)};
}
}}
#pragma GCC diagnostic pop
}
#endif
HelenOS homepage, sources at GitHub