#include "Qubit.h"

#include <sstream>

Qubit::Qubit(const ComplexNumber& alpha, const ComplexNumber& beta)
	:	mAlpha(alpha),
		mBeta(beta)
{

}

const ComplexNumber& Qubit::getAlpha() const
{
	return mAlpha;
}

const ComplexNumber& Qubit::getBeta() const
{
	return mBeta;
}

bool Qubit::isIn0State() const
{
	return mAlpha.getReal() == 1.0 && mBeta.getMagnitude() == 0.0;
}

bool Qubit::isIn1State() const
{
	return mBeta.getReal() == 1.0 && mAlpha.getMagnitude() == 0.0;
}

std::string Qubit::toString(std::size_t precision) const
{
	std::stringstream sstr;
	sstr.precision(precision);
	sstr << "alpha " << mAlpha.getReal() << " " << mAlpha.getImaginary() << "i , beta " << mBeta.getReal() << " " << mBeta.getImaginary() << "i";
	return sstr.str();
}