예제 #1
0
	RationalNumber operator ^ (const RationalNumber& B) const throw(std::invalid_argument)
	{
		if (!isFraction() || !B.isInteger())
		{
			return RationalNumber(powl(getRealNumber(), B.getRealNumber()));
		}
		RationalNumber S(1, 1);
		RationalNumber A = *this;
		long long n = B.numerator;
		if (n < 0)
		{
			A = RationalNumber(1, 1) / A;
			n = -n;
		}
		while (n)
		{
			if (n & 1)
			{
				S = S * A;
			}
			A = A * A;
			n >>= 1;
		}
		return S;
	}
예제 #2
0
	RationalNumber operator * (const RationalNumber& B) const
	{
		if (!isFraction() || !B.isFraction())
		{
			return RationalNumber(getRealNumber() * B.getRealNumber());
		}
		return RationalNumber(numerator * B.numerator, denominator * B.denominator);
	}
예제 #3
0
파일: getEnergy.cpp 프로젝트: njoy/utility
/** 
 * @details 
 * This function should be used when the next string in a stream is required to 
 * be an energy value, but the string argument may not exist. If a string cannot
 * be extracted from the stream (end of file), the *found* flag is set to false 
 * and 0.0 is returned. If the string isn't a positive real number, this method 
 * records an error via the logger specifying the sort of failure and throws an 
 * exception. */
double
njoy::utility::stream::getEnergy
( std::istream& is, bool& found, const std::string& name ){
  const double energy = getRealNumber(is, name, found);
  if ( found && ( energy < 0 ) ){
    njoy::Log::error( "{} must be greater tha 0 eV", name );
    throw std::exception();
  }
  return energy;
}
예제 #4
0
/** 
 * @param is A stream which a real number is to be extracted.
 * @param[in] name The name of the variable to be read from stream. Used when
 *                 logging information before throwing an exception. 
 * @param[in] bound The (inclusive) lower of real values that may be read 
 *                  without throwing an exception. 
 * @param[out] found Records whether a value could read from stream. If EOF is
 *                   encountered before a value can be read, **found** is set to
 *                   false. Otherwise, **found** is set to true.
 * @result When found and not in error, the real number value read from the input
 *         stream **in**. Otherwise, returns zero.
 *
 * @details 
 * This function should be used when the next string in a stream is required 
 * to be an real number value, but may not exist. If a string cannot be extracted 
 * from the stream (end of file), the **found** flag is set to false and zero is 
 * returned. Otherwise the **found** flag is set to true. If a string is extracted 
 * and isn't a real number value or is less than the **bound** argument, this method 
 * records an error via the logger specifying the variable name (see the **name** 
 * argument) and error type and throws an exception.
 */
double 
njoy::utility::stream::getRealWithLBound
( std::istream& is, const std::string& name, const double bound, bool& found ){
  const double realNumber = getRealNumber( is, name, found );
  if ( found && ( realNumber < bound ) ) {
    njoy::Log::error( "{} argument must be greater than or equal to {}",
		name, bound );
    throw std::exception();
  }
  return realNumber;
}
예제 #5
0
	RationalNumber operator / (const RationalNumber& B) const throw(std::domain_error)
	{
		if (!isFraction() || !B.isFraction())
		{
			return RationalNumber(getRealNumber() / B.getRealNumber());
		}
		if (B.numerator == 0)
		{
			throw std::domain_error("Division by zero!");
		}
		return RationalNumber(numerator * B.denominator, denominator * B.numerator);
	}
void KeypadController::start()
{
    enum KeypadButton pincode[4] = { KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE };

    int lastCol = -1;
    bool pressed = false;
    enum segChar writeChar;

    if (setup() != 0)
    {
        emit keypadFinished();
        return;
    }

    // flash 7 segs a few times to show its ready
    selectCol(0xF);
    for (int i=0; i < 3; i++)
    {
        write7seg(SEG_EIGHT);
        usleep(500000);
        write7seg(SEG_BLANK);
        usleep(200000);
    }

    // main loop
    for (col = 0; col < 4; col++, col %= 4)
    {
        QCoreApplication::processEvents();

        write7seg(SEG_BLANK);
        selectCol(col);

        enum KeypadButton button = buttonPressed(col);

        if (button == KEY_NONE)
        {
            if (lastCol == col)
            {
                pressed = false;
            }

            // qDebug() << "nothing";
        }
        else
        {
            if (pressed)
            {
                // ignore button held down
                // qDebug() << "held\n";
            }
            else if (buttonIsNumeric(button))
            {
                // a new button was pressed
                if (needPincode)
                {
                    // add it to pincode
                    pincode[count] = button;
                    count++;
                    qDebug() << "Button is" << getRealNumber(button) << "count is " << count;
                }
                else
                {
                    // forward to main thread
                    qDebug() << "Button is" << getRealNumber(button);
                    emit forwardButton(button);
                }
                pressed = true;
                lastCol = col;
            }
        }

        if (count == 4)
        {
            QString pin = QString("%1%2%3%4").arg(getRealNumber(pincode[0]))
                                  .arg(getRealNumber(pincode[1]))
                                  .arg(getRealNumber(pincode[2]))
                                  .arg(getRealNumber(pincode[3]));
            if (needPincode)
            {
                emit forwardPincode(pin);
            }
            needPincode = false;
        }

        writeChar = getHexRepresentation(pincode[col]);
        write7seg(writeChar);

        usleep(1000);
    }

}