Пример #1
0
		public void NumberTest()
		{
			var two = new Integer(2);
			Assert.AreEqual(2, two.Value);
			Assert.AreEqual("2", two.ToString());

			var twopointfour = new Float(2.4);
			Assert.AreEqual(2.4, twopointfour.Value);
			Assert.AreEqual("2.4", twopointfour.ToString());
		}
Пример #2
0
		private IntegerFraction(Integer numerator, int denominator)
		{
			Ctor(numerator.Value, denominator);
		}
Пример #3
0
		internal IntegerFraction(Integer numerator, Integer denominator)
		{
			Ctor(numerator.Value, denominator.Value);
		}
Пример #4
0
		internal IntegerFraction(Integer value)
		{
			Ctor(value.Value, 1);
		}
Пример #5
0
		private static bool IsNumber(Component component, out Number number)
		{
			if (component is SingleFactorComponent)
			{
				var sfc = (SingleFactorComponent)component;
				if (sfc.Factor is NumericFactor)
				{
					var nf = (NumericFactor)sfc.Factor;
					number = nf.Number;
					return true;
				}
			}

			if (component is IntegerFraction)
			{
				var inf = (IntegerFraction)component;
				if (inf.Denominator == 1)
				{
					number = new Integer(inf.Numerator * (inf.IsNegative ? -1 : 1));
					return true;
				}
			}

			if (component is ComponentList)
			{
				var cl = (ComponentList)component;
				if (cl.Factors.Count == 1)
				{
					var factor = cl.Factors[0];
					if (factor.Factor is NumericFactor)
					{
						if (factor.IsInNumerator)
						{
							number = ((NumericFactor)factor.Factor).Number;
							return true;
						}

						var denom = ((NumericFactor)factor.Factor).Number;
						if (denom is Float)
						{
							number = new Float(1 / ((Float)denom).ValueAsFloat());
							return true;
						}
					}
				}
			}

			number = null;
			return false;
		}