コード例 #1
0
ファイル: Number.cpp プロジェクト: dubrousky/Mathador
NumberPtr Number::Read(Input &input)
{
	Integer ten(10);
	auto_ptr<Integer> intValue(new Integer);
	while(input.Current() >= '0' && input.Current() <= '9')
	{
		Integer digit(input.Current() - '0');
		intValue = intValue->Times(&ten)->Plus(&digit);
		input.Next();
	}

	// Process part after decimal separator
	if(input.Current() == '.')
	{
		// Cast the current value to float (just to prevent compiler warning)
		auto_ptr<MachineReal> realValue(new MachineReal(intValue));
		input.Next();
		auto_ptr<MachineReal> factor(new MachineReal(1.0));
		MachineReal tenth(0.1);
		while(input.Current() >= '0' && input.Current() <= '9')
		{
			MachineReal digit(input.Current() - '0');
			factor = factor->Times(&tenth);
			realValue = realValue->Plus(factor->Times(&digit).get());
			input.Next();
		}
		return NumberPtr(realValue);
	}
	else
		return NumberPtr(intValue);
}
コード例 #2
0
ファイル: Number.cpp プロジェクト: dubrousky/Mathador
IntegerType Number::ReadInteger(Input &input)
{
	IntegerType intValue(0);
	// Process part before decimal separator
	while(input.Current() >= '0' && input.Current() <= '9')
	{
		intValue = intValue * 10 + (input.Current() - '0');
		input.Next();
	}
	return intValue;
}